This is an automated email from the ASF dual-hosted git repository.
smiklosovic pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/cassandra.git
The following commit(s) were added to refs/heads/trunk by this push:
new d24baecac9 Simplify pylib/cqlshlib/helptopics.py using associative
array
d24baecac9 is described below
commit d24baecac986e90bbbb5b6281a256f41c0a27d3f
Author: vgali7 <[email protected]>
AuthorDate: Fri Aug 4 15:14:03 2023 -0500
Simplify pylib/cqlshlib/helptopics.py using associative array
patch by Vineet Gali; reviewed by Stefan Miklosovic and Brandon Williams
for CASSANDRA-18726
---
pylib/cqlshlib/cql3handling.py | 2 -
pylib/cqlshlib/cqlshmain.py | 17 ++-
pylib/cqlshlib/helptopics.py | 244 ++++++++++++-----------------------------
pylib/setup.py | 1 +
4 files changed, 80 insertions(+), 184 deletions(-)
diff --git a/pylib/cqlshlib/cql3handling.py b/pylib/cqlshlib/cql3handling.py
index 4c81926ce4..74c6fc10f5 100644
--- a/pylib/cqlshlib/cql3handling.py
+++ b/pylib/cqlshlib/cql3handling.py
@@ -23,8 +23,6 @@ simple_cql_types = {'ascii', 'bigint', 'blob', 'boolean',
'counter', 'date', 'de
'varint'}
simple_cql_types.difference_update(('set', 'map', 'list'))
-cqldocs = helptopics.CQL3HelpTopics()
-
class UnexpectedTableStructure(UserWarning):
diff --git a/pylib/cqlshlib/cqlshmain.py b/pylib/cqlshlib/cqlshmain.py
index 90ae85abcd..7f15b13bb1 100755
--- a/pylib/cqlshlib/cqlshmain.py
+++ b/pylib/cqlshlib/cqlshmain.py
@@ -31,6 +31,8 @@ from contextlib import contextmanager
from io import StringIO
from uuid import UUID
+from cqlshlib.helptopics import get_html_anchor, get_html_topics
+
UTF8 = 'utf-8'
description = "CQL Shell for Apache Cassandra"
@@ -1795,6 +1797,9 @@ class Shell(cmd.Cmd):
pdb.set_trace()
def get_help_topics(self):
+ """
+ List of 'do_' methods having method comments
+ """
topics = [t[3:] for t in dir(self) if t.startswith('do_') and
getattr(self, t, None).__doc__]
for hide_from_help in ('quit',):
topics.remove(hide_from_help)
@@ -1815,15 +1820,15 @@ class Shell(cmd.Cmd):
if not topics:
shell_topics = [t.upper() for t in self.get_help_topics()]
self.print_topics("\nDocumented shell commands:", shell_topics,
15, 80)
- cql_topics = [t.upper() for t in cqldocs.get_help_topics()]
+ cql_topics = [t.upper() for t in get_html_topics()]
self.print_topics("CQL help topics:", cql_topics, 15, 80)
return
for t in topics:
if t.lower() in self.get_help_topics():
doc = getattr(self, 'do_' + t.lower()).__doc__
self.stdout.write(doc + "\n")
- elif t.lower() in cqldocs.get_help_topics():
- urlpart = cqldocs.get_help_topic(t)
+ elif t.lower() in get_html_topics():
+ urlpart = get_html_anchor(t)
if urlpart is not None:
url = "%s#%s" % (CASSANDRA_CQL_HTML, urlpart)
if self.browser is not None:
@@ -2217,11 +2222,6 @@ def setup_cqlruleset(cqlmodule):
cqlruleset.commands_end_with_newline.update(cqlshhandling.my_commands_ending_with_newline)
-def setup_cqldocs(cqlmodule):
- global cqldocs
- cqldocs = cqlmodule.cqldocs
-
-
def setup_docspath(path):
global CASSANDRA_CQL_HTML
CASSANDRA_CQL_HTML_FALLBACK =
'https://cassandra.apache.org/doc/latest/cql/index.html'
@@ -2269,7 +2269,6 @@ def main(cmdline, pkgpath):
setup_docspath(pkgpath)
setup_cqlruleset(options.cqlmodule)
- setup_cqldocs(options.cqlmodule)
csv.field_size_limit(options.field_size_limit)
if options.file is None:
diff --git a/pylib/cqlshlib/helptopics.py b/pylib/cqlshlib/helptopics.py
index 9be56b9f2e..04b75b39a8 100644
--- a/pylib/cqlshlib/helptopics.py
+++ b/pylib/cqlshlib/helptopics.py
@@ -15,176 +15,74 @@
# limitations under the License.
-class CQL3HelpTopics:
- def get_help_topics(self):
- return [t[5:] for t in dir(self) if t.startswith('help_')]
-
- def get_help_topic(self, topic):
- return getattr(self, 'help_' + topic.lower())()
-
- def help_types(self):
- return 'types'
-
- def help_timestamp(self):
- return 'usingtimestamps'
-
- def help_date(self):
- return 'usingdates'
-
- def help_time(self):
- return 'usingtime'
-
- def help_blob(self):
- return 'constants'
-
- def help_uuid(self):
- return 'constants'
-
- def help_boolean(self):
- return 'constants'
-
- def help_int(self):
- return 'constants'
-
- def help_counter(self):
- return 'counters'
-
- def help_text(self):
- return 'constants'
- help_ascii = help_text
-
- def help_use(self):
- return 'useStmt'
-
- def help_insert(self):
- return 'insertStmt'
-
- def help_update(self):
- return 'updateStmt'
-
- def help_delete(self):
- return 'deleteStmt'
-
- def help_select(self):
- return 'selectStmt'
-
- def help_json(self):
- return 'json'
-
- def help_select_json(self):
- return 'selectJson'
-
- def help_insert_json(self):
- return 'insertJson'
-
- def help_batch(self):
- return 'batchStmt'
- help_begin = help_batch
- help_apply = help_batch
-
- def help_create_keyspace(self):
- return 'createKeyspaceStmt'
-
- def help_alter_keyspace(self):
- return 'alterKeyspaceStmt'
-
- def help_drop_keyspace(self):
- return 'dropKeyspaceStmt'
-
- def help_create_table(self):
- return 'createTableStmt'
- help_create_columnfamily = help_create_table
-
- def help_alter_table(self):
- return 'alterTableStmt'
-
- def help_drop_table(self):
- return 'dropTableStmt'
- help_drop_columnfamily = help_drop_table
-
- def help_create_index(self):
- return 'createIndexStmt'
-
- def help_drop_index(self):
- return 'dropIndexStmt'
-
- def help_truncate(self):
- return 'truncateStmt'
-
- def help_create_type(self):
- return 'createTypeStmt'
-
- def help_alter_type(self):
- return 'alterTypeStmt'
-
- def help_drop_type(self):
- return 'dropTypeStmt'
-
- def help_create_function(self):
- return 'createFunctionStmt'
-
- def help_drop_function(self):
- return 'dropFunctionStmt'
-
- def help_functions(self):
- return 'functions'
-
- def help_create_aggregate(self):
- return 'createAggregateStmt'
-
- def help_drop_aggregate(self):
- return 'dropAggregateStmt'
-
- def help_aggregates(self):
- return 'aggregates'
-
- def help_create_trigger(self):
- return 'createTriggerStmt'
-
- def help_drop_trigger(self):
- return 'dropTriggerStmt'
-
- def help_create_materialized_view(self):
- return 'createMVStmt'
-
- def help_alter_materialized_view(self):
- return 'alterMVStmt'
-
- def help_drop_materialized_view(self):
- return 'dropMVStmt'
-
- def help_keywords(self):
- return 'appendixA'
-
- def help_create_user(self):
- return 'createUserStmt'
-
- def help_alter_user(self):
- return 'alterUserStmt'
-
- def help_drop_user(self):
- return 'dropUserStmt'
-
- def help_list_users(self):
- return 'listUsersStmt'
-
- def help_create_role(self):
- return 'createRoleStmt'
-
- def help_drop_role(self):
- return 'dropRoleStmt'
-
- def help_list_roles(self):
- return 'listRolesStmt'
-
- def help_permissions(self):
- return 'permissions'
-
- def help_list_permissions(self):
- return 'listPermissionsStmt'
-
- def help_grant(self):
- return 'grantRoleStmt'
-
- def help_revoke(self):
- return 'revokeRoleStmt'
+"""
+html_help_topics maps topics to HTML anchors
+"""
+html_help_topics = {
+ 'aggregates': 'aggregates',
+ 'alter_keyspace': 'alterKeyspaceStmt',
+ 'alter_materialized_view': 'alterMVStmt',
+ 'alter_table': 'alterTableStmt',
+ 'alter_type': 'alterTypeStmt',
+ 'alter_user': 'alterUserStmt',
+ 'apply': 'batchStmt',
+ 'ascii': 'constants',
+ 'batch': 'batchStmt',
+ 'begin': 'batchStmt',
+ 'blob': 'constants',
+ 'boolean': 'boolean',
+ 'counter': 'counters',
+ 'create_aggregate': 'createAggregateStmt',
+ 'create_columnfamily': 'createTableStmt',
+ 'create_function': 'createFunctionStmt',
+ 'create_index': 'createIndexStmt',
+ 'create_keyspace': 'createKeyspaceStmt',
+ 'create_materialized_view': 'createMVStmt',
+ 'create_role': 'createRoleStmt',
+ 'create_table': 'createTableStmt',
+ 'create_trigger': 'createTriggerStmt',
+ 'create_type': 'createTypeStmt',
+ 'create_user': 'createUserStmt',
+ 'date': 'usingdates',
+ 'delete': 'deleteStmt',
+ 'drop_aggregate': 'dropAggregateStmt',
+ 'drop_columnfamily': 'dropTableStmt',
+ 'drop_function': 'dropFunctionStmt',
+ 'drop_index': 'dropIndexStmt',
+ 'drop_keyspace': 'dropKeyspaceStmt',
+ 'drop_materialized_view': 'dropMVStmt',
+ 'drop_role': 'dropRoleStmt',
+ 'drop_table': 'dropTableStmt',
+ 'drop_trigger': 'dropTriggerStmt',
+ 'drop_type': 'dropTypeStmt',
+ 'drop_user': 'dropUserStmt',
+ 'functions': 'functions',
+ 'grant': 'grantRoleStmt',
+ 'insert': 'insertStmt',
+ 'insert_json': 'insertJson',
+ 'int': 'constants',
+ 'json': 'json',
+ 'keywords': 'appendixA',
+ 'list_permissions': 'listPermissionsStmt',
+ 'list_roles': 'listRolesStmt',
+ 'list_users': 'listUsersStmt',
+ 'permissions': 'permissions',
+ 'revoke': 'revokeRoleStmt',
+ 'select': 'selectStmt',
+ 'select_json': 'selectJson',
+ 'text': 'constants',
+ 'time': 'usingtime',
+ 'timestamp': 'usingtimestamps',
+ 'truncate': 'truncateStmt',
+ 'types': 'types',
+ 'update': 'updateStmt',
+ 'use': 'useStmt',
+ 'uuid': 'constants'}
+
+
+def get_html_topics():
+ return list(html_help_topics.keys())
+
+
+def get_html_anchor(topic):
+ return html_help_topics[topic]
diff --git a/pylib/setup.py b/pylib/setup.py
index f5fd1841b3..1dfd8cdc89 100755
--- a/pylib/setup.py
+++ b/pylib/setup.py
@@ -26,6 +26,7 @@ def get_extensions():
from Cython.Build import cythonize
return cythonize("cqlshlib/copyutil.py")
+
setup(
name="cassandra-pylib",
description="Cassandra Python Libraries",
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]