[fix] Do not fail when the service is not registered properly

This commit is contained in:
kload 2015-09-30 14:17:45 -04:00
parent 17376896a4
commit c51454b7fe

View file

@ -199,7 +199,8 @@ def service_status(names=[]):
m18n.n('service_unknown', name)) m18n.n('service_unknown', name))
status = None status = None
if services[name]['status'] == 'service': if 'status' not in services[name] or \
services[name]['status'] == 'service':
status = 'service %s status' % name status = 'service %s status' % name
else: else:
status = str(services[name]['status']) status = str(services[name]['status'])
@ -283,18 +284,11 @@ def service_regenconf(service=None, force=False):
""" """
from yunohost.hook import hook_callback from yunohost.hook import hook_callback
if service is None: if service is not None:
# Regen ALL THE CONFIGURATIONS hook_callback('conf_regen', [service], args=[force])
hook_callback('conf_regen', args=[force])
msignals.display(m18n.n('services_configured'), 'success')
else: else:
if service not in _get_services().keys(): hook_callback('conf_regen', args=[force])
raise MoulinetteError(errno.EINVAL, m18n.n('service_unknown', service)) msignals.display(m18n.n('services_configured'), 'success')
hook_callback('conf_regen', [service] , args=[force])
msignals.display(m18n.n('service_configured', service), 'success')
def _run_service_command(action, service): def _run_service_command(action, service):
@ -436,6 +430,7 @@ def service_saferemove(service, conf_file, force=False):
""" """
deleted = False deleted = False
services = _get_services()
if not os.path.exists(conf_file): if not os.path.exists(conf_file):
try: try:
@ -443,8 +438,6 @@ def service_saferemove(service, conf_file, force=False):
except KeyError: pass except KeyError: pass
return True return True
services = _get_services()
# Backup existing file # Backup existing file
date = time.strftime("%Y%m%d.%H%M%S") date = time.strftime("%Y%m%d.%H%M%S")
conf_backup_file = conf_backup_dir + conf_file +'-'+ date conf_backup_file = conf_backup_dir + conf_file +'-'+ date