def run(args, kwargs): if len(args) < 1: app_log.error(show_usage('run')) return if len(args) > 1: app_log.error('Can only run one app. Ignoring %s', ', '.join(args[1:])) appname = args.pop(0) app_config = get_app_config(appname, kwargs) target = app_config.target if 'dir' in app_config: target = os.path.join(target, app_config.dir) if os.path.isdir(target): os.chdir(target) gramex.paths['base'] = Path('.') # If we run with updated parameters, save for next run under the .run config run_config = app_config.setdefault('run', {}) for key, val in kwargs.items(): if key not in app_keys: run_config[key] = app_config.pop(key) save_user_config(appname, app_config) # Tell the user what configs are used cline = ' '.join('--%s=%s' % arg for arg in flatten_config(app_config.get('run', {}))) app_log.info('Gramex %s | %s %s | %s | Python %s', gramex.__version__, appname, cline, os.getcwd(), sys.version.replace('\n', ' ')) gramex.init(args=AttrDict(app=app_config['run'])) elif appname in apps_config['user']: # The user configuration has a wrong path. Inform user app_log.error('%s: no directory %s', appname, app_config.target) app_log.error('Run "gramex uninstall %s" and try again.', appname) else: app_log.error('%s: no directory %s', appname, app_config.target)
def test_init(self): self.check('/init/new', code=404) gramex.init( app=AttrDict( url=AttrDict( init_new=AttrDict( pattern='/init/new', handler='FunctionHandler', kwargs=AttrDict( function='json.dumps({"key": "val1"})' ) ) ) ) ) self.check('/init/new', text='{"key": "val1"}') gramex.init( app=AttrDict( url=AttrDict( init_new=AttrDict( pattern='/init/new', handler='FunctionHandler', kwargs=AttrDict( function='json.dumps({"key": "val2"})' ) ) ) ) ) self.check('/init/new', text='{"key": "val2"}')
def run_gramex(): os.chdir(str(info.folder)) try: gramex.init() except Exception as e: info.exception = e info.thread = None
def re_init(): gramex.init( app=AttrDict( url=AttrDict( init_reload=AttrDict( pattern='/init/reload', handler='utils.CounterHandler' ) ) ) )
def crud(handler): method = handler.path_args[0] if method == 'post': conf = handler.get_argument('data', {}) conf = json.loads(conf, object_pairs_hook=AttrDict) paths = deepcopy(gramex.paths) gramex.paths = AttrDict() gramex.init(new=conf) gramex.paths = paths elif method == 'init': gramex.init() # TODO: generated keys cannot be deleted from gramex.conf return gramex.conf