1
0
Fork 0

Merge remote-tracking branch 'upstream/master' into keep_callables

This commit is contained in:
catherinedevlin 2018-05-14 16:31:19 -04:00
commit dc74a0acd0
3 changed files with 37 additions and 22 deletions

View File

@ -76,6 +76,7 @@ Contributors:
* Pierre Giraud
* Andrew Kuchling
* Catherine Devlin
* Jason Ribeiro
Creator:

View File

@ -1,12 +1,20 @@
Upcoming:
=========
Features:
---------
* Add quit commands to the completion menu. (Thanks: `Jason Ribeiro`_)
Internal changes:
-----------------
* Mark tests requiring a running database server as dbtest (Thanks: `Dick Marinus`_)
* Add ``application_name`` to help identify pgcli connection to database (issue #868) (Thanks: `François Pietka`_)
Bug Fixes:
----------
* Disable pager when using \watch (#837). (Thanks: `Jason Ribeiro`_)
1.9.1:
======
@ -814,3 +822,4 @@ Improvements:
.. _`Isank`: https://github.com/isank
.. _`Bojan Delić`: https://github.com/delicb
.. _`Frederic Aoustin`: https://github.com/fraoustin
.. _`Jason Ribeiro`: https://github.com/jrib

View File

@ -90,6 +90,10 @@ OutputSettings.__new__.__defaults__ = (
)
class PgCliQuitError(Exception):
pass
class PGCli(object):
default_prompt = '\\u@\\h:\\d> '
@ -199,6 +203,9 @@ class PGCli(object):
self.eventloop = create_eventloop()
self.cli = None
def quit(self):
raise PgCliQuitError
def register_special_commands(self):
self.pgspecial.register(
@ -208,6 +215,12 @@ class PGCli(object):
refresh_callback = lambda: self.refresh_completions(
persist_priorities='all')
self.pgspecial.register(self.quit, '\\q', '\\q',
'Quit pgcli.', arg_type=NO_QUERY, case_sensitive=True,
aliases=(':q',))
self.pgspecial.register(self.quit, 'quit', 'quit',
'Quit pgcli.', arg_type=NO_QUERY, case_sensitive=False,
aliases=('exit',))
self.pgspecial.register(refresh_callback, '\\#', '\\#',
'Refresh auto-completions.', arg_type=NO_QUERY)
self.pgspecial.register(refresh_callback, '\\refresh', '\\refresh',
@ -473,6 +486,8 @@ class PGCli(object):
logger.error("sql: %r, error: %r", text, e)
logger.error("traceback: %r", traceback.format_exc())
self._handle_server_closed_connection()
except PgCliQuitError as e:
raise
except Exception as e:
logger.error("sql: %r, error: %r", text, e)
logger.error("traceback: %r", traceback.format_exc())
@ -539,13 +554,6 @@ class PGCli(object):
while True:
document = self.cli.run()
# The reason we check here instead of inside the pgexecute is
# because we want to raise the Exit exception which will be
# caught by the try/except block that wraps the pgexecute.run()
# statement.
if quit_command(document.text):
raise EOFError
try:
document = self.handle_editor_command(self.cli, document)
except RuntimeError as e:
@ -557,15 +565,19 @@ class PGCli(object):
# Initialize default metaquery in case execution fails
query = MetaQuery(query=document.text, successful=False)
watch_command, timing = special.get_watch_command(document.text)
if watch_command:
while watch_command:
self.watch_command, timing = special.get_watch_command(
document.text)
if self.watch_command:
while self.watch_command:
try:
query = self.execute_command(watch_command, query)
click.echo('Waiting for {0} seconds before repeating'.format(timing))
query = self.execute_command(
self.watch_command, query)
click.echo(
'Waiting for {0} seconds before repeating'
.format(timing))
sleep(timing)
except KeyboardInterrupt:
watch_command = None
self.watch_command = None
else:
query = self.execute_command(document.text, query)
@ -577,7 +589,7 @@ class PGCli(object):
self.query_history.append(query)
except EOFError:
except PgCliQuitError:
if not self.less_chatty:
print ('Goodbye!')
@ -833,7 +845,7 @@ class PGCli(object):
return self.query_history[-1][0] if self.query_history else None
def echo_via_pager(self, text, color=None):
if self.pgspecial.pager_config == PAGER_OFF:
if self.pgspecial.pager_config == PAGER_OFF or self.watch_command:
click.echo(text, color=color)
else:
click.echo_via_pager(text, color)
@ -1026,13 +1038,6 @@ def is_select(status):
return status.split(None, 1)[0].lower() == 'select'
def quit_command(sql):
return (sql.strip().lower() == 'exit'
or sql.strip().lower() == 'quit'
or sql.strip() == r'\q'
or sql.strip() == ':q')
def exception_formatter(e):
return click.style(utf8tounicode(str(e)), fg='red')