diff --git a/data/actionsmap/yunohost.yml b/data/actionsmap/yunohost.yml index 8e8f4ab2..10cd95a2 100644 --- a/data/actionsmap/yunohost.yml +++ b/data/actionsmap/yunohost.yml @@ -359,6 +359,8 @@ app: install: action_help: Install apps api: POST /app + configuration: + authenticate: all arguments: app: help: App to install @@ -446,6 +448,8 @@ app: checkurl: action_help: Check availability of a web path api: GET /app/checkurl + configuration: + authenticate: all arguments: url: help: Url to check @@ -474,11 +478,15 @@ app: ssowatconf: action_help: Regenerate SSOwat configuration file api: PUT /ssowatconf + configuration: + authenticate: all ### app_addaccess() TODO: Write help addaccess: action_help: Grant access right to users (everyone by default) api: PUT /app/access + configuration: + authenticate: all arguments: apps: nargs: "+" @@ -490,6 +498,8 @@ app: removeaccess: action_help: Revoke access right to users (everyone by default) api: DELETE /app/access + configuration: + authenticate: all arguments: apps: nargs: "+" @@ -501,6 +511,8 @@ app: clearaccess: action_help: Reset access rights for the app api: POST /app/access + configuration: + authenticate: all arguments: apps: nargs: "+" diff --git a/lib/yunohost/app.py b/lib/yunohost/app.py index 8884d788..59912770 100644 --- a/lib/yunohost/app.py +++ b/lib/yunohost/app.py @@ -23,9 +23,6 @@ Manage apps """ -import logging -logging.warning('the module yunohost.app has not been revisited and updated yet') - import os import sys import json @@ -36,11 +33,9 @@ import time import re import socket import urlparse -from domain import domain_list, domain_add -from user import user_info, user_list -from hook import hook_exec, hook_add, hook_remove -from moulinette.helpers import YunoHostError, YunoHostLDAP, win_msg, random_password, is_true, validate +from moulinette.helpers import win_msg, random_password, is_true, validate +from moulinette.core import MoulinetteError repo_path = '/var/cache/yunohost/repo' apps_path = '/usr/share/yunohost/apps' @@ -60,7 +55,7 @@ def app_listlists(): if '.json' in filename: list_list.append(filename[:len(filename)-5]) except OSError: - raise YunoHostError(1, _("No list found")) + raise MoulinetteError(1, _("No list found")) return { 'Lists' : list_list } @@ -82,20 +77,20 @@ def app_fetchlist(url=None, name=None): url = 'http://app.yunohost.org/list.json' name = 'yunohost' else: - if name is None: raise YunoHostError(22, _("You must indicate a name for your custom list")) + if name is None: raise MoulinetteError(22, _("You must indicate a name for your custom list")) - list_file = repo_path +'/'+ name +'.json' - if os.system('wget "'+ url +'" -O "'+ list_file +'.tmp"') != 0: - os.remove(list_file +'.tmp') - raise YunoHostError(1, _("List server connection failed")) + list_file = '%s/%s.json' % (repo_path, name) + if os.system('wget "%s" -O "%s.tmp"' % (url, list_file)) != 0: + os.remove('%s.tmp' % list_file) + raise MoulinetteError(1, _("List server connection failed")) # Rename fetched temp list - os.rename(list_file +'.tmp', list_file) + os.rename('%s.tmp' % list_file, list_file) - os.system("touch /etc/cron.d/yunohost-applist-"+ name) - os.system("echo '00 00 * * * root yunohost app fetchlist -u "+ url +" -n "+ name +" --no-ldap > /dev/null 2>&1' >/etc/cron.d/yunohost-applist-"+ name) + os.system("touch /etc/cron.d/yunohost-applist-%s" % name) + os.system("echo '00 00 * * * root yunohost app fetchlist -u %s -n %s --no-ldap > /dev/null 2>&1' >/etc/cron.d/yunohost-applist-%s" % (url, name, name)) - win_msg(_("List successfully fetched")) + msignals.display(_("List successfully fetched"), 'success') def app_removelist(name): @@ -107,12 +102,12 @@ def app_removelist(name): """ try: - os.remove(repo_path +'/'+ name + '.json') - os.remove("/etc/cron.d/yunohost-applist-"+ name) + os.remove('%s/%s.json' % (repo_path, name)) + os.remove("/etc/cron.d/yunohost-applist-%s" % name) except OSError: - raise YunoHostError(22, _("Unknown list")) + raise MoulinetteError(22, _("Unknown list")) - win_msg(_("List successfully removed")) + msignals.display(_("List successfully removed"), 'success') def app_list(offset=None, limit=None, filter=None, raw=False): @@ -126,8 +121,6 @@ def app_list(offset=None, limit=None, filter=None, raw=False): raw -- Return the full app_dict """ - # TODO: List installed applications - if offset: offset = int(offset) else: offset = 0 if limit: limit = int(limit) @@ -270,148 +263,60 @@ def app_upgrade(app, url=None, file=None): url -- Git url to fetch for upgrade """ - with YunoHostLDAP() as yldap: - try: - app_list() - except YunoHostError: - raise YunoHostError(1, _("No app to upgrade")) + from yunohost.hook import hook_add, hook_exec - upgraded_apps = [] + try: + app_list() + except MoulinetteError: + raise MoulinetteError(1, _("No app to upgrade")) - # If no app is specified, upgrade all apps - if not app: - app = os.listdir(apps_setting_path) - elif not isinstance(app, list): - app = [ app ] + upgraded_apps = [] - for app_id in app: - installed = _is_installed(app_id) - if not installed: - raise YunoHostError(1, app_id + _(" is not installed")) + # If no app is specified, upgrade all apps + if not app: + app = os.listdir(apps_setting_path) + elif not isinstance(app, list): + app = [ app ] - if app_id in upgraded_apps: - continue + for app_id in app: + installed = _is_installed(app_id) + if not installed: + raise MoulinetteError(1, _("%s is not installed") % app_id) - if '__' in app_id: - original_app_id = app_id[:app_id.index('__')] - else: - original_app_id = app_id + if app_id in upgraded_apps: + continue - current_app_dict = app_info(app_id, raw=True) - new_app_dict = app_info(original_app_id, raw=True) - - if file: - manifest = _extract_app_from_file(file) - elif url: - manifest = _fetch_app_from_git(url) - elif 'lastUpdate' not in new_app_dict or 'git' not in new_app_dict: - raise YunoHostError(22, app_id + _(" is a custom app, please provide an URL manually in order to upgrade it")) - elif (new_app_dict['lastUpdate'] > current_app_dict['lastUpdate']) \ - or ('update_time' not in current_app_dict['settings'] \ - and (new_app_dict['lastUpdate'] > current_app_dict['settings']['install_time'])) \ - or ('update_time' in current_app_dict['settings'] \ - and (new_app_dict['lastUpdate'] > current_app_dict['settings']['update_time'])): - manifest = _fetch_app_from_git(app_id) - else: - continue - - # Check min version - if 'min_version' in manifest and __version__ < manifest['min_version']: - raise YunoHostError(1, _("%s requires a more recent version of the moulinette") % app_id) - - app_setting_path = apps_setting_path +'/'+ app_id - - if original_app_id != app_id: - # Replace original_app_id with the forked one in scripts - for file in os.listdir(app_tmp_folder +'/scripts'): - #TODO: add hooks directory to the list - #TODO: do it with sed ? - if file[:1] != '.': - with open(app_tmp_folder +'/scripts/'+ file, "r") as sources: - lines = sources.readlines() - with open(app_tmp_folder +'/scripts/'+ file, "w") as sources: - for line in lines: - sources.write(re.sub(r''+ original_app_id +'', app_id, line)) - - if 'hooks' in os.listdir(app_tmp_folder): - for file in os.listdir(app_tmp_folder +'/hooks'): - #TODO: do it with sed ? - if file[:1] != '.': - with open(app_tmp_folder +'/hooks/'+ file, "r") as sources: - lines = sources.readlines() - with open(app_tmp_folder +'/hooks/'+ file, "w") as sources: - for line in lines: - sources.write(re.sub(r''+ original_app_id +'', app_id, line)) - - # Add hooks - if 'hooks' in os.listdir(app_tmp_folder): - for file in os.listdir(app_tmp_folder +'/hooks'): - hook_add(app_id, app_tmp_folder +'/hooks/'+ file) - - # Execute App upgrade script - os.system('chown -hR admin: '+ install_tmp) - if hook_exec(app_tmp_folder +'/scripts/upgrade') != 0: - #TODO: display fail messages from script - pass - else: - app_setting(app_id, 'update_time', int(time.time())) - - # Replace scripts and manifest - os.system('rm -rf "'+ app_setting_path +'/scripts" "'+ app_setting_path +'/manifest.json"') - os.system('mv "'+ app_tmp_folder +'/manifest.json" "'+ app_tmp_folder +'/scripts" '+ app_setting_path) - - # So much win - upgraded_apps.append(app_id) - win_msg(app_id + _(" upgraded successfully")) - - if not upgraded_apps: - raise YunoHostError(1, _("No app to upgrade")) - - win_msg(_("Upgrade complete")) - - -def app_install(app, label=None, args=None): - """ - Install apps - - Keyword argument: - label - app -- App to install - args -- Serialize arguments of installation - - """ - #TODO: Create tool for nginx (check path availability & stuff) - - with YunoHostLDAP() as yldap: - - # Fetch or extract sources - try: os.listdir(install_tmp) - except OSError: os.makedirs(install_tmp) - - if app in app_list(raw=True) or ('@' in app) or ('http://' in app) or ('https://' in app): - manifest = _fetch_app_from_git(app) + if '__' in app_id: + original_app_id = app_id[:app_id.index('__')] else: - manifest = _extract_app_from_file(app) + original_app_id = app_id - # Check ID - if 'id' not in manifest or '__' in manifest['id']: - raise YunoHostError(22, _("App id is invalid")) + current_app_dict = app_info(app_id, raw=True) + new_app_dict = app_info(original_app_id, raw=True) - app_id = manifest['id'] + if file: + manifest = _extract_app_from_file(file) + elif url: + manifest = _fetch_app_from_git(url) + elif 'lastUpdate' not in new_app_dict or 'git' not in new_app_dict: + raise MoulinetteError(22, _("%s is a custom app, please provide an URL manually in order to upgrade it") % app_id) + elif (new_app_dict['lastUpdate'] > current_app_dict['lastUpdate']) \ + or ('update_time' not in current_app_dict['settings'] \ + and (new_app_dict['lastUpdate'] > current_app_dict['settings']['install_time'])) \ + or ('update_time' in current_app_dict['settings'] \ + and (new_app_dict['lastUpdate'] > current_app_dict['settings']['update_time'])): + manifest = _fetch_app_from_git(app_id) + else: + continue # Check min version if 'min_version' in manifest and __version__ < manifest['min_version']: - raise YunoHostError(1, _("%s requires a more recent version of the moulinette") % app_id) + raise MoulinetteError(1, _("%s requires a more recent version of the moulinette") % app_id) - # Check if app can be forked - instance_number = _installed_instance_number(app_id, last=True) + 1 - if instance_number > 1 : - if 'multi_instance' not in manifest or not is_true(manifest['multi_instance']): - raise YunoHostError(1, _("App is already installed")) + app_setting_path = apps_setting_path +'/'+ app_id - app_id_forked = app_id + '__' + str(instance_number) - - # Replace app_id with the new one in scripts + if original_app_id != app_id: + # Replace original_app_id with the forked one in scripts for file in os.listdir(app_tmp_folder +'/scripts'): #TODO: do it with sed ? if file[:1] != '.': @@ -419,7 +324,7 @@ def app_install(app, label=None, args=None): lines = sources.readlines() with open(app_tmp_folder +'/scripts/'+ file, "w") as sources: for line in lines: - sources.write(re.sub(r''+ app_id +'', app_id_forked, line)) + sources.write(re.sub(r''+ original_app_id +'', app_id, line)) if 'hooks' in os.listdir(app_tmp_folder): for file in os.listdir(app_tmp_folder +'/hooks'): @@ -429,65 +334,151 @@ def app_install(app, label=None, args=None): lines = sources.readlines() with open(app_tmp_folder +'/hooks/'+ file, "w") as sources: for line in lines: - sources.write(re.sub(r''+ app_id +'', app_id_forked, line)) - - # Change app_id for the rest of the process - app_id = app_id_forked - - # Prepare App settings - app_setting_path = apps_setting_path +'/'+ app_id - - #TMP: Remove old settings - if os.path.exists(app_setting_path): shutil.rmtree(app_setting_path) - os.makedirs(app_setting_path) - os.system('touch '+ app_setting_path +'/settings.yml') + sources.write(re.sub(r''+ original_app_id +'', app_id, line)) # Add hooks if 'hooks' in os.listdir(app_tmp_folder): for file in os.listdir(app_tmp_folder +'/hooks'): hook_add(app_id, app_tmp_folder +'/hooks/'+ file) - app_setting(app_id, 'id', app_id) - app_setting(app_id, 'install_time', int(time.time())) - - if label: - app_setting(app_id, 'label', label) + # Execute App upgrade script + os.system('chown -hR admin: %s' % install_tmp) + if hook_exec(app_tmp_folder +'/scripts/upgrade') != 0: + #TODO: display fail messages from script + pass else: - app_setting(app_id, 'label', manifest['name']) + app_setting(app_id, 'update_time', int(time.time())) - os.system('chown -R admin: '+ app_tmp_folder) + # Replace scripts and manifest + os.system('rm -rf "%s/scripts" "%s/manifest.json"' % (app_setting_path, app_setting_path)) + os.system('mv "%s/manifest.json" "%s/scripts" %s' % (app_tmp_folder, app_tmp_folder, app_setting_path)) - try: - if args is None: - args = '' - args_dict = dict(urlparse.parse_qsl(args)) - except: - args_dict = {} + # So much win + upgraded_apps.append(app_id) + msignals.display(_("%s upgraded successfully") % app_id, 'success') - # Execute App install script - os.system('chown -hR admin: '+ install_tmp) - # Move scripts and manifest to the right place - os.system('cp '+ app_tmp_folder +'/manifest.json ' + app_setting_path) - os.system('cp -R ' + app_tmp_folder +'/scripts '+ app_setting_path) - try: - if hook_exec(app_tmp_folder + '/scripts/install', args_dict) == 0: - shutil.rmtree(app_tmp_folder) - os.system('chmod -R 400 '+ app_setting_path) - os.system('chown -R root: '+ app_setting_path) - os.system('chown -R admin: '+ app_setting_path +'/scripts') - app_ssowatconf() - win_msg(_("Installation complete")) - else: - #TODO: display script fail messages - hook_remove(app_id) - shutil.rmtree(app_setting_path) - shutil.rmtree(app_tmp_folder) - raise YunoHostError(1, _("Installation failed")) - except KeyboardInterrupt, EOFError: + if not upgraded_apps: + raise MoulinetteError(1, _("No app to upgrade")) + + msignals.display(_("Upgrade complete"), 'success') + + +def app_install(auth, app, label=None, args=None): + """ + Install apps + + Keyword argument: + label + app -- App to install + args -- Serialize arguments of installation + + """ + from yunohost.hook import hook_add, hook_remove, hook_exec + + # Fetch or extract sources + try: os.listdir(install_tmp) + except OSError: os.makedirs(install_tmp) + + if app in app_list(raw=True) or ('@' in app) or ('http://' in app) or ('https://' in app): + manifest = _fetch_app_from_git(app) + else: + manifest = _extract_app_from_file(app) + + # Check ID + if 'id' not in manifest or '__' in manifest['id']: + raise MoulinetteError(22, _("App id is invalid")) + + app_id = manifest['id'] + + # Check min version + if 'min_version' in manifest and __version__ < manifest['min_version']: + raise MoulinetteError(1, _("%s requires a more recent version of the moulinette") % app_id) + + # Check if app can be forked + instance_number = _installed_instance_number(app_id, last=True) + 1 + if instance_number > 1 : + if 'multi_instance' not in manifest or not is_true(manifest['multi_instance']): + raise MoulinetteError(1, _("App is already installed")) + + app_id_forked = app_id + '__' + str(instance_number) + + # Replace app_id with the new one in scripts + for file in os.listdir(app_tmp_folder +'/scripts'): + #TODO: do it with sed ? + if file[:1] != '.': + with open(app_tmp_folder +'/scripts/'+ file, "r") as sources: + lines = sources.readlines() + with open(app_tmp_folder +'/scripts/'+ file, "w") as sources: + for line in lines: + sources.write(re.sub(r''+ app_id +'', app_id_forked, line)) + + if 'hooks' in os.listdir(app_tmp_folder): + for file in os.listdir(app_tmp_folder +'/hooks'): + #TODO: do it with sed ? + if file[:1] != '.': + with open(app_tmp_folder +'/hooks/'+ file, "r") as sources: + lines = sources.readlines() + with open(app_tmp_folder +'/hooks/'+ file, "w") as sources: + for line in lines: + sources.write(re.sub(r''+ app_id +'', app_id_forked, line)) + + # Change app_id for the rest of the process + app_id = app_id_forked + + # Prepare App settings + app_setting_path = apps_setting_path +'/'+ app_id + + #TMP: Remove old settings + if os.path.exists(app_setting_path): shutil.rmtree(app_setting_path) + os.makedirs(app_setting_path) + os.system('touch %s/settings.yml' % app_setting_path) + + # Add hooks + if 'hooks' in os.listdir(app_tmp_folder): + for file in os.listdir(app_tmp_folder +'/hooks'): + hook_add(app_id, app_tmp_folder +'/hooks/'+ file) + + app_setting(app_id, 'id', app_id) + app_setting(app_id, 'install_time', int(time.time())) + + if label: + app_setting(app_id, 'label', label) + else: + app_setting(app_id, 'label', manifest['name']) + + os.system('chown -R admin: '+ app_tmp_folder) + + try: + if args is None: + args = '' + args_dict = dict(urlparse.parse_qsl(args)) + except: + args_dict = {} + + # Execute App install script + os.system('chown -hR admin: %s' % install_tmp) + # Move scripts and manifest to the right place + os.system('cp %s/manifest.json %s' % (app_tmp_folder, app_setting_path)) + os.system('cp -R %s/scripts %s' % (app_tmp_folder, app_setting_path)) + try: + if hook_exec(app_tmp_folder + '/scripts/install', args_dict) == 0: + shutil.rmtree(app_tmp_folder) + os.system('chmod -R 400 %s' % app_setting_path) + os.system('chown -R root: %s' % app_setting_path) + os.system('chown -R admin: %s/scripts' % app_setting_path) + app_ssowatconf(auth) + msignals.display(_("Installation complete"), 'success') + else: + #TODO: display script fail messages hook_remove(app_id) shutil.rmtree(app_setting_path) shutil.rmtree(app_tmp_folder) - raise YunoHostError(125, _("Interrupted")) + raise MoulinetteError(1, _("Installation failed")) + except KeyboardInterrupt, EOFError: + hook_remove(app_id) + shutil.rmtree(app_setting_path) + shutil.rmtree(app_tmp_folder) + raise MoulinetteError(125, _("Interrupted")) def app_remove(app): @@ -498,9 +489,10 @@ def app_remove(app): app -- App(s) to delete """ + from yunohost.hook import hook_exec, hook_remove if not _is_installed(app): - raise YunoHostError(22, _("App is not installed")) + raise MoulinetteError(22, _("App is not installed")) app_setting_path = apps_setting_path + app @@ -509,7 +501,7 @@ def app_remove(app): shutil.rmtree('/tmp/yunohost_remove') except: pass - os.system('cp -a '+ app_setting_path + ' /tmp/yunohost_remove && chown -hR admin: /tmp/yunohost_remove') + os.system('cp -a %s /tmp/yunohost_remove && chown -hR admin: /tmp/yunohost_remove' % app_setting_path) os.system('chown -R admin: /tmp/yunohost_remove') os.system('chmod -R u+rX /tmp/yunohost_remove') @@ -520,10 +512,10 @@ def app_remove(app): shutil.rmtree('/tmp/yunohost_remove') hook_remove(app) app_ssowatconf() - win_msg(_("App removed: ")+ app) + msignals.display(_("App removed: %s") % app, 'success') -def app_addaccess(apps, users): +def app_addaccess(auth, apps, users): """ Grant access right to users (everyone by default) @@ -532,9 +524,11 @@ def app_addaccess(apps, users): apps """ + from yunohost.user import user_list, user_info + if not users: users = [] - for user in user_list(YunoHostLDAP())['users']: + for user in user_list(auth)['users']: users.append(user['username']) if not isinstance(users, list): users = [users] @@ -542,7 +536,7 @@ def app_addaccess(apps, users): for app in apps: if not _is_installed(app): - raise YunoHostError(22, _("App is not installed")) + raise MoulinetteError(22, _("App is not installed")) with open(apps_setting_path + app +'/settings.yml') as f: app_settings = yaml.load(f) @@ -560,8 +554,8 @@ def app_addaccess(apps, users): for allowed_user in users: if allowed_user not in new_users.split(','): try: - user_info(allowed_user) - except YunoHostError: + user_info(auth, allowed_user) + except MoulinetteError: continue if new_users == '': new_users = allowed_user @@ -570,12 +564,12 @@ def app_addaccess(apps, users): app_setting(app, 'allowed_users', new_users.strip()) - app_ssowatconf() + app_ssowatconf(auth) return { 'allowed_users': new_users.split(',') } -def app_removeaccess(apps, users): +def app_removeaccess(auth, apps, users): """ Revoke access right to users (everyone by default) @@ -584,6 +578,8 @@ def app_removeaccess(apps, users): apps """ + from yunohost.user import user_list + remove_all = False if not users: remove_all = True @@ -593,7 +589,7 @@ def app_removeaccess(apps, users): new_users = '' if not _is_installed(app): - raise YunoHostError(22, _("App is not installed")) + raise MoulinetteError(22, _("App is not installed")) with open(apps_setting_path + app +'/settings.yml') as f: app_settings = yaml.load(f) @@ -610,7 +606,7 @@ def app_removeaccess(apps, users): new_users = new_users +','+ allowed_user else: new_users='' - for user in user_list(YunoHostLDAP())['users']: + for user in user_list(auth)['users']: if user['username'] not in users: if new_users == '': new_users = user['username'] @@ -618,12 +614,12 @@ def app_removeaccess(apps, users): app_setting(app, 'allowed_users', new_users.strip()) - app_ssowatconf() + app_ssowatconf(auth) return { 'allowed_users': new_users.split(',') } -def app_clearaccess(apps): +def app_clearaccess(auth, apps): """ Reset access rights for the app @@ -635,7 +631,7 @@ def app_clearaccess(apps): for app in apps: if not _is_installed(app): - raise YunoHostError(22, _("App is not installed")) + raise MoulinetteError(22, _("App is not installed")) with open(apps_setting_path + app +'/settings.yml') as f: app_settings = yaml.load(f) @@ -646,7 +642,7 @@ def app_clearaccess(apps): if 'allowed_users' in app_settings: app_setting(app, 'allowed_users', delete=True) - app_ssowatconf() + app_ssowatconf(auth) def app_setting(app, key, value=None, delete=False): @@ -739,13 +735,13 @@ def app_checkport(port): s.connect(("localhost", int(port))) s.close() except socket.error: - win_msg(_("Port available: ")+ str(port)) + msignals.display(_("Port available: %s") % str(port), 'success') else: - raise YunoHostError(22, _("Port not available")) + raise MoulinetteError(22, _("Port not available: %s") % str(port)) -def app_checkurl(url, app=None): +def app_checkurl(auth, url, app=None): """ Check availability of a web path @@ -754,6 +750,8 @@ def app_checkurl(url, app=None): app -- Write domain & path to app settings for further checks """ + from yunohost.domain import domain_list + if "https://" == url[:8]: url = url[8:] elif "http://" == url[:7]: @@ -771,15 +769,15 @@ def app_checkurl(url, app=None): apps_map = app_map(raw=True) validate(r'^([a-zA-Z0-9]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)(\.[a-zA-Z0-9]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)*(\.[a-zA-Z]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)$', domain) - if domain not in domain_list(YunoHostLDAP())['domains']: - raise YunoHostError(22, _("Domain doesn't exists")) + if domain not in domain_list(auth)['domains']: + raise MoulinetteError(22, _("Domain doesn't exists")) if domain in apps_map: if path in apps_map[domain]: - raise YunoHostError(1, _("An app is already installed on this location")) + raise MoulinetteError(1, _("An app is already installed on this location")) for app_path, v in apps_map[domain].items(): if app_path in path and app_path.count('/') < path.count('/'): - raise YunoHostError(1, _("Unable to install app at this location")) + raise MoulinetteError(1, _("Unable to install app at this location")) if app is not None: app_setting(app, 'domain', value=domain) @@ -807,31 +805,33 @@ def app_initdb(user, password=None, db=None, sql=None): print(password) mysql_root_pwd = open('/etc/yunohost/mysql').read().rstrip() - mysql_command = 'mysql -u root -p'+ mysql_root_pwd +' -e "CREATE DATABASE '+ db +' ; GRANT ALL PRIVILEGES ON '+ db +'.* TO \''+ user +'\'@localhost IDENTIFIED BY \''+ password +'\';"' + mysql_command = 'mysql -u root -p%s -e "CREATE DATABASE %s ; GRANT ALL PRIVILEGES ON %s.* TO \'%s\'@localhost IDENTIFIED BY \'%s\';"' % (mysql_root_pwd, db, db, user, password) if os.system(mysql_command) != 0: - raise YunoHostError(1, _("MySQL DB creation failed")) + raise MoulinetteError(1, _("MySQL DB creation failed")) if sql is not None: - if os.system('mysql -u '+ user +' -p'+ password +' '+ db +' < '+ sql) != 0: - raise YunoHostError(1, _("MySQL DB init failed")) + if os.system('mysql -u %s -p%s %s < %s' % (user, password, db, sql)) != 0: + raise MoulinetteError(1, _("MySQL DB init failed")) if not return_pwd: - win_msg(_("Database initiliazed")) + msignals.display(_("Database initiliazed"), 'success') -def app_ssowatconf(): +def app_ssowatconf(auth): """ Regenerate SSOwat configuration file """ + from yunohost.domain import domain_list + from yunohost.user import user_list with open('/etc/yunohost/current_host', 'r') as f: main_domain = f.readline().rstrip() - domains = domain_list(YunoHostLDAP())['domains'] + domains = domain_list(auth)['domains'] users = {} - for user in user_list(YunoHostLDAP())['users']: + for user in user_list(auth)['users']: users[user['username']] = app_map(user=user['username']) skipped_urls = [] @@ -904,7 +904,7 @@ def app_ssowatconf(): with open('/etc/ssowat/conf.json', 'wb') as f: json.dump(conf_dict, f) - win_msg(_('SSOwat configuration generated')) + msignals.display(_('SSOwat configuration generated'), 'success') def _extract_app_from_file(path, remove=False): @@ -927,21 +927,21 @@ def _extract_app_from_file(path, remove=False): os.makedirs(app_tmp_folder) if ".zip" in path: - extract_result = os.system('cd '+ os.getcwd() +' && unzip '+ path +' -d '+ app_tmp_folder +' > /dev/null 2>&1') + extract_result = os.system('cd %s && unzip %s -d %s > /dev/null 2>&1' % (os.getcwd(), path, app_tmp_folder)) if remove: os.remove(path) elif ".tar" in path: - extract_result = os.system('cd '+ os.getcwd() +' && tar -xf '+ path +' -C '+ app_tmp_folder +' > /dev/null 2>&1') + extract_result = os.system('cd %s && tar -xf %s -C %s > /dev/null 2>&1' % (os.getcwd(), path, app_tmp_folder)) if remove: os.remove(path) - elif (path[:1] == '/' and os.path.exists(path)) or (os.system('cd '+ os.getcwd() +'/'+ path) == 0): + elif (path[:1] == '/' and os.path.exists(path)) or (os.system('cd %s/%s' % (os.getcwd(), path)) == 0): shutil.rmtree(app_tmp_folder) if path[len(path)-1:] != '/': path = path + '/' - extract_result = os.system('cd '+ os.getcwd() +' && cp -a "'+ path +'" '+ app_tmp_folder) + extract_result = os.system('cd %s && cp -a "%s" %s' % (os.getcwd(), path, app_tmp_folder)) else: extract_result = 1 if extract_result != 0: - raise YunoHostError(22, _("Invalid install file")) + raise MoulinetteError(22, _("Invalid install file")) try: if len(os.listdir(app_tmp_folder)) == 1: @@ -951,7 +951,7 @@ def _extract_app_from_file(path, remove=False): manifest = json.loads(str(json_manifest.read())) manifest['lastUpdate'] = int(time.time()) except IOError: - raise YunoHostError(1, _("Invalid App file")) + raise MoulinetteError(1, _("Invalid App file")) print(_('OK')) @@ -979,17 +979,17 @@ def _fetch_app_from_git(app): if ".git" in url[-4:]: url = url[:-4] if "/" in url [-1:]: url = url[:-1] url = url + "/archive/master.zip" - if os.system('wget "'+ url +'" -O "'+ app_tmp_folder +'.zip" > /dev/null 2>&1') == 0: + if os.system('wget "%s" -O "%s.zip" > /dev/null 2>&1' % (url, app_tmp_folder)) == 0: return _extract_app_from_file(app_tmp_folder +'.zip', remove=True) - git_result = os.system('git clone '+ app +' '+ app_tmp_folder) + git_result = os.system('git clone %s %s' % (app, app_tmp_folder)) git_result_2 = 0 try: with open(app_tmp_folder + '/manifest.json') as json_manifest: manifest = json.loads(str(json_manifest.read())) manifest['lastUpdate'] = int(time.time()) except IOError: - raise YunoHostError(1, _("Invalid App manifest")) + raise MoulinetteError(1, _("Invalid App manifest")) else: app_dict = app_list(raw=True) @@ -999,24 +999,24 @@ def _fetch_app_from_git(app): app_info['manifest']['lastUpdate'] = app_info['lastUpdate'] manifest = app_info['manifest'] else: - raise YunoHostError(22, _("App doesn't exists")) + raise MoulinetteError(22, _("App doesn't exists")) if "github.com" in app_info['git']['url']: url = app_info['git']['url'].replace("git@github.com:", "https://github.com/") if ".git" in url[-4:]: url = url[:-4] if "/" in url [-1:]: url = url[:-1] url = url + "/archive/"+ str(app_info['git']['revision']) + ".zip" - if os.system('wget "'+ url +'" -O "'+ app_tmp_folder +'.zip" > /dev/null 2>&1') == 0: + if os.system('wget "%s" -O "%s.zip" > /dev/null 2>&1' % (url, app_tmp_folder)) == 0: return _extract_app_from_file(app_tmp_folder +'.zip', remove=True) app_tmp_folder = install_tmp +'/'+ app if os.path.exists(app_tmp_folder): shutil.rmtree(app_tmp_folder) - git_result = os.system('git clone '+ app_info['git']['url'] +' -b '+ app_info['git']['branch'] +' '+ app_tmp_folder) - git_result_2 = os.system('cd '+ app_tmp_folder +' && git reset --hard '+ str(app_info['git']['revision'])) + git_result = os.system('git clone %s -b %s %s' % (app_info['git']['url'], app_info['git']['branch'], app_tmp_folder)) + git_result_2 = os.system('cd %s && git reset --hard %s' % (app_tmp_folder, str(app_info['git']['revision']))) if not git_result == git_result_2 == 0: - raise YunoHostError(22, _("Sources fetching failed")) + raise MoulinetteError(22, _("Sources fetching failed")) print(_('OK'))