From 1b62e9425d276691605ab7ba620b3d2be923dded Mon Sep 17 00:00:00 2001 From: ljf Date: Sat, 14 Apr 2018 18:11:50 +0200 Subject: [PATCH] [enh] Allow to display part of log specified with path --- data/actionsmap/yunohost.yml | 9 +++++++-- src/yunohost/log.py | 17 ++++++++++------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/data/actionsmap/yunohost.yml b/data/actionsmap/yunohost.yml index e57d44716..2150aa7d3 100644 --- a/data/actionsmap/yunohost.yml +++ b/data/actionsmap/yunohost.yml @@ -1625,7 +1625,12 @@ log: ### log_display() display: action_help: Display a log content - api: GET /logs/ + api: GET /logs/ arguments: file_name: - help: Log filenames for which to display the content + help: Log filename which to display the content + -n: + full: --number + help: Number of lines to display + default: 50 + type: int diff --git a/src/yunohost/log.py b/src/yunohost/log.py index bb0be6d0d..86e2f9267 100644 --- a/src/yunohost/log.py +++ b/src/yunohost/log.py @@ -98,18 +98,21 @@ def log_display(file_name, number=50): else: base_filename = file_name - md_filename = base_filename + METADATA_FILE_EXT - md_path = os.path.join(OPERATIONS_PATH, md_filename) - log_filename = base_filename + LOG_FILE_EXT - log_path = os.path.join(OPERATIONS_PATH, log_filename) + base_path = base_filename + if not base_filename.startswith('/'): + base_path = os.path.join(OPERATIONS_PATH, base_filename) + + md_path = base_path + METADATA_FILE_EXT + log_path = base_path + LOG_FILE_EXT operation = base_filename.split("-") if not os.path.exists(md_path) and not os.path.exists(log_path): raise MoulinetteError(errno.EINVAL, m18n.n('log_does_exists', log=file_name)) infos = {} - infos['description'] = m18n.n("log_" + operation[2], *operation[3:]), - infos['name'] = base_filename + if not base_filename.startswith('/'): + infos['description'] = m18n.n("log_" + operation[2], *operation[3:]), + infos['name'] = base_filename if os.path.exists(md_path): with open(md_path, "r") as md_file: @@ -125,7 +128,7 @@ def log_display(file_name, number=50): if os.path.exists(log_path): from yunohost.service import _tail logs = _tail(log_path, int(number)) - logs = [{"datetime": x.split(": ", 1)[0].replace("_", " "), "line": x.split(": ", 1)[1]} for x in logs if x] + #logs = [{"datetime": x.split(": ", 1)[0].replace("_", " "), "line": x.split(": ", 1)[1]} for x in logs if x] infos['log_path'] = log_path infos['logs'] = logs