Skip to content

Commit 31359db

Browse files
author
James William Pye
committed
Correct \e execution and use postgresql.__version__ for the console scripts.
1 parent 49706cc commit 31359db

5 files changed

Lines changed: 28 additions & 16 deletions

File tree

postgresql/bin/pg_dotconf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
from optparse import OptionParser
55
from .. import configfile
6+
from .. import __version__
67

78
__all__ = ['command']
89

@@ -12,7 +13,7 @@ def command(args):
1213
"""
1314
op = OptionParser(
1415
"%prog [--stdout] [-f settings] postgresql.conf ([param=val]|[param])*",
15-
version = '1.0'
16+
version = __version__
1617
)
1718
op.add_option(
1819
'-f', '--file',

postgresql/bin/pg_python.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import contextlib
1414
from .. import clientparameters
1515
from ..resolved import pythoncommand as pycmd
16+
from .. import __version__
1617

1718
from ..driver import default as pg_driver
1819
from .. import exceptions as pg_exc
@@ -30,7 +31,7 @@
3031
def command(argv = sys.argv):
3132
p = clientparameters.DefaultParser(
3233
"%prog [connection options] [script] ...",
33-
version = '1.0',
34+
version = __version__,
3435
option_list = default_options
3536
)
3637
p.disable_interspersed_args()

postgresql/bin/pg_tin.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
from .. import versionstring as pg_version
2121
from ..cluster import Cluster
22+
from .. import __version__
2223

2324
from gettext import gettext as _
2425

@@ -219,7 +220,7 @@ def command(args):
219220

220221
op = optparse.OptionParser(
221222
COMMAND_HELP,
222-
version = '1.0',
223+
version = __version__,
223224
)
224225
op.allow_interspersed_args = False
225226

postgresql/bin/pg_withcluster.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
import subprocess as sp
77
import getpass
88
from optparse import OptionParser
9-
from postgresql.cluster import Cluster
10-
from postgresql.installation import Installation
119

12-
def main(args = sys.argv):
10+
from ..cluster import Cluster
11+
from ..installation import Installation
12+
from .. import __version__
13+
14+
def command(argv = sys.argv):
1315
op = OptionParser(
1416
"%prog [-p] [--version] {[setting=value], ...} [pg_config] command",
15-
version = '1.0'
17+
version = __version__
1618
)
1719
op.allow_interspersed_args = False
1820
op.add_option(
@@ -95,4 +97,4 @@ def main(args = sys.argv):
9597
c.drop()
9698

9799
if __name__ == '__main__':
98-
sys.exit(main())
100+
sys.exit(command(argv=sys.argv))

postgresql/resolved/pythoncommand.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,10 @@ def __init__(self, *args, **kw):
230230
self.register_backslash(r'\x', self.bs_x,
231231
"Execute the Python command within this process.")
232232

233+
def interact(self, *args, **kw):
234+
self.showhelp(None, None)
235+
super().interact(*args,**kw)
236+
233237
def register_backslash(self, bscmd, meth, doc):
234238
self.bsc_map[bscmd] = (meth, doc)
235239

@@ -308,7 +312,7 @@ def execfile(self, filepath):
308312
src.close()
309313
if co is not None:
310314
try:
311-
exec(co, self.globals, self.locals)
315+
exec(co, self.locals, self.locals)
312316
except:
313317
e, v, tb = sys.exc_info()
314318
print_exception(e, v, tb.tb_next or tb)
@@ -330,7 +334,7 @@ def bs_E(self, cmd, arg):
330334
self.editfiles([self.resolve_path(x) for x in self.split(arg) or ('',)])
331335

332336
def bs_e(self, cmd, arg):
333-
'edit and execute the files'
337+
'edit *and* execute the files'
334338
filepaths = [self.resolve_path(x) for x in self.split(arg) or ('',)]
335339
self.editfiles(filepaths)
336340
for x in filepaths:
@@ -341,7 +345,10 @@ def bs_x(self, cmd, arg):
341345
if len(cmd) > 1:
342346
a = self.split(arg)
343347
a.insert(0, '\\x')
344-
rv = command(args = a)
348+
try:
349+
rv = command(argv = a)
350+
except SystemExit as se:
351+
rv = se.code
345352
self.write("[Return Value: %d]%s" %(rv, os.linesep))
346353

347354
def push(self, line):
@@ -591,8 +598,8 @@ def get_main_source(self):
591598
if path is not None:
592599
return loader.get_source(path)
593600

594-
def command_execution(args = sys.argv):
595-
'create an execution using the given args'
601+
def command_execution(argv = sys.argv):
602+
'create an execution using the given argv'
596603
# The pwd should be in the path for python commands.
597604
# setuptools' console_scripts appear to strip this out.
598605
if '' not in sys.path:
@@ -604,15 +611,15 @@ def command_execution(args = sys.argv):
604611
)
605612
op.disable_interspersed_args()
606613
op.add_options(default_optparse_options)
607-
co, ca = op.parse_args(args[1:])
614+
co, ca = op.parse_args(argv[1:])
608615

609616
return Execution(ca,
610617
context = getattr(co, 'python_context', ()),
611618
loader = getattr(co, 'python_main', None),
612619
)
613620

614-
def command(args = sys.argv):
615-
return command_execution(args = args)(
621+
def command(argv = sys.argv):
622+
return command_execution(argv = argv)(
616623
context = postmortem(os.environ.get('PYTHON_POSTMORTEM'))
617624
)
618625

0 commit comments

Comments
 (0)