From 6749a96425c40fdca129d8dc1c1f639c29768c67 Mon Sep 17 00:00:00 2001 From: zamentur Date: Mon, 3 Nov 2014 21:29:59 +0100 Subject: [PATCH] [enh] Support modules system [enh] List modules for adminjs --- actionsmap/yunohost.yml | 10 +++++++++- app.py | 13 ++++++++++++- bin/yunohost | 6 +++++- bin/yunohost-api | 24 +++++++++++++++++++++--- 4 files changed, 47 insertions(+), 6 deletions(-) diff --git a/actionsmap/yunohost.yml b/actionsmap/yunohost.yml index a3012d582..bc819cbbd 100644 --- a/actionsmap/yunohost.yml +++ b/actionsmap/yunohost.yml @@ -35,7 +35,7 @@ _global: configuration: authenticate: - - api + - cli authenticator: default: vendor: ldap @@ -550,6 +550,14 @@ app: apps: nargs: "+" + #~ ### app_listmodules() + listmodules: + action_help: List all web admin modules + api: GET /modules + configuration: + authenticate: + authenticator: ldap-anonymous + ############################# # Backup # ############################# diff --git a/app.py b/app.py index 090d7d05b..27f978fbf 100644 --- a/app.py +++ b/app.py @@ -42,6 +42,7 @@ apps_path = '/usr/share/yunohost/apps' apps_setting_path= '/etc/yunohost/apps/' install_tmp = '/var/cache/yunohost' app_tmp_folder = install_tmp + '/from_file' +modules_path = '/usr/share/yunohost/admin/modules/' def app_listlists(): """ @@ -950,7 +951,17 @@ def app_ssowatconf(auth): msignals.display(m18n.n('ssowat_conf_generated'), 'success') - +def app_listmodules(): + """ + List all modules set up in modules directory + /usr/share/yunohost/admin/modules/ + """ + try: + modules=os.walk(modules_path).next()[1] #[x[0] for x in os.walk(modules_path)] + except OSError: + modules = [] + return { 'modules' : modules } + def _extract_app_from_file(path, remove=False): """ Unzip or untar application tarball in app_tmp_folder, or copy it from a directory diff --git a/bin/yunohost b/bin/yunohost index 7913de091..14a21d8b1 100755 --- a/bin/yunohost +++ b/bin/yunohost @@ -51,5 +51,9 @@ if __name__ == '__main__': sys.exit(1) # Execute the action - ret = cli(['yunohost'], args, print_json=json, use_cache=cache) + from os import listdir + from os.path import isfile, join + path='/usr/share/moulinette/actionsmap/' + modules = [ f[:-4] for f in listdir(path) if isfile(join(path,f))] + ret = cli(modules, args, print_json=json, use_cache=cache) sys.exit(ret) diff --git a/bin/yunohost-api b/bin/yunohost-api index b8dcab558..826b4a3e3 100755 --- a/bin/yunohost-api +++ b/bin/yunohost-api @@ -3,6 +3,9 @@ import sys import os.path +import yaml +from os import listdir +from os.path import isfile, join from_source = False @@ -28,6 +31,17 @@ def is_installed(): return { 'installed': installed } +def _get_modules(): + """ + Get a dict of managed services with their parameters + + """ + from os import listdir + from os.path import isfile, join + path='/usr/share/moulinette/actionsmap/' + onlyfiles = [ f[:-4] for f in listdir(path) if isfile(join(path,f))] + return onlyfiles + ## Main action if __name__ == '__main__': @@ -46,10 +60,14 @@ if __name__ == '__main__': # TODO: Add log argument try: - # Run the server - api(['yunohost'], port=6787, + # Run the server + from os import listdir + from os.path import isfile, join + path='/usr/share/moulinette/actionsmap/' + modules = [ f[:-4] for f in listdir(path) if isfile(join(path,f))] + api(modules, port=6787, routes={('GET', '/installed'): is_installed}, - use_cache=cache, use_websocket=websocket) + use_cache=False, use_websocket=websocket) except MoulinetteError as e: from moulinette.interfaces.cli import colorize print('%s %s' % (colorize(m18n.g('error'), 'red'), e.strerror))