mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[enh] Rename uo in operation_logger
This commit is contained in:
parent
93cb07ed61
commit
775a16d883
9 changed files with 129 additions and 129 deletions
|
@ -44,7 +44,7 @@ from moulinette.utils.filesystem import read_json
|
|||
|
||||
from yunohost.service import service_log, _run_service_command
|
||||
from yunohost.utils import packages
|
||||
from yunohost.log import is_unit_operation, UnitOperation
|
||||
from yunohost.log import is_unit_operation, OperationLogger
|
||||
|
||||
logger = getActionLogger('yunohost.app')
|
||||
|
||||
|
@ -110,13 +110,13 @@ def app_fetchlist(url=None, name=None):
|
|||
# the fetch only this list
|
||||
if url is not None:
|
||||
if name:
|
||||
uo = UnitOperation('app_fetchlist')
|
||||
uo.start()
|
||||
operation_logger = OperationLogger('app_fetchlist')
|
||||
operation_logger.start()
|
||||
_register_new_appslist(url, name)
|
||||
# Refresh the appslists dict
|
||||
appslists = _read_appslist_list()
|
||||
appslists_to_be_fetched = [name]
|
||||
uo.success()
|
||||
operation_logger.success()
|
||||
else:
|
||||
raise MoulinetteError(errno.EINVAL,
|
||||
m18n.n('custom_appslist_name_required'))
|
||||
|
@ -193,7 +193,7 @@ def app_fetchlist(url=None, name=None):
|
|||
|
||||
|
||||
@is_unit_operation()
|
||||
def app_removelist(uo, name):
|
||||
def app_removelist(operation_logger, name):
|
||||
"""
|
||||
Remove list from the repositories
|
||||
|
||||
|
@ -207,7 +207,7 @@ def app_removelist(uo, name):
|
|||
if name not in appslists.keys():
|
||||
raise MoulinetteError(errno.ENOENT, m18n.n('appslist_unknown', appslist=name))
|
||||
|
||||
uo.start()
|
||||
operation_logger.start()
|
||||
|
||||
# Remove json
|
||||
json_path = '%s/%s.json' % (REPO_PATH, name)
|
||||
|
@ -433,7 +433,7 @@ def app_map(app=None, raw=False, user=None):
|
|||
|
||||
|
||||
@is_unit_operation()
|
||||
def app_change_url(uo, auth, app, domain, path):
|
||||
def app_change_url(operation_logger, auth, app, domain, path):
|
||||
"""
|
||||
Modify the URL at which an application is installed.
|
||||
|
||||
|
@ -491,9 +491,9 @@ def app_change_url(uo, auth, app, domain, path):
|
|||
env_dict["YNH_APP_NEW_PATH"] = path.rstrip("/")
|
||||
|
||||
if domain != old_domain:
|
||||
uo.related_to.append(('domain', old_domain))
|
||||
uo.extra.update({'env': env_dict})
|
||||
uo.start()
|
||||
operation_logger.related_to.append(('domain', old_domain))
|
||||
operation_logger.extra.update({'env': env_dict})
|
||||
operation_logger.start()
|
||||
|
||||
if os.path.exists(os.path.join(APP_TMP_FOLDER, "scripts")):
|
||||
shutil.rmtree(os.path.join(APP_TMP_FOLDER, "scripts"))
|
||||
|
@ -515,7 +515,7 @@ def app_change_url(uo, auth, app, domain, path):
|
|||
if hook_exec(os.path.join(APP_TMP_FOLDER, 'scripts/change_url'), args=args_list, env=env_dict, user="root") != 0:
|
||||
msg = "Failed to change '%s' url." % app
|
||||
logger.error(msg)
|
||||
uo.error(msg)
|
||||
operation_logger.error(msg)
|
||||
|
||||
# restore values modified by app_checkurl
|
||||
# see begining of the function
|
||||
|
@ -630,8 +630,8 @@ def app_upgrade(auth, app=[], url=None, file=None):
|
|||
|
||||
# Start register change on system
|
||||
related_to = [('app', app_instance_name)]
|
||||
uo = UnitOperation('app_upgrade', related_to, env=env_dict)
|
||||
uo.start()
|
||||
operation_logger = OperationLogger('app_upgrade', related_to, env=env_dict)
|
||||
operation_logger.start()
|
||||
|
||||
# Apply dirty patch to make php5 apps compatible with php7
|
||||
_patch_php5(extracted_app_folder)
|
||||
|
@ -641,7 +641,7 @@ def app_upgrade(auth, app=[], url=None, file=None):
|
|||
if hook_exec(extracted_app_folder + '/scripts/upgrade', args=args_list, env=env_dict, user="root") != 0:
|
||||
msg = m18n.n('app_upgrade_failed', app=app_instance_name)
|
||||
logger.error(msg)
|
||||
uo.error(msg)
|
||||
operation_logger.error(msg)
|
||||
else:
|
||||
now = int(time.time())
|
||||
# TODO: Move install_time away from app_setting
|
||||
|
@ -671,7 +671,7 @@ def app_upgrade(auth, app=[], url=None, file=None):
|
|||
logger.success(m18n.n('app_upgraded', app=app_instance_name))
|
||||
|
||||
hook_callback('post_app_upgrade', args=args_list, env=env_dict)
|
||||
uo.success()
|
||||
operation_logger.success()
|
||||
|
||||
if not upgraded_apps:
|
||||
raise MoulinetteError(errno.ENODATA, m18n.n('app_no_upgrade'))
|
||||
|
@ -686,7 +686,7 @@ def app_upgrade(auth, app=[], url=None, file=None):
|
|||
|
||||
|
||||
@is_unit_operation()
|
||||
def app_install(uo, auth, app, label=None, args=None, no_remove_on_failure=False):
|
||||
def app_install(operation_logger, auth, app, label=None, args=None, no_remove_on_failure=False):
|
||||
"""
|
||||
Install apps
|
||||
|
||||
|
@ -698,7 +698,7 @@ def app_install(uo, auth, app, label=None, args=None, no_remove_on_failure=False
|
|||
|
||||
"""
|
||||
from yunohost.hook import hook_add, hook_remove, hook_exec, hook_callback
|
||||
from yunohost.log import UnitOperation
|
||||
from yunohost.log import OperationLogger
|
||||
|
||||
|
||||
# Fetch or extract sources
|
||||
|
@ -758,10 +758,10 @@ def app_install(uo, auth, app, label=None, args=None, no_remove_on_failure=False
|
|||
env_dict["YNH_APP_INSTANCE_NUMBER"] = str(instance_number)
|
||||
|
||||
# Start register change on system
|
||||
uo.extra.update({'env':env_dict})
|
||||
uo.related_to = [s for s in uo.related_to if s[0] != "app"]
|
||||
uo.related_to.append(("app", app_id))
|
||||
uo.start()
|
||||
operation_logger.extra.update({'env':env_dict})
|
||||
operation_logger.related_to = [s for s in operation_logger.related_to if s[0] != "app"]
|
||||
operation_logger.related_to.append(("app", app_id))
|
||||
operation_logger.start()
|
||||
|
||||
# Create app directory
|
||||
app_setting_path = os.path.join(APPS_SETTING_PATH, app_instance_name)
|
||||
|
@ -806,7 +806,7 @@ def app_install(uo, auth, app, label=None, args=None, no_remove_on_failure=False
|
|||
logger.exception(m18n.n('unexpected_error'))
|
||||
finally:
|
||||
if install_retcode != 0:
|
||||
error_msg = uo.error(m18n.n('unexpected_error'))
|
||||
error_msg = operation_logger.error(m18n.n('unexpected_error'))
|
||||
if not no_remove_on_failure:
|
||||
# Setup environment for remove script
|
||||
env_dict_remove = {}
|
||||
|
@ -815,10 +815,10 @@ def app_install(uo, auth, app, label=None, args=None, no_remove_on_failure=False
|
|||
env_dict_remove["YNH_APP_INSTANCE_NUMBER"] = str(instance_number)
|
||||
|
||||
# Execute remove script
|
||||
uo_remove = UnitOperation('remove_on_failed_install',
|
||||
operation_logger_remove = OperationLogger('remove_on_failed_install',
|
||||
[('app', app_instance_name)],
|
||||
env=env_dict_remove)
|
||||
uo_remove.start()
|
||||
operation_logger_remove.start()
|
||||
|
||||
remove_retcode = hook_exec(
|
||||
os.path.join(extracted_app_folder, 'scripts/remove'),
|
||||
|
@ -828,9 +828,9 @@ def app_install(uo, auth, app, label=None, args=None, no_remove_on_failure=False
|
|||
msg = m18n.n('app_not_properly_removed',
|
||||
app=app_instance_name)
|
||||
logger.warning(msg)
|
||||
uo_remove.error(msg)
|
||||
operation_logger_remove.error(msg)
|
||||
else:
|
||||
uo_remove.success()
|
||||
operation_logger_remove.success()
|
||||
|
||||
# Clean tmp folders
|
||||
shutil.rmtree(app_setting_path)
|
||||
|
@ -868,7 +868,7 @@ def app_install(uo, auth, app, label=None, args=None, no_remove_on_failure=False
|
|||
|
||||
|
||||
@is_unit_operation()
|
||||
def app_remove(uo, auth, app):
|
||||
def app_remove(operation_logger, auth, app):
|
||||
"""
|
||||
Remove app
|
||||
|
||||
|
@ -881,7 +881,7 @@ def app_remove(uo, auth, app):
|
|||
raise MoulinetteError(errno.EINVAL,
|
||||
m18n.n('app_not_installed', app=app))
|
||||
|
||||
uo.start()
|
||||
operation_logger.start()
|
||||
|
||||
app_setting_path = APPS_SETTING_PATH + app
|
||||
|
||||
|
@ -906,8 +906,8 @@ def app_remove(uo, auth, app):
|
|||
env_dict["YNH_APP_ID"] = app_id
|
||||
env_dict["YNH_APP_INSTANCE_NAME"] = app
|
||||
env_dict["YNH_APP_INSTANCE_NUMBER"] = str(app_instance_nb)
|
||||
uo.extra.update({'env': env_dict})
|
||||
uo.flush()
|
||||
operation_logger.extra.update({'env': env_dict})
|
||||
operation_logger.flush()
|
||||
|
||||
if hook_exec('/tmp/yunohost_remove/scripts/remove', args=args_list, env=env_dict, user="root") == 0:
|
||||
logger.success(m18n.n('app_removed', app=app))
|
||||
|
@ -957,8 +957,8 @@ def app_addaccess(auth, apps, users=[]):
|
|||
|
||||
# Start register change on system
|
||||
related_to = [('app', app)]
|
||||
uo= UnitOperation('app_addaccess', related_to)
|
||||
uo.start()
|
||||
operation_logger= OperationLogger('app_addaccess', related_to)
|
||||
operation_logger.start()
|
||||
|
||||
allowed_users = set()
|
||||
if 'allowed_users' in app_settings:
|
||||
|
@ -972,14 +972,14 @@ def app_addaccess(auth, apps, users=[]):
|
|||
logger.warning(m18n.n('user_unknown', user=allowed_user))
|
||||
continue
|
||||
allowed_users.add(allowed_user)
|
||||
uo.related_to.append(('user', allowed_user))
|
||||
operation_logger.related_to.append(('user', allowed_user))
|
||||
|
||||
uo.flush()
|
||||
operation_logger.flush()
|
||||
new_users = ','.join(allowed_users)
|
||||
app_setting(app, 'allowed_users', new_users)
|
||||
hook_callback('post_app_addaccess', args=[app, new_users])
|
||||
|
||||
uo.success()
|
||||
operation_logger.success()
|
||||
|
||||
result[app] = allowed_users
|
||||
|
||||
|
@ -1020,8 +1020,8 @@ def app_removeaccess(auth, apps, users=[]):
|
|||
|
||||
# Start register change on system
|
||||
related_to = [('app', app)]
|
||||
uo= UnitOperation('app_removeaccess', related_to)
|
||||
uo.start()
|
||||
operation_logger= OperationLogger('app_removeaccess', related_to)
|
||||
operation_logger.start()
|
||||
|
||||
if remove_all:
|
||||
pass
|
||||
|
@ -1034,15 +1034,15 @@ def app_removeaccess(auth, apps, users=[]):
|
|||
if allowed_user not in users:
|
||||
allowed_users.append(allowed_user)
|
||||
|
||||
uo.related_to += [ ('user', x) for x in allowed_users ]
|
||||
uo.flush()
|
||||
operation_logger.related_to += [ ('user', x) for x in allowed_users ]
|
||||
operation_logger.flush()
|
||||
new_users = ','.join(allowed_users)
|
||||
app_setting(app, 'allowed_users', new_users)
|
||||
hook_callback('post_app_removeaccess', args=[app, new_users])
|
||||
|
||||
result[app] = allowed_users
|
||||
|
||||
uo.success()
|
||||
operation_logger.success()
|
||||
|
||||
app_ssowatconf(auth)
|
||||
|
||||
|
@ -1069,8 +1069,8 @@ def app_clearaccess(auth, apps):
|
|||
|
||||
# Start register change on system
|
||||
related_to = [('app', app)]
|
||||
uo= UnitOperation('app_clearaccess', related_to)
|
||||
uo.start()
|
||||
operation_logger= OperationLogger('app_clearaccess', related_to)
|
||||
operation_logger.start()
|
||||
|
||||
if 'mode' in app_settings:
|
||||
app_setting(app, 'mode', delete=True)
|
||||
|
@ -1080,7 +1080,7 @@ def app_clearaccess(auth, apps):
|
|||
|
||||
hook_callback('post_app_clearaccess', args=[app])
|
||||
|
||||
uo.success()
|
||||
operation_logger.success()
|
||||
|
||||
app_ssowatconf(auth)
|
||||
|
||||
|
@ -1109,7 +1109,7 @@ def app_debug(app):
|
|||
|
||||
|
||||
@is_unit_operation()
|
||||
def app_makedefault(uo, auth, app, domain=None):
|
||||
def app_makedefault(operation_logger, auth, app, domain=None):
|
||||
"""
|
||||
Redirect domain root to an app
|
||||
|
||||
|
@ -1126,11 +1126,11 @@ def app_makedefault(uo, auth, app, domain=None):
|
|||
|
||||
if domain is None:
|
||||
domain = app_domain
|
||||
uo.related_to.append(('domain',domain))
|
||||
operation_logger.related_to.append(('domain',domain))
|
||||
elif domain not in domain_list(auth)['domains']:
|
||||
raise MoulinetteError(errno.EINVAL, m18n.n('domain_unknown'))
|
||||
|
||||
uo.start()
|
||||
operation_logger.start()
|
||||
if '/' in app_map(raw=True)[domain]:
|
||||
raise MoulinetteError(errno.EEXIST,
|
||||
m18n.n('app_make_default_location_already_used',
|
||||
|
|
|
@ -51,7 +51,7 @@ from yunohost.hook import (
|
|||
from yunohost.monitor import binary_to_human
|
||||
from yunohost.tools import tools_postinstall
|
||||
from yunohost.service import service_regen_conf
|
||||
from yunohost.log import UnitOperation
|
||||
from yunohost.log import OperationLogger
|
||||
|
||||
BACKUP_PATH = '/home/yunohost.backup'
|
||||
ARCHIVES_PATH = '%s/archives' % BACKUP_PATH
|
||||
|
@ -1174,14 +1174,14 @@ class RestoreManager():
|
|||
return
|
||||
|
||||
# Start register change on system
|
||||
uo = UnitOperation('backup_restore_system')
|
||||
uo.start()
|
||||
operation_logger = OperationLogger('backup_restore_system')
|
||||
operation_logger.start()
|
||||
|
||||
logger.debug(m18n.n('restore_running_hooks'))
|
||||
|
||||
env_dict = self._get_env_var()
|
||||
uo.extra['env'] = env_dict
|
||||
uo.flush()
|
||||
operation_logger.extra['env'] = env_dict
|
||||
operation_logger.flush()
|
||||
ret = hook_callback('restore',
|
||||
system_targets,
|
||||
args=[self.work_dir],
|
||||
|
@ -1198,9 +1198,9 @@ class RestoreManager():
|
|||
error_part.append(part)
|
||||
|
||||
if ret['failed']:
|
||||
uo.error(m18n.n('restore_system_part_failed', part=', '.join(error_part)))
|
||||
operation_logger.error(m18n.n('restore_system_part_failed', part=', '.join(error_part)))
|
||||
else:
|
||||
uo.success()
|
||||
operation_logger.success()
|
||||
|
||||
service_regen_conf()
|
||||
|
||||
|
@ -1250,8 +1250,8 @@ class RestoreManager():
|
|||
|
||||
# Start register change on system
|
||||
related_to = [('app', app_instance_name)]
|
||||
uo = UnitOperation('backup_restore_app', related_to)
|
||||
uo.start()
|
||||
operation_logger = OperationLogger('backup_restore_app', related_to)
|
||||
operation_logger.start()
|
||||
|
||||
# Check if the app is not already installed
|
||||
if _is_installed(app_instance_name):
|
||||
|
@ -1302,8 +1302,8 @@ class RestoreManager():
|
|||
# Prepare env. var. to pass to script
|
||||
env_dict = self._get_env_var(app_instance_name)
|
||||
|
||||
uo.extra['env'] = env_dict
|
||||
uo.flush()
|
||||
operation_logger.extra['env'] = env_dict
|
||||
operation_logger.flush()
|
||||
|
||||
# Execute app restore script
|
||||
hook_exec(restore_script,
|
||||
|
@ -1315,7 +1315,7 @@ class RestoreManager():
|
|||
except:
|
||||
msg = m18n.n('restore_app_failed',app=app_instance_name)
|
||||
logger.exception(msg)
|
||||
uo.error(msg)
|
||||
operation_logger.error(msg)
|
||||
|
||||
self.targets.set_result("apps", app_instance_name, "Error")
|
||||
|
||||
|
@ -1328,10 +1328,10 @@ class RestoreManager():
|
|||
env_dict_remove["YNH_APP_INSTANCE_NAME"] = app_instance_name
|
||||
env_dict_remove["YNH_APP_INSTANCE_NUMBER"] = str(app_instance_nb)
|
||||
|
||||
uo = UnitOperation('remove_on_failed_restore',
|
||||
operation_logger = OperationLogger('remove_on_failed_restore',
|
||||
[('app', app_instance_name)],
|
||||
env=env_dict_remove)
|
||||
uo.start()
|
||||
operation_logger.start()
|
||||
|
||||
# Execute remove script
|
||||
# TODO: call app_remove instead
|
||||
|
@ -1339,9 +1339,9 @@ class RestoreManager():
|
|||
env=env_dict_remove, user="root") != 0:
|
||||
msg = m18n.n('app_not_properly_removed', app=app_instance_name)
|
||||
logger.warning(msg)
|
||||
uo.error(msg)
|
||||
operation_logger.error(msg)
|
||||
else:
|
||||
uo.success()
|
||||
operation_logger.success()
|
||||
|
||||
# Cleaning app directory
|
||||
shutil.rmtree(app_settings_new_path, ignore_errors=True)
|
||||
|
@ -1349,7 +1349,7 @@ class RestoreManager():
|
|||
# TODO Cleaning app hooks
|
||||
else:
|
||||
self.targets.set_result("apps", app_instance_name, "Success")
|
||||
uo.success()
|
||||
operation_logger.success()
|
||||
finally:
|
||||
# Cleaning temporary scripts directory
|
||||
shutil.rmtree(tmp_folder_for_app_restore, ignore_errors=True)
|
||||
|
|
|
@ -45,7 +45,7 @@ from yunohost.utils.network import get_public_ip
|
|||
from moulinette import m18n
|
||||
from yunohost.app import app_ssowatconf
|
||||
from yunohost.service import _run_service_command, service_regen_conf
|
||||
from yunohost.log import UnitOperation
|
||||
from yunohost.log import OperationLogger
|
||||
|
||||
logger = getActionLogger('yunohost.certmanager')
|
||||
|
||||
|
@ -160,7 +160,7 @@ def _certificate_install_selfsigned(domain_list, force=False):
|
|||
|
||||
for domain in domain_list:
|
||||
|
||||
uo = UnitOperation('selfsigned_cert_install', [('domain', domain)],
|
||||
operation_logger = OperationLogger('selfsigned_cert_install', [('domain', domain)],
|
||||
args={'force': force})
|
||||
|
||||
# Paths of files and folder we'll need
|
||||
|
@ -185,7 +185,7 @@ def _certificate_install_selfsigned(domain_list, force=False):
|
|||
raise MoulinetteError(errno.EINVAL, m18n.n(
|
||||
'certmanager_attempt_to_replace_valid_cert', domain=domain))
|
||||
|
||||
uo.start()
|
||||
operation_logger.start()
|
||||
|
||||
# Create output folder for new certificate stuff
|
||||
os.makedirs(new_cert_folder)
|
||||
|
@ -243,11 +243,11 @@ def _certificate_install_selfsigned(domain_list, force=False):
|
|||
if status and status["CA_type"]["code"] == "self-signed" and status["validity"] > 3648:
|
||||
logger.success(
|
||||
m18n.n("certmanager_cert_install_success_selfsigned", domain=domain))
|
||||
uo.success()
|
||||
operation_logger.success()
|
||||
else:
|
||||
msg = "Installation of self-signed certificate installation for %s failed !" % (domain)
|
||||
logger.error(msg)
|
||||
uo.error(msg)
|
||||
operation_logger.error(msg)
|
||||
|
||||
|
||||
def _certificate_install_letsencrypt(auth, domain_list, force=False, no_checks=False, staging=False):
|
||||
|
@ -288,7 +288,7 @@ def _certificate_install_letsencrypt(auth, domain_list, force=False, no_checks=F
|
|||
# Actual install steps
|
||||
for domain in domain_list:
|
||||
|
||||
uo = UnitOperation('letsencrypt_cert_install', [('domain', domain)],
|
||||
operation_logger = OperationLogger('letsencrypt_cert_install', [('domain', domain)],
|
||||
args={'force': force, 'no_checks': no_checks,
|
||||
'staging': staging})
|
||||
logger.info(
|
||||
|
@ -298,7 +298,7 @@ def _certificate_install_letsencrypt(auth, domain_list, force=False, no_checks=F
|
|||
if not no_checks:
|
||||
_check_domain_is_ready_for_ACME(domain)
|
||||
|
||||
uo.start()
|
||||
operation_logger.start()
|
||||
|
||||
_configure_for_acme_challenge(auth, domain)
|
||||
_fetch_and_enable_new_certificate(domain, staging, no_checks=no_checks)
|
||||
|
@ -307,12 +307,12 @@ def _certificate_install_letsencrypt(auth, domain_list, force=False, no_checks=F
|
|||
logger.success(
|
||||
m18n.n("certmanager_cert_install_success", domain=domain))
|
||||
|
||||
uo.success()
|
||||
operation_logger.success()
|
||||
except Exception as e:
|
||||
_display_debug_information(domain)
|
||||
msg = "Certificate installation for %s failed !\nException: %s" % (domain, e)
|
||||
logger.error(msg)
|
||||
uo.error(msg)
|
||||
operation_logger.error(msg)
|
||||
|
||||
def certificate_renew(auth, domain_list, force=False, no_checks=False, email=False, staging=False):
|
||||
"""
|
||||
|
@ -391,7 +391,7 @@ def certificate_renew(auth, domain_list, force=False, no_checks=False, email=Fal
|
|||
# Actual renew steps
|
||||
for domain in domain_list:
|
||||
|
||||
uo = UnitOperation('letsencrypt_cert_renew', [('domain', domain)],
|
||||
operation_logger = OperationLogger('letsencrypt_cert_renew', [('domain', domain)],
|
||||
args={'force': force, 'no_checks': no_checks,
|
||||
'staging': staging, 'email': email})
|
||||
|
||||
|
@ -402,14 +402,14 @@ def certificate_renew(auth, domain_list, force=False, no_checks=False, email=Fal
|
|||
if not no_checks:
|
||||
_check_domain_is_ready_for_ACME(domain)
|
||||
|
||||
uo.start()
|
||||
operation_logger.start()
|
||||
|
||||
_fetch_and_enable_new_certificate(domain, staging, no_checks=no_checks)
|
||||
|
||||
logger.success(
|
||||
m18n.n("certmanager_cert_renew_success", domain=domain))
|
||||
|
||||
uo.success()
|
||||
operation_logger.success()
|
||||
|
||||
except Exception as e:
|
||||
import traceback
|
||||
|
@ -418,7 +418,7 @@ def certificate_renew(auth, domain_list, force=False, no_checks=False, email=Fal
|
|||
traceback.print_exc(file=stack)
|
||||
msg = "Certificate renewing for %s failed !" % (domain)
|
||||
logger.error(msg)
|
||||
uo.error(msg)
|
||||
operation_logger.error(msg)
|
||||
logger.error(stack.getvalue())
|
||||
logger.error(str(e))
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ def domain_list(auth):
|
|||
|
||||
|
||||
@is_unit_operation()
|
||||
def domain_add(uo, auth, domain, dyndns=False):
|
||||
def domain_add(operation_logger, auth, domain, dyndns=False):
|
||||
"""
|
||||
Create a custom domain
|
||||
|
||||
|
@ -80,7 +80,7 @@ def domain_add(uo, auth, domain, dyndns=False):
|
|||
except MoulinetteError:
|
||||
raise MoulinetteError(errno.EEXIST, m18n.n('domain_exists'))
|
||||
|
||||
uo.start()
|
||||
operation_logger.start()
|
||||
|
||||
# DynDNS domain
|
||||
if dyndns:
|
||||
|
@ -134,7 +134,7 @@ def domain_add(uo, auth, domain, dyndns=False):
|
|||
|
||||
|
||||
@is_unit_operation()
|
||||
def domain_remove(uo, auth, domain, force=False):
|
||||
def domain_remove(operation_logger, auth, domain, force=False):
|
||||
"""
|
||||
Delete domains
|
||||
|
||||
|
@ -165,7 +165,7 @@ def domain_remove(uo, auth, domain, force=False):
|
|||
raise MoulinetteError(errno.EPERM,
|
||||
m18n.n('domain_uninstall_app_first'))
|
||||
|
||||
uo.start()
|
||||
operation_logger.start()
|
||||
if auth.remove('virtualdomain=' + domain + ',ou=domains') or force:
|
||||
os.system('rm -rf /etc/yunohost/certs/%s' % domain)
|
||||
else:
|
||||
|
|
|
@ -114,7 +114,7 @@ def _dyndns_available(provider, domain):
|
|||
|
||||
|
||||
@is_unit_operation()
|
||||
def dyndns_subscribe(uo, subscribe_host="dyndns.yunohost.org", domain=None, key=None):
|
||||
def dyndns_subscribe(operation_logger, subscribe_host="dyndns.yunohost.org", domain=None, key=None):
|
||||
"""
|
||||
Subscribe to a DynDNS service
|
||||
|
||||
|
@ -126,7 +126,7 @@ def dyndns_subscribe(uo, subscribe_host="dyndns.yunohost.org", domain=None, key=
|
|||
"""
|
||||
if domain is None:
|
||||
domain = _get_maindomain()
|
||||
uo.related_to.append(('domain', domain))
|
||||
operation_logger.related_to.append(('domain', domain))
|
||||
|
||||
# Verify if domain is provided by subscribe_host
|
||||
if not _dyndns_provides(subscribe_host, domain):
|
||||
|
@ -139,7 +139,7 @@ def dyndns_subscribe(uo, subscribe_host="dyndns.yunohost.org", domain=None, key=
|
|||
raise MoulinetteError(errno.ENOENT,
|
||||
m18n.n('dyndns_unavailable', domain=domain))
|
||||
|
||||
uo.start()
|
||||
operation_logger.start()
|
||||
|
||||
if key is None:
|
||||
if len(glob.glob('/etc/yunohost/dyndns/*.key')) == 0:
|
||||
|
@ -176,7 +176,7 @@ def dyndns_subscribe(uo, subscribe_host="dyndns.yunohost.org", domain=None, key=
|
|||
|
||||
|
||||
@is_unit_operation()
|
||||
def dyndns_update(uo, dyn_host="dyndns.yunohost.org", domain=None, key=None,
|
||||
def dyndns_update(operation_logger, dyn_host="dyndns.yunohost.org", domain=None, key=None,
|
||||
ipv4=None, ipv6=None):
|
||||
"""
|
||||
Update IP on DynDNS platform
|
||||
|
@ -232,8 +232,8 @@ def dyndns_update(uo, dyn_host="dyndns.yunohost.org", domain=None, key=None,
|
|||
|
||||
key = keys[0]
|
||||
|
||||
uo.related_to.append(('domain', domain))
|
||||
uo.start()
|
||||
operation_logger.related_to.append(('domain', domain))
|
||||
operation_logger.start()
|
||||
|
||||
# This mean that hmac-md5 is used
|
||||
# (Re?)Trigger the migration to sha256 and return immediately.
|
||||
|
|
|
@ -239,8 +239,8 @@ def is_unit_operation(entities=['app', 'domain', 'service', 'user'],
|
|||
if len(args) > 0:
|
||||
from inspect import getargspec
|
||||
keys = getargspec(func).args
|
||||
if 'uo' in keys:
|
||||
keys.remove('uo')
|
||||
if 'operation_logger' in keys:
|
||||
keys.remove('operation_logger')
|
||||
for k, arg in enumerate(args):
|
||||
kwargs[keys[k]] = arg
|
||||
args = ()
|
||||
|
@ -267,24 +267,24 @@ def is_unit_operation(entities=['app', 'domain', 'service', 'user'],
|
|||
for field in exclude:
|
||||
if field in context:
|
||||
context.pop(field, None)
|
||||
uo = UnitOperation(op_key, related_to, args=context)
|
||||
operation_logger = OperationLogger(op_key, related_to, args=context)
|
||||
|
||||
try:
|
||||
# Start the actual function, and give the unit operation
|
||||
# in argument to let the developper start the record itself
|
||||
args = (uo,) + args
|
||||
args = (operation_logger,) + args
|
||||
result = func(*args, **kwargs)
|
||||
except Exception as e:
|
||||
uo.error(e)
|
||||
operation_logger.error(e)
|
||||
raise
|
||||
else:
|
||||
uo.success()
|
||||
operation_logger.success()
|
||||
return result
|
||||
return func_wrapper
|
||||
return decorate
|
||||
|
||||
|
||||
class UnitOperation(object):
|
||||
class OperationLogger(object):
|
||||
"""
|
||||
Instances of this class represents unit operation done on the ynh instance.
|
||||
|
||||
|
|
|
@ -152,7 +152,7 @@ def service_stop(names):
|
|||
logger.debug(m18n.n('service_already_stopped', service=name))
|
||||
|
||||
@is_unit_operation()
|
||||
def service_enable(uo, names):
|
||||
def service_enable(operation_logger, names):
|
||||
"""
|
||||
Enable one or more services
|
||||
|
||||
|
@ -160,7 +160,7 @@ def service_enable(uo, names):
|
|||
names -- Services name to enable
|
||||
|
||||
"""
|
||||
uo.start()
|
||||
operation_logger.start()
|
||||
if isinstance(names, str):
|
||||
names = [names]
|
||||
for name in names:
|
||||
|
@ -346,7 +346,7 @@ def service_log(name, number=50):
|
|||
|
||||
|
||||
@is_unit_operation([('names', 'service')])
|
||||
def service_regen_conf(uo, names=[], with_diff=False, force=False, dry_run=False,
|
||||
def service_regen_conf(operation_logger, names=[], with_diff=False, force=False, dry_run=False,
|
||||
list_pending=False):
|
||||
"""
|
||||
Regenerate the configuration file(s) for a service
|
||||
|
@ -380,12 +380,12 @@ def service_regen_conf(uo, names=[], with_diff=False, force=False, dry_run=False
|
|||
return pending_conf
|
||||
|
||||
if not dry_run:
|
||||
uo.related_to = [('service', x) for x in names]
|
||||
operation_logger.related_to = [('service', x) for x in names]
|
||||
if not names:
|
||||
uo.name_parameter_override = 'all'
|
||||
operation_logger.name_parameter_override = 'all'
|
||||
elif len(names) != 1:
|
||||
uo.name_parameter_override = str(len(uo.related_to))+'_services'
|
||||
uo.start()
|
||||
operation_logger.name_parameter_override = str(len(operation_logger.related_to))+'_services'
|
||||
operation_logger.start()
|
||||
|
||||
# Clean pending conf directory
|
||||
if os.path.isdir(PENDING_CONF_DIR):
|
||||
|
@ -425,12 +425,12 @@ def service_regen_conf(uo, names=[], with_diff=False, force=False, dry_run=False
|
|||
# Set the processing method
|
||||
_regen = _process_regen_conf if not dry_run else lambda *a, **k: True
|
||||
|
||||
uo.related_to = []
|
||||
operation_logger.related_to = []
|
||||
|
||||
# Iterate over services and process pending conf
|
||||
for service, conf_files in _get_pending_conf(names).items():
|
||||
if not dry_run:
|
||||
uo.related_to.append(('service', service))
|
||||
operation_logger.related_to.append(('service', service))
|
||||
|
||||
logger.debug(m18n.n(
|
||||
'service_regenconf_pending_applying' if not dry_run else
|
||||
|
@ -580,7 +580,7 @@ def service_regen_conf(uo, names=[], with_diff=False, force=False, dry_run=False
|
|||
|
||||
hook_callback('conf_regen', names, pre_callback=_pre_call)
|
||||
|
||||
uo.success()
|
||||
operation_logger.success()
|
||||
|
||||
return result
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ from yunohost.service import service_status, service_regen_conf, service_log, se
|
|||
from yunohost.monitor import monitor_disk, monitor_system
|
||||
from yunohost.utils.packages import ynh_packages_version
|
||||
from yunohost.utils.network import get_public_ip
|
||||
from yunohost.log import is_unit_operation, UnitOperation
|
||||
from yunohost.log import is_unit_operation, OperationLogger
|
||||
|
||||
# FIXME this is a duplicate from apps.py
|
||||
APPS_SETTING_PATH = '/etc/yunohost/apps/'
|
||||
|
@ -140,7 +140,7 @@ def tools_adminpw(auth, new_password):
|
|||
|
||||
|
||||
@is_unit_operation()
|
||||
def tools_maindomain(uo, auth, new_domain=None):
|
||||
def tools_maindomain(operation_logger, auth, new_domain=None):
|
||||
"""
|
||||
Check the current main domain, or change it
|
||||
|
||||
|
@ -157,8 +157,8 @@ def tools_maindomain(uo, auth, new_domain=None):
|
|||
if new_domain not in domain_list(auth)['domains']:
|
||||
raise MoulinetteError(errno.EINVAL, m18n.n('domain_unknown'))
|
||||
|
||||
uo.related_to.append(('domain', new_domain))
|
||||
uo.start()
|
||||
operation_logger.related_to.append(('domain', new_domain))
|
||||
operation_logger.start()
|
||||
|
||||
# Apply changes to ssl certs
|
||||
ssl_key = "/etc/ssl/private/yunohost_key.pem"
|
||||
|
@ -250,7 +250,7 @@ def _is_inside_container():
|
|||
|
||||
|
||||
@is_unit_operation()
|
||||
def tools_postinstall(uo, domain, password, ignore_dyndns=False):
|
||||
def tools_postinstall(operation_logger, domain, password, ignore_dyndns=False):
|
||||
"""
|
||||
YunoHost post-install
|
||||
|
||||
|
@ -299,7 +299,7 @@ def tools_postinstall(uo, domain, password, ignore_dyndns=False):
|
|||
else:
|
||||
dyndns = False
|
||||
|
||||
uo.start()
|
||||
operation_logger.start()
|
||||
logger.info(m18n.n('yunohost_installing'))
|
||||
|
||||
service_regen_conf(['nslcd', 'nsswitch'], force=True)
|
||||
|
@ -476,7 +476,7 @@ def tools_update(ignore_apps=False, ignore_packages=False):
|
|||
|
||||
|
||||
@is_unit_operation()
|
||||
def tools_upgrade(uo, auth, ignore_apps=False, ignore_packages=False):
|
||||
def tools_upgrade(operation_logger, auth, ignore_apps=False, ignore_packages=False):
|
||||
"""
|
||||
Update apps & package cache, then display changelog
|
||||
|
||||
|
@ -517,7 +517,7 @@ def tools_upgrade(uo, auth, ignore_apps=False, ignore_packages=False):
|
|||
if cache.get_changes():
|
||||
logger.info(m18n.n('upgrading_packages'))
|
||||
|
||||
uo.start()
|
||||
operation_logger.start()
|
||||
try:
|
||||
# Apply APT changes
|
||||
# TODO: Logs output for the API
|
||||
|
@ -527,10 +527,10 @@ def tools_upgrade(uo, auth, ignore_apps=False, ignore_packages=False):
|
|||
failure = True
|
||||
logger.warning('unable to upgrade packages: %s' % str(e))
|
||||
logger.error(m18n.n('packages_upgrade_failed'))
|
||||
uo.error(m18n.n('packages_upgrade_failed'))
|
||||
operation_logger.error(m18n.n('packages_upgrade_failed'))
|
||||
else:
|
||||
logger.info(m18n.n('done'))
|
||||
uo.success()
|
||||
operation_logger.success()
|
||||
else:
|
||||
logger.info(m18n.n('packages_no_upgrade'))
|
||||
|
||||
|
@ -716,7 +716,7 @@ def tools_port_available(port):
|
|||
|
||||
|
||||
@is_unit_operation()
|
||||
def tools_shutdown(uo, force=False):
|
||||
def tools_shutdown(operation_logger, force=False):
|
||||
shutdown = force
|
||||
if not shutdown:
|
||||
try:
|
||||
|
@ -729,13 +729,13 @@ def tools_shutdown(uo, force=False):
|
|||
shutdown = True
|
||||
|
||||
if shutdown:
|
||||
uo.start()
|
||||
operation_logger.start()
|
||||
logger.warn(m18n.n('server_shutdown'))
|
||||
subprocess.check_call(['systemctl', 'poweroff'])
|
||||
|
||||
|
||||
@is_unit_operation()
|
||||
def tools_reboot(uo, force=False):
|
||||
def tools_reboot(operation_logger, force=False):
|
||||
reboot = force
|
||||
if not reboot:
|
||||
try:
|
||||
|
@ -747,7 +747,7 @@ def tools_reboot(uo, force=False):
|
|||
if i.lower() == 'y' or i.lower() == 'yes':
|
||||
reboot = True
|
||||
if reboot:
|
||||
uo.start()
|
||||
operation_logger.start()
|
||||
logger.warn(m18n.n('server_reboot'))
|
||||
subprocess.check_call(['systemctl', 'reboot'])
|
||||
|
||||
|
@ -870,8 +870,8 @@ def tools_migrations_migrate(target=None, skip=False, auto=False, accept_disclai
|
|||
for migration in migrations:
|
||||
|
||||
# Start register change on system
|
||||
uo= UnitOperation('tools_migrations_migrate_' + mode)
|
||||
uo.start()
|
||||
operation_logger= OperationLogger('tools_migrations_migrate_' + mode)
|
||||
operation_logger.start()
|
||||
|
||||
if not skip:
|
||||
|
||||
|
@ -881,11 +881,11 @@ def tools_migrations_migrate(target=None, skip=False, auto=False, accept_disclai
|
|||
try:
|
||||
if mode == "forward":
|
||||
m = migration["module"].MyMigration()
|
||||
m.uo = uo
|
||||
m.operation_logger = operation_logger
|
||||
m.migrate()
|
||||
elif mode == "backward":
|
||||
m = migration["module"].MyMigration()
|
||||
m.uo = uo
|
||||
m.operation_logger = operation_logger
|
||||
m.backward()
|
||||
else: # can't happen
|
||||
raise Exception("Illegal state for migration: '%s', should be either 'forward' or 'backward'" % mode)
|
||||
|
@ -897,7 +897,7 @@ def tools_migrations_migrate(target=None, skip=False, auto=False, accept_disclai
|
|||
number=migration.number,
|
||||
name=migration.name)
|
||||
logger.error(msg, exc_info=1)
|
||||
uo.error(msg)
|
||||
operation_logger.error(msg)
|
||||
break
|
||||
|
||||
else: # if skip
|
||||
|
@ -911,7 +911,7 @@ def tools_migrations_migrate(target=None, skip=False, auto=False, accept_disclai
|
|||
"name": migration.name
|
||||
}
|
||||
|
||||
uo.success()
|
||||
operation_logger.success()
|
||||
|
||||
# special case where we want to go back from the start
|
||||
if target == 0:
|
||||
|
|
|
@ -99,7 +99,7 @@ def user_list(auth, fields=None):
|
|||
|
||||
|
||||
@is_unit_operation([('username', 'user')])
|
||||
def user_create(uo, auth, username, firstname, lastname, mail, password,
|
||||
def user_create(operation_logger, auth, username, firstname, lastname, mail, password,
|
||||
mailbox_quota="0"):
|
||||
"""
|
||||
Create user
|
||||
|
@ -134,7 +134,7 @@ def user_create(uo, auth, username, firstname, lastname, mail, password,
|
|||
m18n.n('mail_domain_unknown',
|
||||
domain=mail.split("@")[1]))
|
||||
|
||||
uo.start()
|
||||
operation_logger.start()
|
||||
|
||||
# Get random UID/GID
|
||||
all_uid = {x.pw_uid for x in pwd.getpwall()}
|
||||
|
@ -222,7 +222,7 @@ def user_create(uo, auth, username, firstname, lastname, mail, password,
|
|||
|
||||
|
||||
@is_unit_operation([('username', 'user')])
|
||||
def user_delete(uo, auth, username, purge=False):
|
||||
def user_delete(operation_logger, auth, username, purge=False):
|
||||
"""
|
||||
Delete user
|
||||
|
||||
|
@ -234,7 +234,7 @@ def user_delete(uo, auth, username, purge=False):
|
|||
from yunohost.app import app_ssowatconf
|
||||
from yunohost.hook import hook_callback
|
||||
|
||||
uo.start()
|
||||
operation_logger.start()
|
||||
if auth.remove('uid=%s,ou=users' % username):
|
||||
# Invalidate passwd to take user deletion into account
|
||||
subprocess.call(['nscd', '-i', 'passwd'])
|
||||
|
@ -259,7 +259,7 @@ def user_delete(uo, auth, username, purge=False):
|
|||
|
||||
|
||||
@is_unit_operation([('username', 'user')], exclude=['auth', 'change_password'])
|
||||
def user_update(uo, auth, username, firstname=None, lastname=None, mail=None,
|
||||
def user_update(operation_logger, auth, username, firstname=None, lastname=None, mail=None,
|
||||
change_password=None, add_mailforward=None, remove_mailforward=None,
|
||||
add_mailalias=None, remove_mailalias=None, mailbox_quota=None):
|
||||
"""
|
||||
|
@ -360,7 +360,7 @@ def user_update(uo, auth, username, firstname=None, lastname=None, mail=None,
|
|||
if mailbox_quota is not None:
|
||||
new_attr_dict['mailuserquota'] = mailbox_quota
|
||||
|
||||
uo.start()
|
||||
operation_logger.start()
|
||||
|
||||
if auth.update('uid=%s,ou=users' % username, new_attr_dict):
|
||||
logger.success(m18n.n('user_updated'))
|
||||
|
|
Loading…
Add table
Reference in a new issue