Fix route registering

This commit is contained in:
Kload 2013-11-21 11:33:48 +01:00
parent d9d7d0ef24
commit 8f12b330b0

View file

@ -117,6 +117,10 @@ def http_exec(request, **kwargs):
raise YunoHostError(1, _("A YunoHost command is already running")) raise YunoHostError(1, _("A YunoHost command is already running"))
except IOError: except IOError:
if dict['function'].split('.')[1] != 'tools_postinstall': if dict['function'].split('.')[1] != 'tools_postinstall':
try:
with open('/etc/yunohost/installed'): pass
except IOError:
raise YunoHostError(1, _("You must run postinstall before any other actions"))
with open('/var/run/yunohost.pid', 'w') as f: with open('/var/run/yunohost.pid', 'w') as f:
f.write('ldap') f.write('ldap')
os.system('chmod 400 /var/run/yunohost.pid') os.system('chmod 400 /var/run/yunohost.pid')
@ -212,38 +216,26 @@ def main():
action_map = yaml.load(f) action_map = yaml.load(f)
# Register only postinstall action if YunoHost isn't completely set up # Register only postinstall action if YunoHost isn't completely set up
try: del action_map['general_arguments']
with open('/etc/yunohost/installed') as f: pass for category, category_params in action_map.items():
except IOError: api.register('ALL', '/api/'+ category, api_doc)
installed = False for action, action_params in category_params['actions'].items():
api.register('POST', '/postinstall', http_exec) if 'action_help' not in action_params:
api.register('OPTIONS', '/postinstall', http_exec) action_params['action_help'] = ''
action_dict['POST /postinstall'] = { if 'api' not in action_params:
'function' : 'yunohost_tools.tools_postinstall', action_params['api'] = 'GET /'+ category +'/'+ action
'help' : 'Execute post-install', method, path = action_params['api'].split(' ')
'arguments' : action_map['tools']['actions']['postinstall']['arguments'] # Register route
} if '{' in path:
else: path = path.replace('{', '(?P<').replace('}', '>[^/]+)')
del action_map['general_arguments'] api.register(method, path, http_exec)
for category, category_params in action_map.items(): api.register('OPTIONS', path, http_exec)
api.register('ALL', '/api/'+ category, api_doc) action_dict[action_params['api']] = {
for action, action_params in category_params['actions'].items(): 'function': 'yunohost_'+ category +'.'+ category +'_'+ action,
if 'action_help' not in action_params: 'help' : action_params['action_help']
action_params['action_help'] = '' }
if 'api' not in action_params: if 'arguments' in action_params:
action_params['api'] = 'GET /'+ category +'/'+ action action_dict[action_params['api']]['arguments'] = action_params['arguments']
method, path = action_params['api'].split(' ')
# Register route
if '{' in path:
path = path.replace('{', '(?P<').replace('}', '>[^/]+)')
api.register(method, path, http_exec)
api.register('OPTIONS', path, http_exec)
action_dict[action_params['api']] = {
'function': 'yunohost_'+ category +'.'+ category +'_'+ action,
'help' : action_params['action_help']
}
if 'arguments' in action_params:
action_dict[action_params['api']]['arguments'] = action_params['arguments']
api.register('ALL', '/installed', is_installed) api.register('ALL', '/installed', is_installed)