You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by br...@apache.org on 2012/09/18 04:42:34 UTC

[2/3] git commit: cqlsh: catch IOError on history loading Patch by Aleksey Yeschenko, reviewed by brandonwilliams for CASSANDRA-4669

cqlsh: catch IOError on history loading
Patch by Aleksey Yeschenko, reviewed by brandonwilliams for
CASSANDRA-4669


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/e7f28f30
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/e7f28f30
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/e7f28f30

Branch: refs/heads/trunk
Commit: e7f28f30320bae4faa1092567d7b9b46f8947842
Parents: 4d600f3
Author: Brandon Williams <br...@apache.org>
Authored: Mon Sep 17 21:41:30 2012 -0500
Committer: Brandon Williams <br...@apache.org>
Committed: Mon Sep 17 21:41:30 2012 -0500

----------------------------------------------------------------------
 bin/cqlsh |   26 ++++++++++++++++++--------
 1 files changed, 18 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/e7f28f30/bin/cqlsh
----------------------------------------------------------------------
diff --git a/bin/cqlsh b/bin/cqlsh
index 3bef142..4e93db7 100755
--- a/bin/cqlsh
+++ b/bin/cqlsh
@@ -2687,16 +2687,28 @@ def setup_cqlruleset(cqlmodule):
         cqlruleset.completer_for(rulename, termname)(func)
     cqlruleset.commands_end_with_newline.update(my_commands_ending_with_newline)
 
-def main(options, hostname, port):
-    setup_cqlruleset(options.cqlmodule)
-
-    if os.path.exists(HISTORY) and readline is not None:
-        readline.read_history_file(HISTORY)
+def init_history():
+    if readline is not None:
+        try:
+            readline.read_history_file(HISTORY)
+        except IOError:
+            pass
         delims = readline.get_completer_delims()
         delims.replace("'", "")
         delims += '.'
         readline.set_completer_delims(delims)
 
+def save_history():
+    if readline is not None:
+        try:
+            readline.write_history_file(HISTORY)
+        except IOError:
+            pass
+
+def main(options, hostname, port):
+    setup_cqlruleset(options.cqlmodule)
+    init_history()
+
     if options.file is None:
         stdin = None
     else:
@@ -2731,9 +2743,7 @@ def main(options, hostname, port):
         shell.debug = True
 
     shell.cmdloop()
-
-    if readline is not None:
-        readline.write_history_file(HISTORY)
+    save_history()
 
 if __name__ == '__main__':
     main(*read_options(sys.argv[1:], os.environ))