Fix in-browser "help", Python 3

authored Adam Holmberg, reviewed by Ekaterina Dimitrova and Andres de la Pena for CASSANDRA-16658
This commit is contained in:
Adam Holmberg 2021-05-10 14:07:29 -05:00 committed by Ekaterina Dimitrova
parent 98b449f38a
commit 9783d47b9f
2 changed files with 12 additions and 15 deletions

View File

@ -1,4 +1,5 @@
4.0-rc2
* Fix in-browser "help", Python 3 (CASSANDRA-16658)
* Fix DROP COMPACT STORAGE for counters (CASSANDRA-16653)
* Add back validation for AlterTableStatements (CASSANDRA-16643)
* Fix cqlsh encoding error with unicode in multi-line statement (CASSANDRA-16539)

View File

@ -60,7 +60,7 @@ except ImportError:
CQL_LIB_PREFIX = 'cassandra-driver-internal-only-'
CASSANDRA_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..')
CASSANDRA_CQL_HTML_FALLBACK = 'https://cassandra.apache.org/doc/cql3/CQL-3.2.html'
CASSANDRA_CQL_HTML_FALLBACK = 'https://cassandra.apache.org/doc/latest/cql/index.html'
# default location of local CQL.html
if os.path.exists(CASSANDRA_PATH + '/doc/cql3/CQL.html'):
@ -78,15 +78,11 @@ else:
# 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
#
# webbrowser._tryorder is None in python3.7+
if webbrowser._tryorder is None or len(webbrowser._tryorder) == 0:
CASSANDRA_CQL_HTML = CASSANDRA_CQL_HTML_FALLBACK
elif webbrowser._tryorder[0] == 'xdg-open' and os.environ.get('XDG_DATA_DIRS', '') == '':
try:
webbrowser.register_standard_browsers() # registration is otherwise lazy in Python3
except AttributeError:
pass
if webbrowser._tryorder and 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')
@ -1923,12 +1919,12 @@ class Shell(cmd.Cmd):
urlpart = cqldocs.get_help_topic(t)
if urlpart is not None:
url = "%s#%s" % (CASSANDRA_CQL_HTML, urlpart)
if len(webbrowser._tryorder) == 0:
self.printerr("*** No browser to display CQL help. URL for help topic %s : %s" % (t, url))
elif self.browser is not None:
webbrowser.get(self.browser).open_new_tab(url)
if self.browser is not None:
opened = webbrowser.get(self.browser).open_new_tab(url)
else:
webbrowser.open_new_tab(url)
opened = webbrowser.open_new_tab(url)
if not opened:
self.printerr("*** No browser to display CQL help. URL for help topic %s : %s" % (t, url))
else:
self.printerr("*** No help on %s" % (t,))