PageRenderTime 464ms CodeModel.GetById 291ms app.highlight 4ms RepoModel.GetById 167ms app.codeStats 0ms

/silverlining/mgr-scripts/call-script.py

https://bitbucket.org/ianb/silverlining/
Python | 27 lines | 23 code | 3 blank | 1 comment | 3 complexity | 05b282ed8cc07f74d9eb08dbe3d2eb7a MD5 | raw file
 1import sys
 2import os
 3if os.path.exists(os.path.join(os.path.dirname(os.path.dirname(__file__)), 'runner.py')):
 4    # In development
 5    sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
 6else:
 7    sys.path.insert(0, '/usr/local/share/silverlining/lib')
 8from silversupport.appconfig import AppConfig
 9
10
11def main():
12    instance_name = sys.argv[1]
13    script = sys.argv[2]
14    if instance_name.startswith('/'):
15        app_ini = os.path.join(instance_name, 'app.ini')
16        app_config = AppConfig(app_ini)
17    else:
18        app_config = AppConfig.from_instance_name(instance_name)
19    app_config.activate_services(os.environ)
20    app_config.activate_path()
21    script = os.path.join(app_config.app_dir, script)
22    ns = {'__file__': script, '__name__': '__main__'}
23    sys.argv = [script] + sys.argv[3:]
24    execfile(script, ns)
25
26if __name__ == '__main__':
27    main()