Commit 90f47f75 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Add the script launcher: track_publications.

parent 4d4251da
......@@ -26,11 +26,11 @@
EXAMPLE
> cd web2py
> python web2py.py --shell track_publications -M --run fix-country.py
> cd ... /track_publications/scripts
> ./track_publications fix-country.py
AUTHOR
R. Le Gac
R. Le Gac -- Nov 2014
"""
from callbacks import INHIBIT_PUBLICATION_UPDATE_ON_OK
......
#!/usr/bin/env python
# -*- coding: utf-8 -*-
""" NAME
track_publications -- run a script within track_publications
SYNOPSIS
track_publications [options] script.py
DESCRIPTION
run the script in the web2py context when the track_publications
model is instantiated.
OPTIONS
-h, --help
Display the help and exit.
EXAMPLE
> cd ... track_publications/scripts
> ./track_publications myscript.py
AUTHOR
R. Le Gac
"""
if __name__ == "__main__":
import os
import subprocess
import sys
from argparse import ArgumentParser
WEB2PY_DIR = '../../web2py'
WEB2PY = os.path.join(WEB2PY_DIR, 'web2py.py')
# command line options
parser = ArgumentParser()
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
script_path = os.path.join(os.getcwd(), args.script)
cmd = [WEB2PY,
'--no-banner',
'--shell', 'track_publications',
'--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