[enh] raise exception when journal doesn't exist

This commit is contained in:
Laurent Peuch 2018-01-06 11:20:41 +01:00
parent 223e41743b
commit 388e611c45
2 changed files with 8 additions and 4 deletions

View file

@ -201,6 +201,7 @@
"invalid_url_format": "Invalid URL format", "invalid_url_format": "Invalid URL format",
"ip6tables_unavailable": "You cannot play with ip6tables here. You are either in a container or your kernel does not support it", "ip6tables_unavailable": "You cannot play with ip6tables here. You are either in a container or your kernel does not support it",
"iptables_unavailable": "You cannot play with iptables here. You are either in a container or your kernel does not support it", "iptables_unavailable": "You cannot play with iptables here. You are either in a container or your kernel does not support it",
"journal_does_exists": "There is not journal with the name '{journal}', use 'yunohost journal list to see all available journals'",
"ldap_init_failed_to_create_admin": "LDAP initialization failed to create admin user", "ldap_init_failed_to_create_admin": "LDAP initialization failed to create admin user",
"ldap_initialized": "LDAP has been initialized", "ldap_initialized": "LDAP has been initialized",
"license_undefined": "undefined", "license_undefined": "undefined",

View file

@ -26,9 +26,12 @@
import os import os
import yaml import yaml
import errno
from datetime import datetime from datetime import datetime
from moulinette import m18n
from moulinette.core import MoulinetteError
from moulinette.utils.log import getActionLogger from moulinette.utils.log import getActionLogger
JOURNALS_PATH = '/var/log/yunohost/journals/' JOURNALS_PATH = '/var/log/yunohost/journals/'
@ -84,8 +87,8 @@ def journals_display(file_name):
""" """
if not os.path.exists(JOURNALS_PATH): if not os.path.exists(JOURNALS_PATH):
# TODO raise exception raise MoulinetteError(errno.EINVAL,
return {} m18n.n('journal_does_exists', journal=file_name))
for category in os.listdir(JOURNALS_PATH): for category in os.listdir(JOURNALS_PATH):
for journal in filter(lambda x: x.endswith(".journal"), os.listdir(os.path.join(JOURNALS_PATH, category))): for journal in filter(lambda x: x.endswith(".journal"), os.listdir(os.path.join(JOURNALS_PATH, category))):
@ -112,8 +115,8 @@ def journals_display(file_name):
"logs": logs, "logs": logs,
} }
# TODO raise exception raise MoulinetteError(errno.EINVAL,
return {} m18n.n('journal_does_exists', journal=file_name))
class Journal(object): class Journal(object):