1. jagguli
  2. aioweb

Commits

jagguli  committed 23e2db3

updated run script to handle testing and shell, use this to setup
environment for dev

  • Participants
  • Parent commits 3a0d820
  • Branches devel

Comments (0)

Files changed (1)

File bin/aioweb-launch.py

View file
 
 Usage:
     aioweb-launch.py startapp <project>
-    aioweb-launch.py execute <command>
+    aioweb-launch.py runtests <project> <tests>...
+    aioweb-launch.py execute <project> <command>
 
 Options:
     -h --help Show this 
+    -c --config Config file default: $XDG_CONFIG_HOME/aioweb/default.ini
 """
 from docopt import docopt
 import os
-from os.path import join, dirname, abspath
+from os.path import join, dirname, abspath, expanduser
 import sys
 import site
+import logging
+import configparser
+import nose
 
-paths = []
 
-base_path = abspath(os.getcwd())
-print(base_path)
-src_path = join(base_path, "src")
-lib_path = join(base_path, "lib")
-paths.append(src_path)
-sys.path.extend(paths)
-site.addsitedir(lib_path)
-os.chdir(src_path)
-environ = {}
-environ['PYTHONPATH'] = ":".join(sys.path)
-environ.update(os.environ)
+def read_config(configfile):
+    config = configparser.ConfigParser()
+    logging.debug("Reading config from: %s" % configfile)
+    config.read(configfile)
+    return config
+
+
+def set_path(app_path, environ):
+    src_path = join(app_path, "src")
+    lib_path = join(app_path, "lib")
+    sys.path.append(src_path)
+    site.addsitedir(lib_path)
+    environ.update(os.environ)
+    environ['PYTHONPATH'] = ":".join(sys.path)
+    # print(sys.path)
+
+
+def execute_in_project(arguments, config):
+    app_name = arguments['<project>']
+    app_config = config[app_name]
+    app_path = expanduser(app_config['path'])
+    dev_path = expanduser(config.get('default', 'dev_path'))
+    app_main = app_config.get('main', 'src/%s/application.py' % app_name)
+    app_command = arguments['<command>'] or "python3"
+    os.chdir(app_path)
+    environ = {}
+    set_path(app_path, environ)
+    if dev_path:
+        set_path(dev_path, environ)
+    if arguments['execute']:
+        os.execlpe(app_command, environ)
+    elif arguments['startapp']:
+        os.execvpe(app_command, (app_command, app_main,), environ)
+    elif arguments['runtests']:
+        sys.exit(nose.main(argv=['nose']+arguments['<tests>']))
+        
+
+paths = []
+aioweb_config_path = join(expanduser(os.environ.get('XDG_CONFIG_HOME', "~/.config")), "aioweb")
+aioweb_config_file = join(aioweb_config_path, "default.ini")
+print(aioweb_config_path)
+config = read_config(aioweb_config_file)
 arguments = docopt(__doc__, version='0.1')
 print(arguments)
-if arguments['execute']:
-    os.execvpe(sys.argv[2], sys.argv[2:], environ)
-elif arguments['startapp']:
-    os.execvpe("python3", sys.argv[1:], environ)
+execute_in_project(arguments, config)