Remove 'auto' option, essentially irrelevant if we want to properly manage errors

This commit is contained in:
Alexandre Aubin 2018-08-09 00:24:31 +00:00
parent 5e99db7c63
commit 77b7f96b33
9 changed files with 27 additions and 31 deletions

View file

@ -191,7 +191,7 @@ def app_fetchlist(url=None, name=None):
_write_appslist_list(appslists) _write_appslist_list(appslists)
@is_unit_operation(auto=False) @is_unit_operation()
def app_removelist(uo, name): def app_removelist(uo, name):
""" """
Remove list from the repositories Remove list from the repositories
@ -429,7 +429,7 @@ def app_map(app=None, raw=False, user=None):
return result return result
@is_unit_operation(auto=False) @is_unit_operation()
def app_change_url(uo, auth, app, domain, path): def app_change_url(uo, auth, app, domain, path):
""" """
Modify the URL at which an application is installed. Modify the URL at which an application is installed.
@ -681,7 +681,7 @@ def app_upgrade(auth, app=[], url=None, file=None):
return {"log": service_log('yunohost-api', number="100").values()[0]} return {"log": service_log('yunohost-api', number="100").values()[0]}
@is_unit_operation(auto=False) @is_unit_operation()
def app_install(uo, auth, app, label=None, args=None, no_remove_on_failure=False): def app_install(uo, auth, app, label=None, args=None, no_remove_on_failure=False):
""" """
Install apps Install apps
@ -862,7 +862,7 @@ def app_install(uo, auth, app, label=None, args=None, no_remove_on_failure=False
hook_callback('post_app_install', args=args_list, env=env_dict) hook_callback('post_app_install', args=args_list, env=env_dict)
@is_unit_operation(auto=False) @is_unit_operation()
def app_remove(uo, auth, app): def app_remove(uo, auth, app):
""" """
Remove app Remove app
@ -1103,7 +1103,7 @@ def app_debug(app):
} }
@is_unit_operation(auto=False) @is_unit_operation()
def app_makedefault(uo, auth, app, domain=None): def app_makedefault(uo, auth, app, domain=None):
""" """
Redirect domain root to an app Redirect domain root to an app

View file

@ -51,7 +51,7 @@ from yunohost.hook import (
from yunohost.monitor import binary_to_human from yunohost.monitor import binary_to_human
from yunohost.tools import tools_postinstall from yunohost.tools import tools_postinstall
from yunohost.service import service_regen_conf from yunohost.service import service_regen_conf
from yunohost.log import UnitOperation, is_unit_operation from yunohost.log import UnitOperation
BACKUP_PATH = '/home/yunohost.backup' BACKUP_PATH = '/home/yunohost.backup'
ARCHIVES_PATH = '%s/archives' % BACKUP_PATH ARCHIVES_PATH = '%s/archives' % BACKUP_PATH

View file

@ -47,7 +47,7 @@ from yunohost.utils.errors import YunoHostError
from moulinette import m18n from moulinette import m18n
from yunohost.app import app_ssowatconf from yunohost.app import app_ssowatconf
from yunohost.service import _run_service_command, service_regen_conf from yunohost.service import _run_service_command, service_regen_conf
from yunohost.log import is_unit_operation, UnitOperation from yunohost.log import UnitOperation
logger = getActionLogger('yunohost.certmanager') logger = getActionLogger('yunohost.certmanager')

View file

@ -62,7 +62,7 @@ def domain_list(auth):
return {'domains': result_list} return {'domains': result_list}
@is_unit_operation(auto=False) @is_unit_operation()
def domain_add(uo, auth, domain, dyndns=False): def domain_add(uo, auth, domain, dyndns=False):
""" """
Create a custom domain Create a custom domain
@ -133,7 +133,7 @@ def domain_add(uo, auth, domain, dyndns=False):
logger.success(m18n.n('domain_created')) logger.success(m18n.n('domain_created'))
@is_unit_operation(auto=False) @is_unit_operation()
def domain_remove(uo, auth, domain, force=False): def domain_remove(uo, auth, domain, force=False):
""" """
Delete domains Delete domains

View file

@ -113,7 +113,7 @@ def _dyndns_available(provider, domain):
return r == u"Domain %s is available" % domain return r == u"Domain %s is available" % domain
@is_unit_operation(auto=False) @is_unit_operation()
def dyndns_subscribe(uo, subscribe_host="dyndns.yunohost.org", domain=None, key=None): def dyndns_subscribe(uo, subscribe_host="dyndns.yunohost.org", domain=None, key=None):
""" """
Subscribe to a DynDNS service Subscribe to a DynDNS service
@ -175,7 +175,7 @@ def dyndns_subscribe(uo, subscribe_host="dyndns.yunohost.org", domain=None, key=
dyndns_installcron() dyndns_installcron()
@is_unit_operation(auto=False) @is_unit_operation()
def dyndns_update(uo, dyn_host="dyndns.yunohost.org", domain=None, key=None, def dyndns_update(uo, dyn_host="dyndns.yunohost.org", domain=None, key=None,
ipv4=None, ipv6=None): ipv4=None, ipv6=None):
""" """

View file

@ -197,7 +197,7 @@ def log_display(path, number=50, share=False):
return infos return infos
def is_unit_operation(entities='app,domain,service,user', exclude='auth,password', operation_key=None, auto=True): def is_unit_operation(entities='app,domain,service,user', exclude='auth,password', operation_key=None):
""" """
Configure quickly a unit operation Configure quickly a unit operation
@ -218,9 +218,6 @@ def is_unit_operation(entities='app,domain,service,user', exclude='auth,password
well formed description you should add a translation key like this well formed description you should add a translation key like this
"log_" + operation_key in locales files. "log_" + operation_key in locales files.
auto If true, start the recording. If False, the unit operation object
created is given to the decorated function as the first argument and you can
start recording at the good time.
""" """
def decorate(func): def decorate(func):
def func_wrapper(*args, **kwargs): def func_wrapper(*args, **kwargs):
@ -266,12 +263,9 @@ def is_unit_operation(entities='app,domain,service,user', exclude='auth,password
context.pop(field, None) context.pop(field, None)
uo = UnitOperation(op_key, related_to, args=context) uo = UnitOperation(op_key, related_to, args=context)
# Start to record or give the unit operation in argument to let the
# developper start the record itself
if auto:
uo.start()
try: try:
if not auto: # Start the actual function, and give the unit operation
# in argument to let the developper start the record itself
args = (uo,) + args args = (uo,) + args
result = func(*args, **kwargs) result = func(*args, **kwargs)
except Exception as e: except Exception as e:

View file

@ -152,7 +152,7 @@ def service_stop(names):
logger.debug(m18n.n('service_already_stopped', service=name)) logger.debug(m18n.n('service_already_stopped', service=name))
@is_unit_operation() @is_unit_operation()
def service_enable(names): def service_enable(uo, names):
""" """
Enable one or more services Enable one or more services
@ -160,6 +160,7 @@ def service_enable(names):
names -- Services name to enable names -- Services name to enable
""" """
uo.start()
if isinstance(names, str): if isinstance(names, str):
names = [names] names = [names]
for name in names: for name in names:
@ -344,7 +345,7 @@ def service_log(name, number=50):
return result return result
@is_unit_operation('names:service', auto=False) @is_unit_operation('names:service')
def service_regen_conf(uo, names=[], with_diff=False, force=False, dry_run=False, def service_regen_conf(uo, names=[], with_diff=False, force=False, dry_run=False,
list_pending=False): list_pending=False):
""" """

View file

@ -139,7 +139,7 @@ def tools_adminpw(auth, new_password):
logger.success(m18n.n('admin_password_changed')) logger.success(m18n.n('admin_password_changed'))
@is_unit_operation(auto=False) @is_unit_operation()
def tools_maindomain(uo, auth, new_domain=None): def tools_maindomain(uo, auth, new_domain=None):
""" """
Check the current main domain, or change it Check the current main domain, or change it
@ -249,7 +249,7 @@ def _is_inside_container():
return out.split()[1] != "(1," return out.split()[1] != "(1,"
@is_unit_operation(auto=False) @is_unit_operation()
def tools_postinstall(uo, domain, password, ignore_dyndns=False): def tools_postinstall(uo, domain, password, ignore_dyndns=False):
""" """
YunoHost post-install YunoHost post-install
@ -473,7 +473,7 @@ def tools_update(ignore_apps=False, ignore_packages=False):
return {'packages': packages, 'apps': apps} return {'packages': packages, 'apps': apps}
@is_unit_operation(auto=False) @is_unit_operation()
def tools_upgrade(uo, auth, ignore_apps=False, ignore_packages=False): def tools_upgrade(uo, auth, ignore_apps=False, ignore_packages=False):
""" """
Update apps & package cache, then display changelog Update apps & package cache, then display changelog
@ -713,7 +713,7 @@ def tools_port_available(port):
return False return False
@is_unit_operation(auto=False) @is_unit_operation()
def tools_shutdown(uo, force=False): def tools_shutdown(uo, force=False):
shutdown = force shutdown = force
if not shutdown: if not shutdown:
@ -732,7 +732,7 @@ def tools_shutdown(uo, force=False):
subprocess.check_call(['systemctl', 'poweroff']) subprocess.check_call(['systemctl', 'poweroff'])
@is_unit_operation(auto=False) @is_unit_operation()
def tools_reboot(uo, force=False): def tools_reboot(uo, force=False):
reboot = force reboot = force
if not reboot: if not reboot:

View file

@ -99,7 +99,7 @@ def user_list(auth, fields=None):
return {'users': users} return {'users': users}
@is_unit_operation('username:user', auto=False) @is_unit_operation('username:user')
def user_create(uo, auth, username, firstname, lastname, mail, password, def user_create(uo, auth, username, firstname, lastname, mail, password,
mailbox_quota="0"): mailbox_quota="0"):
""" """
@ -224,7 +224,7 @@ def user_create(uo, auth, username, firstname, lastname, mail, password,
@is_unit_operation('username:user') @is_unit_operation('username:user')
def user_delete(auth, username, purge=False): def user_delete(uo, auth, username, purge=False):
""" """
Delete user Delete user
@ -236,6 +236,7 @@ def user_delete(auth, username, purge=False):
from yunohost.app import app_ssowatconf from yunohost.app import app_ssowatconf
from yunohost.hook import hook_callback from yunohost.hook import hook_callback
uo.start()
if auth.remove('uid=%s,ou=users' % username): if auth.remove('uid=%s,ou=users' % username):
# Invalidate passwd to take user deletion into account # Invalidate passwd to take user deletion into account
subprocess.call(['nscd', '-i', 'passwd']) subprocess.call(['nscd', '-i', 'passwd'])
@ -259,7 +260,7 @@ def user_delete(auth, username, purge=False):
logger.success(m18n.n('user_deleted')) logger.success(m18n.n('user_deleted'))
@is_unit_operation('username:user', exclude='auth,change_password', auto=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(uo, auth, username, firstname=None, lastname=None, mail=None,
change_password=None, add_mailforward=None, remove_mailforward=None, change_password=None, add_mailforward=None, remove_mailforward=None,
add_mailalias=None, remove_mailalias=None, mailbox_quota=None): add_mailalias=None, remove_mailalias=None, mailbox_quota=None):