mirror of https://github.com/apache/cassandra
Show CQL help in cqlsh in web browser
patch by Robert Stupp; reviewed by Paulo Motta for CASSANDRA-7225
This commit is contained in:
parent
432a8a4843
commit
0ee8895b27
|
|
@ -1,4 +1,5 @@
|
||||||
2.2.4
|
2.2.4
|
||||||
|
* Show CQL help in cqlsh in web browser (CASSANDRA-7225)
|
||||||
* Serialize on disk the proper SSTable compression ratio (CASSANDRA-10775)
|
* Serialize on disk the proper SSTable compression ratio (CASSANDRA-10775)
|
||||||
* Reject index queries while the index is building (CASSANDRA-8505)
|
* Reject index queries while the index is building (CASSANDRA-8505)
|
||||||
* CQL.textile syntax incorrectly includes optional keyspace for aggregate SFUNC and FINALFUNC (CASSANDRA-10747)
|
* CQL.textile syntax incorrectly includes optional keyspace for aggregate SFUNC and FINALFUNC (CASSANDRA-10747)
|
||||||
|
|
|
||||||
61
bin/cqlsh.py
61
bin/cqlsh.py
|
|
@ -45,6 +45,7 @@ import sys
|
||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
import warnings
|
import warnings
|
||||||
|
import webbrowser
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from glob import glob
|
from glob import glob
|
||||||
|
|
@ -71,6 +72,31 @@ CQL_LIB_PREFIX = 'cassandra-driver-internal-only-'
|
||||||
|
|
||||||
CASSANDRA_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..')
|
CASSANDRA_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..')
|
||||||
|
|
||||||
|
if os.path.exists(CASSANDRA_PATH + '/doc/cql3/CQL.html'):
|
||||||
|
# default location of local CQL.html
|
||||||
|
CASSANDRA_CQL_HTML = 'file://' + CASSANDRA_PATH + '/doc/cql3/CQL.html'
|
||||||
|
elif os.path.exists('/usr/share/doc/cassandra/CQL.html'):
|
||||||
|
# fallback to package file
|
||||||
|
CASSANDRA_CQL_HTML = 'file:///usr/share/doc/cassandra/CQL.html'
|
||||||
|
else:
|
||||||
|
# fallback to online version
|
||||||
|
CASSANDRA_CQL_HTML = 'https://cassandra.apache.org/doc/cql3/CQL-2.2.html'
|
||||||
|
|
||||||
|
# On Linux, the Python webbrowser module uses the 'xdg-open' executable
|
||||||
|
# to open a file/URL. But that only works, if the current session has been
|
||||||
|
# opened from _within_ a desktop environment. I.e. 'xdg-open' will fail,
|
||||||
|
# if the session's been opened via ssh to a remote box.
|
||||||
|
#
|
||||||
|
# Use 'python' to get some information about the detected browsers.
|
||||||
|
# >>> import webbrowser
|
||||||
|
# >>> webbrowser._tryorder
|
||||||
|
# >>> webbrowser._browser
|
||||||
|
#
|
||||||
|
if webbrowser._tryorder[0] == 'xdg-open' and os.environ.get('XDG_DATA_DIRS', '') == '':
|
||||||
|
# only on Linux (some OS with xdg-open)
|
||||||
|
webbrowser._tryorder.remove('xdg-open')
|
||||||
|
webbrowser._tryorder.append('xdg-open')
|
||||||
|
|
||||||
# use bundled libs for python-cql and thrift, if available. if there
|
# use bundled libs for python-cql and thrift, if available. if there
|
||||||
# is a ../lib dir, use bundled libs there preferentially.
|
# is a ../lib dir, use bundled libs there preferentially.
|
||||||
ZIPLIB_DIRS = [os.path.join(CASSANDRA_PATH, 'lib')]
|
ZIPLIB_DIRS = [os.path.join(CASSANDRA_PATH, 'lib')]
|
||||||
|
|
@ -164,6 +190,9 @@ parser.add_option("-C", "--color", action='store_true', dest='color',
|
||||||
help='Always use color output')
|
help='Always use color output')
|
||||||
parser.add_option("--no-color", action='store_false', dest='color',
|
parser.add_option("--no-color", action='store_false', dest='color',
|
||||||
help='Never use color output')
|
help='Never use color output')
|
||||||
|
parser.add_option("--browser", dest='browser', help="""The browser to use to display CQL help, where BROWSER can be:
|
||||||
|
- one of the supported browsers in https://docs.python.org/2/library/webbrowser.html.
|
||||||
|
- browser path followed by %s, example: /usr/bin/google-chrome-stable %s""")
|
||||||
parser.add_option('--ssl', action='store_true', help='Use SSL', default=False)
|
parser.add_option('--ssl', action='store_true', help='Use SSL', default=False)
|
||||||
parser.add_option("-u", "--username", help="Authenticate as user.")
|
parser.add_option("-u", "--username", help="Authenticate as user.")
|
||||||
parser.add_option("-p", "--password", help="Authenticate using password.")
|
parser.add_option("-p", "--password", help="Authenticate using password.")
|
||||||
|
|
@ -630,7 +659,7 @@ class Shell(cmd.Cmd):
|
||||||
|
|
||||||
def __init__(self, hostname, port, color=False,
|
def __init__(self, hostname, port, color=False,
|
||||||
username=None, password=None, encoding=None, stdin=None, tty=True,
|
username=None, password=None, encoding=None, stdin=None, tty=True,
|
||||||
completekey=DEFAULT_COMPLETEKEY, use_conn=None,
|
completekey=DEFAULT_COMPLETEKEY, browser=None, use_conn=None,
|
||||||
cqlver=DEFAULT_CQLVER, keyspace=None,
|
cqlver=DEFAULT_CQLVER, keyspace=None,
|
||||||
tracing_enabled=False, expand_enabled=False,
|
tracing_enabled=False, expand_enabled=False,
|
||||||
display_nanotime_format=DEFAULT_NANOTIME_FORMAT,
|
display_nanotime_format=DEFAULT_NANOTIME_FORMAT,
|
||||||
|
|
@ -674,6 +703,9 @@ class Shell(cmd.Cmd):
|
||||||
else:
|
else:
|
||||||
self.session = self.conn.connect()
|
self.session = self.conn.connect()
|
||||||
|
|
||||||
|
if browser == "":
|
||||||
|
browser = None
|
||||||
|
self.browser = browser
|
||||||
self.color = color
|
self.color = color
|
||||||
|
|
||||||
self.display_nanotime_format = display_nanotime_format
|
self.display_nanotime_format = display_nanotime_format
|
||||||
|
|
@ -2178,10 +2210,33 @@ class Shell(cmd.Cmd):
|
||||||
doc = getattr(self, 'do_' + t.lower()).__doc__
|
doc = getattr(self, 'do_' + t.lower()).__doc__
|
||||||
self.stdout.write(doc + "\n")
|
self.stdout.write(doc + "\n")
|
||||||
elif t.lower() in cqldocs.get_help_topics():
|
elif t.lower() in cqldocs.get_help_topics():
|
||||||
cqldocs.print_help_topic(t)
|
urlpart = cqldocs.get_help_topic(t)
|
||||||
|
if urlpart is not None:
|
||||||
|
url = "%s#%s" % (CASSANDRA_CQL_HTML, urlpart)
|
||||||
|
if self.browser is not None:
|
||||||
|
webbrowser.get(self.browser).open_new_tab(url)
|
||||||
|
else:
|
||||||
|
webbrowser.open_new_tab(url)
|
||||||
else:
|
else:
|
||||||
self.printerr("*** No help on %s" % (t,))
|
self.printerr("*** No help on %s" % (t,))
|
||||||
|
|
||||||
|
def do_unicode(self, parsed):
|
||||||
|
"""
|
||||||
|
Textual input/output
|
||||||
|
|
||||||
|
When control characters, or other characters which can't be encoded
|
||||||
|
in your current locale, are found in values of 'text' or 'ascii'
|
||||||
|
types, it will be shown as a backslash escape. If color is enabled,
|
||||||
|
any such backslash escapes will be shown in a different color from
|
||||||
|
the surrounding text.
|
||||||
|
|
||||||
|
Unicode code points in your data will be output intact, if the
|
||||||
|
encoding for your locale is capable of decoding them. If you prefer
|
||||||
|
that non-ascii characters be shown with Python-style "\\uABCD"
|
||||||
|
escape sequences, invoke cqlsh with an ASCII locale (for example,
|
||||||
|
by setting the $LANG environment variable to "C").
|
||||||
|
"""
|
||||||
|
|
||||||
def do_paging(self, parsed):
|
def do_paging(self, parsed):
|
||||||
"""
|
"""
|
||||||
PAGING [cqlsh]
|
PAGING [cqlsh]
|
||||||
|
|
@ -2524,6 +2579,7 @@ def read_options(cmdlineargs, environment):
|
||||||
optvalues.username = option_with_default(configs.get, 'authentication', 'username')
|
optvalues.username = option_with_default(configs.get, 'authentication', 'username')
|
||||||
optvalues.password = option_with_default(rawconfigs.get, 'authentication', 'password')
|
optvalues.password = option_with_default(rawconfigs.get, 'authentication', 'password')
|
||||||
optvalues.keyspace = option_with_default(configs.get, 'authentication', 'keyspace')
|
optvalues.keyspace = option_with_default(configs.get, 'authentication', 'keyspace')
|
||||||
|
optvalues.browser = option_with_default(configs.get, 'ui', 'browser', None)
|
||||||
optvalues.completekey = option_with_default(configs.get, 'ui', 'completekey',
|
optvalues.completekey = option_with_default(configs.get, 'ui', 'completekey',
|
||||||
DEFAULT_COMPLETEKEY)
|
DEFAULT_COMPLETEKEY)
|
||||||
optvalues.color = option_with_default(configs.getboolean, 'ui', 'color')
|
optvalues.color = option_with_default(configs.getboolean, 'ui', 'color')
|
||||||
|
|
@ -2664,6 +2720,7 @@ def main(options, hostname, port):
|
||||||
stdin=stdin,
|
stdin=stdin,
|
||||||
tty=options.tty,
|
tty=options.tty,
|
||||||
completekey=options.completekey,
|
completekey=options.completekey,
|
||||||
|
browser=options.browser,
|
||||||
cqlver=options.cqlversion,
|
cqlver=options.cqlversion,
|
||||||
keyspace=options.keyspace,
|
keyspace=options.keyspace,
|
||||||
display_timestamp_format=options.time_format,
|
display_timestamp_format=options.time_format,
|
||||||
|
|
|
||||||
|
|
@ -776,7 +776,7 @@
|
||||||
depends="maven-ant-tasks-retrieve-build,build-project" description="Compile Cassandra classes"/>
|
depends="maven-ant-tasks-retrieve-build,build-project" description="Compile Cassandra classes"/>
|
||||||
<target name="codecoverage" depends="jacoco-run,jacoco-report" description="Create code coverage report"/>
|
<target name="codecoverage" depends="jacoco-run,jacoco-report" description="Create code coverage report"/>
|
||||||
|
|
||||||
<target depends="init,gen-cql3-grammar"
|
<target depends="init,gen-cql3-grammar,generate-cql-html"
|
||||||
name="build-project">
|
name="build-project">
|
||||||
<echo message="${ant.project.name}: ${ant.file}"/>
|
<echo message="${ant.project.name}: ${ant.file}"/>
|
||||||
<!-- Order matters! -->
|
<!-- Order matters! -->
|
||||||
|
|
@ -1013,6 +1013,11 @@
|
||||||
<copy todir="${dist.dir}/javadoc">
|
<copy todir="${dist.dir}/javadoc">
|
||||||
<fileset dir="${javadoc.dir}"/>
|
<fileset dir="${javadoc.dir}"/>
|
||||||
</copy>
|
</copy>
|
||||||
|
<copy todir="${dist.dir}/doc">
|
||||||
|
<fileset dir="doc">
|
||||||
|
<exclude name="cql3/CQL.textile"/>
|
||||||
|
</fileset>
|
||||||
|
</copy>
|
||||||
<copy todir="${dist.dir}/bin">
|
<copy todir="${dist.dir}/bin">
|
||||||
<fileset dir="bin"/>
|
<fileset dir="bin"/>
|
||||||
</copy>
|
</copy>
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,23 @@ password = !!bang!!$
|
||||||
color = on
|
color = on
|
||||||
completekey = tab
|
completekey = tab
|
||||||
|
|
||||||
|
; To use another than the system default browser for cqlsh HELP to open
|
||||||
|
; the CQL doc HTML, use the 'browser' preference.
|
||||||
|
; If the field value is empty or not specified, cqlsh will use the
|
||||||
|
; default browser (specifying 'browser = default' does not work).
|
||||||
|
;
|
||||||
|
; Supported browsers are those supported by the Python webbrowser module.
|
||||||
|
; (https://docs.python.org/2/library/webbrowser.html).
|
||||||
|
;
|
||||||
|
; Hint: to use Google Chome, use
|
||||||
|
; 'browser = open -a /Applications/Google\ Chrome.app %s' on Mac OS X and
|
||||||
|
; 'browser = /usr/bin/google-chrome-stable %s' on Linux and
|
||||||
|
; 'browser = C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s' on Windows.
|
||||||
|
;
|
||||||
|
; This setting can be overridden with the --browser command line option.
|
||||||
|
;
|
||||||
|
;browser =
|
||||||
|
|
||||||
[cql]
|
[cql]
|
||||||
version = 3.1.5
|
version = 3.1.5
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ build-stamp: patch-stamp
|
||||||
dh_testdir
|
dh_testdir
|
||||||
printf "version=%s" $(VERSION) > build.properties
|
printf "version=%s" $(VERSION) > build.properties
|
||||||
|
|
||||||
|
$(ANT) generate-cql-html
|
||||||
$(ANT) jar
|
$(ANT) jar
|
||||||
cd pylib && python setup.py install --no-compile --install-layout deb \
|
cd pylib && python setup.py install --no-compile --install-layout deb \
|
||||||
--root $(CURDIR)/debian/cassandra
|
--root $(CURDIR)/debian/cassandra
|
||||||
|
|
@ -62,7 +63,7 @@ binary-indep: build install
|
||||||
dh_testroot
|
dh_testroot
|
||||||
dh_installchangelogs
|
dh_installchangelogs
|
||||||
dh_installinit -u'start 50 2 3 4 5 . stop 50 0 1 6 .'
|
dh_installinit -u'start 50 2 3 4 5 . stop 50 0 1 6 .'
|
||||||
dh_installdocs README.asc CHANGES.txt NEWS.txt
|
dh_installdocs README.asc CHANGES.txt NEWS.txt doc/cql3/CQL.css doc/cql3/CQL.html
|
||||||
dh_installexamples tools/*.yaml
|
dh_installexamples tools/*.yaml
|
||||||
dh_bash-completion
|
dh_bash-completion
|
||||||
dh_compress
|
dh_compress
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue