better option handling for the shell, thanks Paolo

This commit is contained in:
mdipierro
2019-04-19 21:23:59 -07:00
parent 0d04b8a511
commit 8a9b2d687e
+18 -8
View File
@@ -135,11 +135,14 @@ def env(
request.function = f or 'index' request.function = f or 'index'
response.view = '%s/%s.html' % (request.controller, response.view = '%s/%s.html' % (request.controller,
request.function) request.function)
if global_settings.cmd_options: cmd_opts = global_settings.cmd_options
ip = global_settings.cmd_options.ip if cmd_opts:
port = global_settings.cmd_options.port ip = cmd_opts.ip
request.is_shell = global_settings.cmd_options.shell is not None port = cmd_opts.port
request.is_scheduler = global_settings.cmd_options.scheduler is not None request.is_shell = cmd_opts.shell is not None
# FIXME: cmd_opts.scheduler does not imply that
# we are running in the scheduler
request.is_scheduler = cmd_opts.scheduler is not None
else: else:
ip, port = '127.0.0.1', '8000' ip, port = '127.0.0.1', '8000'
request.env.http_host = '%s:%s' % (ip, port) request.env.http_host = '%s:%s' % (ip, port)
@@ -206,14 +209,18 @@ def run(
import_models=False, import_models=False,
startfile=None, startfile=None,
bpython=False, bpython=False,
python_code=False, python_code=None,
cronjob=False): cronjob=False,
scheduler_job=False):
""" """
Start interactive shell or run Python script (startfile) in web2py Start interactive shell or run Python script (startfile) in web2py
controller environment. appname is formatted like: controller environment. appname is formatted like:
- a : web2py application name - a : web2py application name
- a/c : exec the controller c into the application environment - a/c : exec the controller c into the application environment
- a/c/f : exec the controller c, then the action f
into the application environment
- a/c/f?x=y : as above
""" """
(a, c, f, args, vars) = parse_path_info(appname, av=True) (a, c, f, args, vars) = parse_path_info(appname, av=True)
@@ -223,7 +230,8 @@ def run(
adir = os.path.join('applications', a) adir = os.path.join('applications', a)
if not os.path.exists(adir): if not os.path.exists(adir):
if sys.stdin and not sys.stdin.name == '/dev/null': if not scheduler_job and \
sys.stdin and not sys.stdin.name == '/dev/null':
confirm = raw_input( confirm = raw_input(
'application %s does not exist, create (y/n)?' % a) 'application %s does not exist, create (y/n)?' % a)
else: else:
@@ -242,6 +250,8 @@ def run(
db = os.path.join(adir, 'models/db.py') db = os.path.join(adir, 'models/db.py')
if os.path.exists(db): if os.path.exists(db):
data = fileutils.read_file(db) data = fileutils.read_file(db)
# NOTE: is this for backward compatibility ?
# there is no need for import gluon.utils otherwise
data = data.replace( data = data.replace(
'<your secret key>', 'sha512:' + web2py_uuid()) '<your secret key>', 'sha512:' + web2py_uuid())
fileutils.write_file(db, data) fileutils.write_file(db, data)