summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvgeny Fadeev <evgeny.fadeev@gmail.com>2010-12-16 21:33:06 -0500
committerEvgeny Fadeev <evgeny.fadeev@gmail.com>2010-12-16 21:33:06 -0500
commit46dc3d406edf34253595234d5ae4c0420e188e2d (patch)
tree2795e7e7090da381331d202ff16358f8e0b0a93f
parent47af4934aaaf5200c3272eb95f5071e5e30004c5 (diff)
downloadaskbot-46dc3d406edf34253595234d5ae4c0420e188e2d.tar.gz
askbot-46dc3d406edf34253595234d5ae4c0420e188e2d.tar.bz2
askbot-46dc3d406edf34253595234d5ae4c0420e188e2d.zip
one more small improvement to the dump_forum command
-rw-r--r--askbot/management/commands/dump_forum.py20
-rw-r--r--askbot/utils/console.py10
-rw-r--r--askbot/utils/path.py9
3 files changed, 26 insertions, 13 deletions
diff --git a/askbot/management/commands/dump_forum.py b/askbot/management/commands/dump_forum.py
index 9328bb53..8047b2f6 100644
--- a/askbot/management/commands/dump_forum.py
+++ b/askbot/management/commands/dump_forum.py
@@ -22,11 +22,15 @@ The extension ".json" will be added automatically."""
)
print "Saving file %s ..." % dump_file.name
stdout_orig = sys.stdout
- sys.stdout = dump_file
- management.call_command(
- 'dumpdata',
- exclude = ('contenttypes',),
- indent = 4
- )
- sys.stdout = stdout_orig
- print "Done."
+ try:
+ sys.stdout = dump_file
+ management.call_command(
+ 'dumpdata',
+ exclude = ('contenttypes',),
+ indent = 4
+ )
+ sys.stdout = stdout_orig
+ print "Done."
+ except KeyboardInterrupt:
+ sys.stdout = stdout_orig
+ print "\nCanceled."
diff --git a/askbot/utils/console.py b/askbot/utils/console.py
index bc51f3a3..f0dab45e 100644
--- a/askbot/utils/console.py
+++ b/askbot/utils/console.py
@@ -37,14 +37,14 @@ def open_new_file(prompt_phrase, extension = '', hint = None):
else:
extension = ''
+ file_object = None
if hint:
file_path = path.extend_file_name(hint, extension)
- if not os.path.exists(file_path):
- return open(file_path, 'w+')
+ file_object = path.create_file_if_does_not_exist(file_path, print_warning = True)
- while 1:
+ while file_object == None:
file_path = raw_input(prompt_phrase)
file_path = path.extend_file_name(file_path, extension)
+ file_object = path.create_file_if_does_not_exist(file_path, print_warning = True)
- if not os.path.exists(file_path):
- return open(file_path, 'w+')
+ return file_object
diff --git a/askbot/utils/path.py b/askbot/utils/path.py
index aeffb1ae..e4c117c3 100644
--- a/askbot/utils/path.py
+++ b/askbot/utils/path.py
@@ -21,3 +21,12 @@ def extend_file_name(file_path, extension):
file_path += extension
return file_path
+def create_file_if_does_not_exist(file_path, print_warning = True):
+ """if file at file_path does not exist, create it and return
+ the file object, otherwise return None"""
+ if not os.path.exists(file_path):
+ return open(file_path, 'w+')
+ else:
+ if print_warning:
+ print "File %s exists" % file_path
+ return None