Commit f888a0ae authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Adapt the run script to execute script in a multi-application context.

The script argument "application" is added.
parent 8756dfff
#!/usr/bin/env python
# -*- coding: utf-8 -*-
""" NAME
run -- run a script using the application model
run -- run a script using the application model
SYNOPSIS
run [options] script.py
DESCRIPTION
run the script in the web2py context when the
run the script in the web2py context when the
application model is instantiated.
OPTIONS
-a, --application
Name of the application
-h, --help
Display the help and exit.
EXAMPLE
> cd ... myapp/scripts
> ./run myscript.py
AUTHOR
R. Le Gac
"""
if __name__ == "__main__":
import os
import subprocess
import sys
from argparse import ArgumentParser
APP = os.getcwd().split(os.sep)[-2]
WEB2PY_DIR = '../../web2py'
WEB2PY = os.path.join(WEB2PY_DIR, 'web2py.py')
# command line options
parser = ArgumentParser()
parser.add_argument('-a', '--app',
default=APP,
dest='application',
help='the name of the application.')
parser.add_argument('script',
help='the name of the script to be run.')
parser.add_argument('args',
nargs='*',
help='the arguments for the script.')
args = parser.parse_args()
# run the script in the track_publication context
# run the script in the application context
script_path = os.path.join(os.getcwd(), args.script)
cmd = [WEB2PY,
'--no-banner',
'--shell', APP,
'--shell', args.application,
'--import_models',
'--run', script_path]
if args.args:
cmd.append('--args')
cmd.extend(args.args)
return_code = subprocess.call(cmd)
# exit
sys.exit(return_code)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment