some cleanup and better use of die() function, thanks paolo

This commit is contained in:
mdipierro
2019-04-09 21:49:04 -07:00
parent 59700b8d06
commit b96c54cef9
5 changed files with 96 additions and 87 deletions
+9 -7
View File
@@ -193,6 +193,13 @@ def exec_pythonrc():
return dict()
def die(msg, exit_status=1, error_preamble=True):
if error_preamble:
msg = "%s: error: %s" % (sys.argv[0], msg)
print(msg, file=sys.stderr)
sys.exit(exit_status)
def run(
appname,
plain=False,
@@ -212,7 +219,7 @@ def run(
(a, c, f, args, vars) = parse_path_info(appname, av=True)
errmsg = 'invalid application name: %s' % appname
if not a:
die(errmsg)
die(errmsg, error_preamble=False)
adir = os.path.join('applications', a)
if not os.path.exists(adir):
@@ -258,7 +265,7 @@ def run(
elif os.path.isfile(pyfile):
execfile(pyfile, _env)
else:
die(errmsg)
die(errmsg, error_preamble=False)
if f:
exec('print( %s())' % f, _env)
@@ -358,11 +365,6 @@ def parse_path_info(path_info, av=False):
return (None, None, None)
def die(msg):
print(msg, file=sys.stderr)
sys.exit(1)
def test(testpath, import_models=True, verbose=False):
"""
Run doctests in web2py environment. testpath is formatted like: