better shell using create_app, thanks Paolo
This commit is contained in:
+15
-25
@@ -23,7 +23,6 @@ import glob
|
|||||||
import traceback
|
import traceback
|
||||||
import gluon.fileutils as fileutils
|
import gluon.fileutils as fileutils
|
||||||
from gluon.settings import global_settings
|
from gluon.settings import global_settings
|
||||||
from gluon.utils import web2py_uuid
|
|
||||||
from gluon.compileapp import build_environment, read_pyc, run_models_in
|
from gluon.compileapp import build_environment, read_pyc, run_models_in
|
||||||
from gluon.restricted import RestrictedError
|
from gluon.restricted import RestrictedError
|
||||||
from gluon.globals import Request, Response, Session
|
from gluon.globals import Request, Response, Session
|
||||||
@@ -137,14 +136,18 @@ def env(
|
|||||||
request.function)
|
request.function)
|
||||||
cmd_opts = global_settings.cmd_options
|
cmd_opts = global_settings.cmd_options
|
||||||
if cmd_opts:
|
if cmd_opts:
|
||||||
ip = cmd_opts.ip
|
if not cmd_opts.interfaces:
|
||||||
port = cmd_opts.port
|
ip = cmd_opts.ip
|
||||||
|
port = cmd_opts.port
|
||||||
|
else:
|
||||||
|
first_if = cmd_opts.interfaces[0]
|
||||||
|
ip = first_if[0]
|
||||||
|
port = first_if[1]
|
||||||
request.is_shell = cmd_opts.shell 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 = '127.0.0.1'; port = 8000
|
||||||
|
# FIXME: what about request.is_shell ?
|
||||||
|
request.is_scheduler = False
|
||||||
request.env.http_host = '%s:%s' % (ip, port)
|
request.env.http_host = '%s:%s' % (ip, port)
|
||||||
request.env.remote_addr = '127.0.0.1'
|
request.env.remote_addr = '127.0.0.1'
|
||||||
request.env.web2py_runtime_gae = global_settings.web2py_runtime_gae
|
request.env.web2py_runtime_gae = global_settings.web2py_runtime_gae
|
||||||
@@ -230,37 +233,24 @@ 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 not scheduler_job and \
|
if not cronjob and not scheduler_job and \
|
||||||
sys.stdin and not sys.stdin.name == '/dev/null':
|
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:
|
||||||
logging.warn('application does not exist and will not be created')
|
logging.warn('application does not exist and will not be created')
|
||||||
return
|
return
|
||||||
if confirm.lower() in ['y', 'yes']:
|
if confirm.lower() in ('y', 'yes'):
|
||||||
|
|
||||||
os.mkdir(adir)
|
os.mkdir(adir)
|
||||||
w2p_unpack('welcome.w2p', adir)
|
fileutils.create_app(adir)
|
||||||
for subfolder in ['models', 'views', 'controllers', 'databases',
|
|
||||||
'modules', 'cron', 'errors', 'sessions',
|
|
||||||
'languages', 'static', 'private', 'uploads']:
|
|
||||||
subpath = os.path.join(adir, subfolder)
|
|
||||||
if not os.path.exists(subpath):
|
|
||||||
os.mkdir(subpath)
|
|
||||||
db = os.path.join(adir, 'models/db.py')
|
|
||||||
if os.path.exists(db):
|
|
||||||
data = fileutils.read_file(db)
|
|
||||||
# NOTE: is this for backward compatibility ?
|
|
||||||
# there is no need for import gluon.utils otherwise
|
|
||||||
data = data.replace(
|
|
||||||
'<your secret key>', 'sha512:' + web2py_uuid())
|
|
||||||
fileutils.write_file(db, data)
|
|
||||||
|
|
||||||
if c:
|
if c:
|
||||||
import_models = True
|
import_models = True
|
||||||
extra_request = {}
|
extra_request = {}
|
||||||
if args:
|
if args:
|
||||||
extra_request['args'] = args
|
extra_request['args'] = args
|
||||||
|
if scheduler_job:
|
||||||
|
extra_request['is_scheduler'] = True
|
||||||
if vars:
|
if vars:
|
||||||
# underscore necessary because request.vars is a property
|
# underscore necessary because request.vars is a property
|
||||||
extra_request['_vars'] = vars
|
extra_request['_vars'] = vars
|
||||||
|
|||||||
Reference in New Issue
Block a user