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/10/09 17:07:46 UTC
[2/5] git commit: cqlsh: allow configuration of value display formats
Patch by Aleksey Yeschenko, reviewed by brandonwilliams for CASSANDRA-3756
cqlsh: allow configuration of value display formats
Patch by Aleksey Yeschenko, reviewed by brandonwilliams for
CASSANDRA-3756
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/c44af8c2
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/c44af8c2
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/c44af8c2
Branch: refs/heads/trunk
Commit: c44af8c2c5c74b4f033bde5e445776122c4a3197
Parents: 0bdd152
Author: Brandon Williams <br...@apache.org>
Authored: Tue Oct 9 10:06:46 2012 -0500
Committer: Brandon Williams <br...@apache.org>
Committed: Tue Oct 9 10:06:46 2012 -0500
----------------------------------------------------------------------
bin/cqlsh | 33 ++++++++++++++++++++++++++++-----
1 files changed, 28 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/c44af8c2/bin/cqlsh
----------------------------------------------------------------------
diff --git a/bin/cqlsh b/bin/cqlsh
index 9fad4c6..729fcdc 100755
--- a/bin/cqlsh
+++ b/bin/cqlsh
@@ -117,6 +117,9 @@ DEFAULT_PORT = 9160
DEFAULT_CQLVER = '3'
DEFAULT_TRANSPORT_FACTORY = 'cqlshlib.tfactory.regular_transport_factory'
+DEFAULT_TIME_FORMAT = '%Y-%m-%d %H:%M:%S%z'
+DEFAULT_FLOAT_PRECISION = 3
+
epilog = """Connects to %(DEFAULT_HOST)s:%(DEFAULT_PORT)d by default. These
defaults can be changed by setting $CQLSH_HOST and/or $CQLSH_PORT. When a
host (and optional port number) are given on the command line, they take
@@ -404,8 +407,6 @@ class Shell(cmd.Cmd):
continue_prompt = " ... "
keyspace_prompt = "cqlsh:%s> "
keyspace_continue_prompt = "%s ... "
- display_time_format = '%Y-%m-%d %H:%M:%S%z'
- display_float_precision = 3
num_retries = 4
show_line_nums = False
debug = False
@@ -417,7 +418,9 @@ class Shell(cmd.Cmd):
def __init__(self, hostname, port, transport_factory, color=False,
username=None, password=None, encoding=None, stdin=None, tty=True,
- completekey='tab', use_conn=None, cqlver=None, keyspace=None):
+ completekey='tab', use_conn=None, cqlver=None, keyspace=None,
+ display_time_format=DEFAULT_TIME_FORMAT,
+ display_float_precision=DEFAULT_FLOAT_PRECISION):
cmd.Cmd.__init__(self, completekey=completekey)
self.hostname = hostname
self.port = port
@@ -452,6 +455,8 @@ class Shell(cmd.Cmd):
self.current_keyspace = keyspace
self.color = color
+ self.display_time_format = display_time_format
+ self.display_float_precision = display_float_precision
if encoding is None:
encoding = locale.getpreferredencoding()
self.encoding = encoding
@@ -1745,7 +1750,9 @@ class Shell(cmd.Cmd):
return
subshell = Shell(self.hostname, self.port, self.transport_factory,
color=self.color, encoding=self.encoding, stdin=f,
- tty=False, use_conn=self.conn, cqlver=self.cql_version)
+ tty=False, use_conn=self.conn, cqlver=self.cql_version,
+ display_time_format=self.display_time_format,
+ display_float_precision=self.display_float_precision)
subshell.cmdloop()
f.close()
@@ -2559,6 +2566,16 @@ def option_with_default(cparser_getter, section, option, default=None):
except ConfigParser.Error:
return default
+def raw_option_with_default(configs, section, option, default=None):
+ """
+ Same (almost) as option_with_default() but won't do any string interpolation.
+ Useful for config values that include '%' symbol, e.g. time format string.
+ """
+ try:
+ return configs.get(section, option, raw=True)
+ except ConfigParser.Error:
+ return default
+
def should_use_color():
if not sys.stdout.isatty():
return False
@@ -2603,6 +2620,10 @@ def read_options(cmdlineargs, environment):
DEFAULT_TRANSPORT_FACTORY)
optvalues.completekey = option_with_default(configs.get, 'ui', 'completekey', 'tab')
optvalues.color = option_with_default(configs.getboolean, 'ui', 'color')
+ optvalues.time_format = raw_option_with_default(configs, 'ui', 'time_format',
+ DEFAULT_TIME_FORMAT)
+ optvalues.float_precision = option_with_default(configs.getint, 'ui', 'float_precision',
+ DEFAULT_FLOAT_PRECISION)
optvalues.debug = False
optvalues.file = None
optvalues.tty = sys.stdin.isatty()
@@ -2701,7 +2722,9 @@ def main(options, hostname, port):
tty=options.tty,
completekey=options.completekey,
cqlver=options.cqlversion,
- keyspace=options.keyspace)
+ keyspace=options.keyspace,
+ display_time_format=options.time_format,
+ display_float_precision=options.float_precision)
except KeyboardInterrupt:
sys.exit('Connection aborted.')
except CQL_ERRORS, e: