You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by al...@apache.org on 2013/05/29 20:12:17 UTC

[1/3] git commit: Fix clqsh test_prompt

Updated Branches:
  refs/heads/trunk d78b62264 -> 4f7e2b801


Fix clqsh test_prompt


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

Branch: refs/heads/trunk
Commit: 87450cb13e6cab141e24f430db5532adcf18751c
Parents: 26c65e6
Author: Aleksey Yeschenko <al...@apache.org>
Authored: Wed May 29 21:01:17 2013 +0300
Committer: Aleksey Yeschenko <al...@apache.org>
Committed: Wed May 29 21:01:58 2013 +0300

----------------------------------------------------------------------
 pylib/cqlshlib/test/test_cqlsh_output.py |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/87450cb1/pylib/cqlshlib/test/test_cqlsh_output.py
----------------------------------------------------------------------
diff --git a/pylib/cqlshlib/test/test_cqlsh_output.py b/pylib/cqlshlib/test/test_cqlsh_output.py
index e67cc9c..6ca251e 100644
--- a/pylib/cqlshlib/test/test_cqlsh_output.py
+++ b/pylib/cqlshlib/test/test_cqlsh_output.py
@@ -636,14 +636,14 @@ class TestCqlshOutput(BaseTestCase):
         ), cqlver=(2, 3))
 
     def test_prompt(self):
-        with testrun_cqlsh(tty=True, keyspace=None, cqlver=2) as c:
+        with testrun_cqlsh(tty=True, keyspace=None, cqlver=3) as c:
             self.assertEqual(c.output_header.splitlines()[-1], 'cqlsh> ')
 
             c.send('\n')
             output = c.read_to_next_prompt().replace('\r\n', '\n')
             self.assertEqual(output, '\ncqlsh> ')
 
-            cmd = "USE '%s';\n" % get_test_keyspace().replace("'", "''")
+            cmd = 'USE "%s";\n' % get_test_keyspace().replace('"', '""')
             c.send(cmd)
             output = c.read_to_next_prompt().replace('\r\n', '\n')
             self.assertEqual(output, '%scqlsh:%s> ' % (cmd, get_test_keyspace()))
@@ -655,10 +655,10 @@ class TestCqlshOutput(BaseTestCase):
             c.send('use NONEXISTENTKEYSPACE;\n')
             outputlines = c.read_to_next_prompt().splitlines()
             self.assertEqual(outputlines[0], 'use NONEXISTENTKEYSPACE;')
-            self.assertEqual(outputlines[3], 'cqlsh:system> ')
+            self.assertEqual(outputlines[2], 'cqlsh:system> ')
             midline = ColoredText(outputlines[1])
             self.assertEqual(midline.plain(),
-                             "Bad Request: Keyspace 'NONEXISTENTKEYSPACE' does not exist")
+                             "Bad Request: Keyspace 'nonexistentkeyspace' does not exist")
             self.assertColorFromTags(midline,
                              "RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR")
 


[2/3] git commit: cqlsh: add vertical output option (see EXPAND)

Posted by al...@apache.org.
 cqlsh: add vertical output option (see EXPAND)

 patch by MichaƂ Michalski; reviewed by Aleksey Yeschenko for
 CASSANDRA-5597


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

Branch: refs/heads/trunk
Commit: 26c65e640cea57e8a2c0e007ab3f5febc7a2f160
Parents: 6d7404b
Author: Aleksey Yeschenko <al...@apache.org>
Authored: Wed May 29 20:59:51 2013 +0300
Committer: Aleksey Yeschenko <al...@apache.org>
Committed: Wed May 29 21:01:58 2013 +0300

----------------------------------------------------------------------
 CHANGES.txt                                  |    1 +
 bin/cqlsh                                    |   72 ++++++++++++++++++++-
 pylib/cqlshlib/test/test_cqlsh_completion.py |    6 +-
 3 files changed, 73 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/26c65e64/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 61bd4b7..f51baae 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -9,6 +9,7 @@
  * Exclude localTimestamp from validation for tombstones (CASSANDRA-5398)
  * cqlsh: add custom prompt support (CASSANDRA-5539)
  * Reuse prepared statements in hot auth queries (CASSANDRA-5594)
+ * cqlsh: add vertical output option (see EXPAND) (CASSANDRA-5597)
 Merged from 1.1:
  * Remove buggy thrift max message length option (CASSANDRA-5529)
  * Fix NPE in Pig's widerow mode (CASSANDRA-5488)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/26c65e64/bin/cqlsh
----------------------------------------------------------------------
diff --git a/bin/cqlsh b/bin/cqlsh
index f96cb23..1abd078 100755
--- a/bin/cqlsh
+++ b/bin/cqlsh
@@ -32,7 +32,7 @@ exit 1
 from __future__ import with_statement
 
 description = "CQL Shell for Apache Cassandra"
-version = "3.0.3"
+version = "3.1.0"
 
 from StringIO import StringIO
 from itertools import groupby
@@ -188,6 +188,7 @@ my_commands_ending_with_newline = (
     'capture',
     'debug',
     'tracing',
+    'expand',
     'exit',
     'quit'
 )
@@ -214,6 +215,7 @@ cqlsh_extra_syntax_rules = r'''
                    | <debugCommand>
                    | <helpCommand>
                    | <tracingCommand>
+                   | <expandCommand>
                    | <exitCommand>
                    ;
 
@@ -281,6 +283,9 @@ cqlsh_extra_syntax_rules = r'''
 <tracingCommand> ::= "TRACING" ( switch=( "ON" | "OFF" ) )?
                    ;
 
+<expandCommand> ::= "EXPAND" ( switch=( "ON" | "OFF" ) )?
+                   ;
+
 <exitCommand> ::= "exit" | "quit"
                 ;
 
@@ -467,7 +472,8 @@ class Shell(cmd.Cmd):
     def __init__(self, hostname, port, transport_factory, color=False,
                  username=None, password=None, encoding=None, stdin=None, tty=True,
                  completekey=DEFAULT_COMPLETEKEY, use_conn=None,
-                 cqlver=DEFAULT_CQLVER, keyspace=None, tracing_enabled=False,
+                 cqlver=DEFAULT_CQLVER, keyspace=None,
+                 tracing_enabled=False, expand_enabled=False,
                  display_time_format=DEFAULT_TIME_FORMAT,
                  display_float_precision=DEFAULT_FLOAT_PRECISION):
         cmd.Cmd.__init__(self, completekey=completekey)
@@ -478,6 +484,7 @@ class Shell(cmd.Cmd):
         self.password = password
         self.keyspace = keyspace
         self.tracing_enabled = tracing_enabled
+        self.expand_enabled = expand_enabled
         if use_conn is not None:
             self.conn = use_conn
         else:
@@ -1109,7 +1116,10 @@ class Shell(cmd.Cmd):
         colnames_t = [(name, self.get_nametype(cursor, n)) for (n, name) in enumerate(colnames)]
         formatted_names = [self.myformat_colname(name, nametype) for (name, nametype) in colnames_t]
         formatted_values = [map(self.myformat_value, row, cursor.column_types) for row in cursor]
-        self.print_formatted_result(formatted_names, formatted_values)
+        if self.expand_enabled:
+            self.print_formatted_result_vertically(formatted_names, formatted_values)
+        else:
+            self.print_formatted_result(formatted_names, formatted_values)
 
     def print_formatted_result(self, formatted_names, formatted_values):
         # determine column widths
@@ -1128,6 +1138,20 @@ class Shell(cmd.Cmd):
             line = ' | '.join(col.rjust(w, color=self.color) for (col, w) in zip(row, widths))
             self.writeresult(' ' + line)
 
+    def print_formatted_result_vertically(self, formatted_names, formatted_values):
+        max_col_width = max([n.displaywidth for n in formatted_names])
+        max_val_width = max([n.displaywidth for row in formatted_values for n in row])
+
+        # for each row returned, list all the column-value pairs
+        for row_id, row in enumerate(formatted_values):
+            self.writeresult("@ Row %d" % (row_id + 1))
+            self.writeresult('-%s-' % '-+-'.join(['-' * max_col_width, '-' * max_val_width]))
+            for field_id, field in enumerate(row):
+                column = formatted_names[field_id].ljust(max_col_width, color=self.color)
+                value = field.ljust(field.displaywidth, color=self.color)
+                self.writeresult(' ' + " | ".join([column, value]))
+            self.writeresult('')
+
     def print_dynamic_result(self, cursor):
         for row in cursor:
             colnames = [d[0] for d in cursor.description]
@@ -1984,6 +2008,48 @@ class Shell(cmd.Cmd):
             self.tracing_enabled = False
             print 'Disabled tracing.'
 
+    def do_expand(self, parsed):
+        """
+        EXPAND [cqlsh]
+
+          Enables or disables expanded (vertical) output.
+
+        EXPAND ON
+
+          Enables expanded (vertical) output.
+
+        EXPAND OFF
+
+          Disables expanded (vertical) output.
+
+        EXPAND
+
+          EXPAND with no arguments shows the current value of expand setting.
+        """
+        switch = parsed.get_binding('switch')
+        if switch is None:
+            if self.expand_enabled:
+                print "Expanded output is currently enabled. Use EXPAND OFF to disable"
+            else:
+                print "Expanded output is currently disabled. Use EXPAND ON to enable."
+            return
+
+        if switch.upper() == 'ON':
+            if self.expand_enabled:
+                self.printerr('Expanded output is already enabled. '
+                              'Use EXPAND OFF to disable.')
+                return
+            self.expand_enabled = True
+            print 'Now printing expanded output'
+            return
+
+        if switch.upper() == 'OFF':
+            if not self.expand_enabled:
+                self.printerr('Expanded output is not enabled.')
+                return
+            self.expand_enabled = False
+            print 'Disabled expanded output.'
+
     def do_consistency(self, parsed):
         """
         CONSISTENCY [cqlsh with CQL3 only]

http://git-wip-us.apache.org/repos/asf/cassandra/blob/26c65e64/pylib/cqlshlib/test/test_cqlsh_completion.py
----------------------------------------------------------------------
diff --git a/pylib/cqlshlib/test/test_cqlsh_completion.py b/pylib/cqlshlib/test/test_cqlsh_completion.py
index edb2b51..3051378 100644
--- a/pylib/cqlshlib/test/test_cqlsh_completion.py
+++ b/pylib/cqlshlib/test/test_cqlsh_completion.py
@@ -98,7 +98,7 @@ class TestCqlshCompletion_CQL2(CqlshCompletionCase):
         self.trycompletions('', choices=('?', 'ALTER', 'ASSUME', 'BEGIN', 'CAPTURE', 'CONSISTENCY',
                                          'COPY', 'CREATE', 'DEBUG', 'DELETE', 'DESC', 'DESCRIBE',
                                          'DROP', 'HELP', 'INSERT', 'SELECT', 'SHOW', 'SOURCE',
-                                         'TRACING', 'TRUNCATE', 'UPDATE', 'USE', 'exit', 'quit'))
+                                         'TRACING', 'EXPAND', 'TRUNCATE', 'UPDATE', 'USE', 'exit', 'quit'))
 
     def test_complete_command_words(self):
         self.trycompletions('alt', '\b\b\bALTER ')
@@ -181,8 +181,8 @@ class TestCqlshCompletion_CQL3final(TestCqlshCompletion_CQL2):
         self.trycompletions('', choices=('?', 'ALTER', 'ASSUME', 'BEGIN', 'CAPTURE', 'CONSISTENCY',
                                          'COPY', 'CREATE', 'DEBUG', 'DELETE', 'DESC', 'DESCRIBE',
                                          'DROP', 'GRANT', 'HELP', 'INSERT', 'LIST', 'REVOKE',
-                                         'SELECT', 'SHOW', 'SOURCE', 'TRACING', 'TRUNCATE', 'UPDATE',
-                                         'USE', 'exit', 'quit'))
+                                         'SELECT', 'SHOW', 'SOURCE', 'TRACING', 'EXPAND', 'TRUNCATE',
+                                         'UPDATE', 'USE', 'exit', 'quit'))
 
     def test_complete_in_create_keyspace(self):
         self.trycompletions('create keyspace ', '', choices=('<identifier>', '<quotedName>'))


[3/3] git commit: Merge branch 'cassandra-1.2' into trunk

Posted by al...@apache.org.
Merge branch 'cassandra-1.2' into trunk

Conflicts:
	bin/cqlsh
	pylib/cqlshlib/test/test_cqlsh_completion.py
	pylib/cqlshlib/test/test_cqlsh_output.py


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

Branch: refs/heads/trunk
Commit: 4f7e2b801894614266d8284bd41e7d2676c8773b
Parents: d78b622 87450cb
Author: Aleksey Yeschenko <al...@apache.org>
Authored: Wed May 29 21:12:08 2013 +0300
Committer: Aleksey Yeschenko <al...@apache.org>
Committed: Wed May 29 21:12:08 2013 +0300

----------------------------------------------------------------------
 CHANGES.txt                                  |    1 +
 bin/cqlsh                                    |   70 ++++++++++++++++++++-
 pylib/cqlshlib/test/test_cqlsh_completion.py |    4 +-
 3 files changed, 71 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/4f7e2b80/CHANGES.txt
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cassandra/blob/4f7e2b80/bin/cqlsh
----------------------------------------------------------------------
diff --cc bin/cqlsh
index 977603b,1abd078..5741c31
--- a/bin/cqlsh
+++ b/bin/cqlsh
@@@ -952,6 -1138,29 +962,20 @@@ class Shell(cmd.Cmd)
              line = ' | '.join(col.rjust(w, color=self.color) for (col, w) in zip(row, widths))
              self.writeresult(' ' + line)
  
+     def print_formatted_result_vertically(self, formatted_names, formatted_values):
+         max_col_width = max([n.displaywidth for n in formatted_names])
+         max_val_width = max([n.displaywidth for row in formatted_values for n in row])
+ 
+         # for each row returned, list all the column-value pairs
+         for row_id, row in enumerate(formatted_values):
+             self.writeresult("@ Row %d" % (row_id + 1))
+             self.writeresult('-%s-' % '-+-'.join(['-' * max_col_width, '-' * max_val_width]))
+             for field_id, field in enumerate(row):
+                 column = formatted_names[field_id].ljust(max_col_width, color=self.color)
+                 value = field.ljust(field.displaywidth, color=self.color)
+                 self.writeresult(' ' + " | ".join([column, value]))
+             self.writeresult('')
+ 
 -    def print_dynamic_result(self, cursor):
 -        for row in cursor:
 -            colnames = [d[0] for d in cursor.description]
 -            colnames_t = [(name, self.get_nametype(cursor, n)) for (n, name) in enumerate(colnames)]
 -            colnames = [self.myformat_colname(name, nametype) for (name, nametype) in colnames_t]
 -            colvals = map(self.myformat_value, row, cursor.column_types)
 -            line = ' | '.join('%s,%s' % (n.coloredval, v.coloredval) for (n, v) in zip(colnames, colvals))
 -            self.writeresult(' ' + line)
 -
      def emptyline(self):
          pass
  
@@@ -1645,9 -2008,51 +1669,51 @@@
              self.tracing_enabled = False
              print 'Disabled tracing.'
  
+     def do_expand(self, parsed):
+         """
+         EXPAND [cqlsh]
+ 
+           Enables or disables expanded (vertical) output.
+ 
+         EXPAND ON
+ 
+           Enables expanded (vertical) output.
+ 
+         EXPAND OFF
+ 
+           Disables expanded (vertical) output.
+ 
+         EXPAND
+ 
+           EXPAND with no arguments shows the current value of expand setting.
+         """
+         switch = parsed.get_binding('switch')
+         if switch is None:
+             if self.expand_enabled:
+                 print "Expanded output is currently enabled. Use EXPAND OFF to disable"
+             else:
+                 print "Expanded output is currently disabled. Use EXPAND ON to enable."
+             return
+ 
+         if switch.upper() == 'ON':
+             if self.expand_enabled:
+                 self.printerr('Expanded output is already enabled. '
+                               'Use EXPAND OFF to disable.')
+                 return
+             self.expand_enabled = True
+             print 'Now printing expanded output'
+             return
+ 
+         if switch.upper() == 'OFF':
+             if not self.expand_enabled:
+                 self.printerr('Expanded output is not enabled.')
+                 return
+             self.expand_enabled = False
+             print 'Disabled expanded output.'
+ 
      def do_consistency(self, parsed):
          """
 -        CONSISTENCY [cqlsh with CQL3 only]
 +        CONSISTENCY [cqlsh only]
  
             Overrides default consistency level (default level is ONE).
  

http://git-wip-us.apache.org/repos/asf/cassandra/blob/4f7e2b80/pylib/cqlshlib/test/test_cqlsh_completion.py
----------------------------------------------------------------------
diff --cc pylib/cqlshlib/test/test_cqlsh_completion.py
index ea4f77c,3051378..b8f0167
--- a/pylib/cqlshlib/test/test_cqlsh_completion.py
+++ b/pylib/cqlshlib/test/test_cqlsh_completion.py
@@@ -90,16 -90,15 +90,16 @@@ class CqlshCompletionCase(BaseTestCase)
      def strategies(self):
          return self.module.CqlRuleSet.replication_strategies
  
 -class TestCqlshCompletion_CQL2(CqlshCompletionCase):
 -    cqlver = 2
 -    module = cqlsh.cqlhandling
 +class TestCqlshCompletion(CqlshCompletionCase):
 +    cqlver = '3.1.0'
 +    module = cqlsh.cql3handling
  
      def test_complete_on_empty_string(self):
 -        self.trycompletions('', choices=('?', 'ALTER', 'ASSUME', 'BEGIN', 'CAPTURE', 'CONSISTENCY',
 +        self.trycompletions('', choices=('?', 'ALTER', 'BEGIN', 'CAPTURE', 'CONSISTENCY',
                                           'COPY', 'CREATE', 'DEBUG', 'DELETE', 'DESC', 'DESCRIBE',
 -                                         'DROP', 'HELP', 'INSERT', 'SELECT', 'SHOW', 'SOURCE',
 -                                         'TRACING', 'EXPAND', 'TRUNCATE', 'UPDATE', 'USE', 'exit', 'quit'))
 +                                         'DROP', 'GRANT', 'HELP', 'INSERT', 'LIST', 'REVOKE',
-                                          'SELECT', 'SHOW', 'SOURCE', 'TRACING', 'TRUNCATE', 'UPDATE',
-                                          'USE', 'exit', 'quit'))
++                                         'SELECT', 'SHOW', 'SOURCE', 'TRACING', 'EXPAND', 'TRUNCATE',
++                                         'UPDATE', 'USE', 'exit', 'quit'))
  
      def test_complete_command_words(self):
          self.trycompletions('alt', '\b\b\bALTER ')