summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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