diff options
author | Amjith Ramanujam <amjith.r@gmail.com> | 2018-12-01 14:04:36 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-01 14:04:36 -0800 |
commit | 59fe0e215e5b8d1ea0c43274b900a0fcf6b97888 (patch) | |
tree | 76eacdd3f526960a654201c0a75b88a83636acf6 | |
parent | a67a102da28efce646dc64479bec125d22a3f937 (diff) | |
parent | 40f8c24adf3e12023db0fc45e8d0130b9aed756b (diff) |
Merge pull request #24 from dbcli/j-bennet/remove-mysql
Removed mysql-specific stuff.
-rw-r--r-- | litecli/completion_refresher.py | 3 | ||||
-rw-r--r-- | litecli/liteclirc | 2 | ||||
-rwxr-xr-x | litecli/main.py | 13 | ||||
-rw-r--r-- | litecli/packages/special/dbcommands.py | 89 | ||||
-rw-r--r-- | tests/liteclirc | 5 | ||||
-rw-r--r-- | tests/utils.py | 3 |
6 files changed, 13 insertions, 102 deletions
diff --git a/litecli/completion_refresher.py b/litecli/completion_refresher.py index d9930b6..9602070 100644 --- a/litecli/completion_refresher.py +++ b/litecli/completion_refresher.py @@ -110,8 +110,7 @@ def refresh_databases(completer, executor): @refresher("schemata") def refresh_schemata(completer, executor): - # schemata - In MySQL Schema is the same as database. But for mycli - # schemata will be the name of the current database. + # name of the current database. completer.extend_schemata(executor.dbname) completer.set_dbname(executor.dbname) diff --git a/litecli/liteclirc b/litecli/liteclirc index 2bc900e..d7f098b 100644 --- a/litecli/liteclirc +++ b/litecli/liteclirc @@ -51,7 +51,7 @@ key_bindings = emacs # Enabling this option will show the suggestions in a wider menu. Thus more items are suggested. wider_completion_menu = False -# MySQL prompt +# litecli prompt # \D - The full current date # \d - Database name # \m - Minutes of the current time diff --git a/litecli/main.py b/litecli/main.py index 2c3723a..6a44fec 100755 --- a/litecli/main.py +++ b/litecli/main.py @@ -61,21 +61,18 @@ class LiteCli(object): default_prompt = "\\d> " max_len_prompt = 45 - defaults_suffix = None def __init__( self, sqlexecute=None, prompt=None, logfile=None, - defaults_suffix=None, auto_vertical_output=False, warn=None, liteclirc=None, ): self.sqlexecute = sqlexecute self.logfile = logfile - self.defaults_suffix = defaults_suffix # Load config. c = self.config = get_config(liteclirc) @@ -289,9 +286,6 @@ class LiteCli(object): sections = ["client"] - if self.defaults_suffix: - sections.extend([sect + self.defaults_suffix for sect in sections]) - def get(key): result = None for sect in cnf: @@ -857,11 +851,6 @@ class LiteCli(object): help="Log every query and its results to a file.", ) @click.option( - "--defaults-group-suffix", - type=str, - help="Read MySQL config groups with the specified suffix.", -) -@click.option( "--liteclirc", default=config_location() + "config", help="Location of liteclirc file.", @@ -888,7 +877,6 @@ def cli( verbose, prompt, logfile, - defaults_group_suffix, auto_vertical_output, table, csv, @@ -911,7 +899,6 @@ def cli( litecli = LiteCli( prompt=prompt, logfile=logfile, - defaults_suffix=defaults_group_suffix, auto_vertical_output=auto_vertical_output, warn=warn, liteclirc=liteclirc, diff --git a/litecli/packages/special/dbcommands.py b/litecli/packages/special/dbcommands.py index 67dc769..8d30b63 100644 --- a/litecli/packages/special/dbcommands.py +++ b/litecli/packages/special/dbcommands.py @@ -109,41 +109,17 @@ def list_databases(cur, **_): @special_command( - "status", + ".status", "\\s", - "Get status information from the server.", + "Show current settings.", arg_type=RAW_QUERY, aliases=("\\s",), case_sensitive=True, ) def status(cur, **_): - query = "SHOW GLOBAL STATUS;" - log.debug(query) - try: - cur.execute(query) - except ProgrammingError: - # Fallback in case query fail, as it does with Mysql 4 - query = "SHOW STATUS;" - log.debug(query) - cur.execute(query) - status = dict(cur.fetchall()) - - query = "SHOW GLOBAL VARIABLES;" - log.debug(query) - cur.execute(query) - variables = dict(cur.fetchall()) - - # prepare in case keys are bytes, as with Python 3 and Mysql 4 - if isinstance(list(variables)[0], bytes) and isinstance(list(status)[0], bytes): - variables = {k.decode("utf-8"): v.decode("utf-8") for k, v in variables.items()} - status = {k.decode("utf-8"): v.decode("utf-8") for k, v in status.items()} - # Create output buffers. - title = [] - output = [] footer = [] - - title.append("--------------") + footer.append("--------------") # Output the litecli client information. implementation = platform.python_implementation() @@ -151,21 +127,17 @@ def status(cur, **_): client_info = [] client_info.append("litecli {0},".format(__version__)) client_info.append("running on {0} {1}".format(implementation, version)) - title.append(" ".join(client_info) + "\n") + footer.append(" ".join(client_info)) # Build the output that will be displayed as a table. - output.append(("Connection id:", cur.connection.thread_id())) - - query = "SELECT DATABASE(), USER();" + query = "SELECT file from pragma_database_list() where name = 'main';" log.debug(query) cur.execute(query) - db, user = cur.fetchone() + db = cur.fetchone()[0] if db is None: db = "" - output.append(("Current database:", db)) - output.append(("Current user:", user)) - + footer.append("Current database: " + db) if iocommands.is_pager_enabled(): if "PAGER" in os.environ: pager = os.environ["PAGER"] @@ -173,50 +145,7 @@ def status(cur, **_): pager = "System default" else: pager = "stdout" - output.append(("Current pager:", pager)) - - output.append( - ( - "Server version:", - "{0} {1}".format(variables["version"], variables["version_comment"]), - ) - ) - output.append(("Protocol version:", variables["protocol_version"])) - - if "unix" in cur.connection.host_info.lower(): - host_info = cur.connection.host_info - else: - host_info = "{0} via TCP/IP".format(cur.connection.host) - - output.append(("Connection:", host_info)) - - query = ( - "SELECT @@character_set_server, @@character_set_database, " - "@@character_set_client, @@character_set_connection LIMIT 1;" - ) - log.debug(query) - cur.execute(query) - charset = cur.fetchone() - output.append(("Server characterset:", charset[0])) - output.append(("Db characterset:", charset[1])) - output.append(("Client characterset:", charset[2])) - output.append(("Conn. characterset:", charset[3])) - output.append(("Uptime:", format_uptime(status["Uptime"]))) - - # Print the current server statistics. - stats = [] - stats.append("Connections: {0}".format(status["Threads_connected"])) - if "Queries" in status: - stats.append("Queries: {0}".format(status["Queries"])) - stats.append("Slow queries: {0}".format(status["Slow_queries"])) - stats.append("Opens: {0}".format(status["Opened_tables"])) - stats.append("Flush tables: {0}".format(status["Flush_commands"])) - stats.append("Open tables: {0}".format(status["Open_tables"])) - if "Queries" in status: - queries_per_second = int(status["Queries"]) / int(status["Uptime"]) - stats.append("Queries per second avg: {:.3f}".format(queries_per_second)) - stats = " ".join(stats) - footer.append("\n" + stats) + footer.append("Current pager:" + pager) footer.append("--------------") - return [("\n".join(title), output, "", "\n".join(footer))] + return [(None, None, "", "\n".join(footer))] diff --git a/tests/liteclirc b/tests/liteclirc index 1f25107..b899d62 100644 --- a/tests/liteclirc +++ b/tests/liteclirc @@ -51,18 +51,15 @@ key_bindings = emacs # Enabling this option will show the suggestions in a wider menu. Thus more items are suggested. wider_completion_menu = False -# MySQL prompt +# litecli prompt # \D - The full current date # \d - Database name -# \h - Hostname of the server # \m - Minutes of the current time # \n - Newline # \P - AM/PM -# \p - Port # \R - The current time, in 24-hour military time (0–23) # \r - The current time, standard 12-hour time (1–12) # \s - Seconds of the current time -# \t - Product type (Percona, MySQL, MariaDB) prompt = '\t :\d> ' prompt_continuation = '-> ' diff --git a/tests/utils.py b/tests/utils.py index 9a56709..41bac9b 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -27,8 +27,7 @@ except Exception as ex: CAN_CONNECT_TO_DB = False dbtest = pytest.mark.skipif( - not CAN_CONNECT_TO_DB, - reason="Need a mysql instance at localhost accessible by user 'root'", + not CAN_CONNECT_TO_DB, reason="Error creating sqlite connection" ) |