Explicitely tell when to start the uo logging to avoid displaying the message about logs when not needed

This commit is contained in:
Alexandre Aubin 2018-08-08 17:05:52 +00:00
parent 37c5547755
commit 5e99db7c63
6 changed files with 33 additions and 22 deletions

View file

@ -191,8 +191,8 @@ def app_fetchlist(url=None, name=None):
_write_appslist_list(appslists)
@is_unit_operation()
def app_removelist(name):
@is_unit_operation(auto=False)
def app_removelist(uo, name):
"""
Remove list from the repositories
@ -206,6 +206,8 @@ def app_removelist(name):
if name not in appslists.keys():
raise MoulinetteError(errno.ENOENT, m18n.n('appslist_unknown', appslist=name))
uo.start()
# Remove json
json_path = '%s/%s.json' % (REPO_PATH, name)
if os.path.exists(json_path):

View file

@ -162,7 +162,6 @@ def _certificate_install_selfsigned(domain_list, force=False):
uo = UnitOperation('selfsigned_cert_install', [('domain', domain)],
args={'force': force})
uo.start()
# Paths of files and folder we'll need
date_tag = datetime.now().strftime("%Y%m%d.%H%M%S")
@ -186,6 +185,8 @@ def _certificate_install_selfsigned(domain_list, force=False):
raise MoulinetteError(errno.EINVAL, m18n.n(
'certmanager_attempt_to_replace_valid_cert', domain=domain))
uo.start()
# Create output folder for new certificate stuff
os.makedirs(new_cert_folder)
@ -288,8 +289,6 @@ def _certificate_install_letsencrypt(auth, domain_list, force=False, no_checks=F
uo = UnitOperation('letsencrypt_cert_install', [('domain', domain)],
args={'force': force, 'no_checks': no_checks,
'staging': staging})
uo.start()
logger.info(
"Now attempting install of certificate for domain %s!", domain)
@ -297,6 +296,8 @@ 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()
_configure_for_acme_challenge(auth, domain)
_fetch_and_enable_new_certificate(domain, staging)
_install_cron()
@ -389,7 +390,6 @@ def certificate_renew(auth, domain_list, force=False, no_checks=False, email=Fal
uo = UnitOperation('letsencrypt_cert_renew', [('domain', domain)],
args={'force': force, 'no_checks': no_checks,
'staging': staging, 'email': email})
uo.start()
logger.info(
"Now attempting renewing of certificate for domain %s !", domain)
@ -398,6 +398,8 @@ 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()
_fetch_and_enable_new_certificate(domain, staging)
logger.success(

View file

@ -62,8 +62,8 @@ def domain_list(auth):
return {'domains': result_list}
@is_unit_operation()
def domain_add(auth, domain, dyndns=False):
@is_unit_operation(auto=False)
def domain_add(uo, auth, domain, dyndns=False):
"""
Create a custom domain
@ -80,6 +80,8 @@ def domain_add(auth, domain, dyndns=False):
except MoulinetteError:
raise MoulinetteError(errno.EEXIST, m18n.n('domain_exists'))
uo.start()
# DynDNS domain
if dyndns:
@ -131,8 +133,8 @@ def domain_add(auth, domain, dyndns=False):
logger.success(m18n.n('domain_created'))
@is_unit_operation()
def domain_remove(auth, domain, force=False):
@is_unit_operation(auto=False)
def domain_remove(uo, auth, domain, force=False):
"""
Delete domains
@ -163,6 +165,7 @@ def domain_remove(auth, domain, force=False):
raise MoulinetteError(errno.EPERM,
m18n.n('domain_uninstall_app_first'))
uo.start()
if auth.remove('virtualdomain=' + domain + ',ou=domains') or force:
os.system('rm -rf /etc/yunohost/certs/%s' % domain)
else:

View file

@ -127,7 +127,6 @@ 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))
uo.start()
# Verify if domain is provided by subscribe_host
if not _dyndns_provides(subscribe_host, domain):
@ -140,6 +139,8 @@ def dyndns_subscribe(uo, subscribe_host="dyndns.yunohost.org", domain=None, key=
raise MoulinetteError(errno.ENOENT,
m18n.n('dyndns_unavailable', domain=domain))
uo.start()
if key is None:
if len(glob.glob('/etc/yunohost/dyndns/*.key')) == 0:
if not os.path.exists('/etc/yunohost/dyndns'):
@ -217,17 +218,12 @@ def dyndns_update(uo, dyn_host="dyndns.yunohost.org", domain=None, key=None,
return
else:
logger.info("Updated needed, going on...")
if domain is not None:
uo.related_to.append(('domain', domain))
# If domain is not given, try to guess it from keys available...
if domain is None:
(domain, key) = _guess_current_dyndns_domain(dyn_host)
uo.related_to.append(('domain', domain))
uo.start()
# If key is not given, pick the first file we find with the domain given
else:
uo.start()
if key is None:
keys = glob.glob('/etc/yunohost/dyndns/K{0}.+*.private'.format(domain))
@ -236,6 +232,9 @@ def dyndns_update(uo, dyn_host="dyndns.yunohost.org", domain=None, key=None,
key = keys[0]
uo.related_to.append(('domain', domain))
uo.start()
# This mean that hmac-md5 is used
# (Re?)Trigger the migration to sha256 and return immediately.
# The actual update will be done in next run.

View file

@ -249,8 +249,8 @@ def _is_inside_container():
return out.split()[1] != "(1,"
@is_unit_operation()
def tools_postinstall(domain, password, ignore_dyndns=False):
@is_unit_operation(auto=False)
def tools_postinstall(uo, domain, password, ignore_dyndns=False):
"""
YunoHost post-install
@ -299,6 +299,7 @@ def tools_postinstall(domain, password, ignore_dyndns=False):
else:
dyndns = False
uo.start()
logger.info(m18n.n('yunohost_installing'))
service_regen_conf(['nslcd', 'nsswitch'], force=True)

View file

@ -99,8 +99,8 @@ def user_list(auth, fields=None):
return {'users': users}
@is_unit_operation('username:user')
def user_create(auth, username, firstname, lastname, mail, password,
@is_unit_operation('username:user', auto=False)
def user_create(uo, auth, username, firstname, lastname, mail, password,
mailbox_quota="0"):
"""
Create user
@ -136,6 +136,8 @@ def user_create(auth, username, firstname, lastname, mail, password,
m18n.n('mail_domain_unknown',
domain=mail.split("@")[1]))
uo.start()
# Get random UID/GID
all_uid = {x.pw_uid for x in pwd.getpwall()}
all_gid = {x.pw_gid for x in pwd.getpwall()}
@ -257,8 +259,8 @@ def user_delete(auth, username, purge=False):
logger.success(m18n.n('user_deleted'))
@is_unit_operation('username:user', exclude='auth,change_password')
def user_update(auth, username, firstname=None, lastname=None, mail=None,
@is_unit_operation('username:user', exclude='auth,change_password', auto=False)
def user_update(uo, 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):
"""
@ -359,6 +361,8 @@ def user_update(auth, username, firstname=None, lastname=None, mail=None,
if mailbox_quota is not None:
new_attr_dict['mailuserquota'] = mailbox_quota
uo.start()
if auth.update('uid=%s,ou=users' % username, new_attr_dict):
logger.success(m18n.n('user_updated'))
app_ssowatconf(auth)