Add a --share option to 'log display' to share the log on yunopaste

This commit is contained in:
Alexandre Aubin 2018-07-21 17:59:51 +00:00
parent eb42a25ada
commit 8eaceefbbd
3 changed files with 18 additions and 2 deletions

View file

@ -1693,3 +1693,6 @@ log:
help: Number of lines to display help: Number of lines to display
default: 50 default: 50
type: int type: int
--share:
help: Share the full log using yunopaste
action: store_true

View file

@ -211,7 +211,7 @@
"log_link_to_log": "Full log of this operation: '<a href=\"#/tools/logs/{name}\" style=\"text-decoration:underline\">{desc}</a>'", "log_link_to_log": "Full log of this operation: '<a href=\"#/tools/logs/{name}\" style=\"text-decoration:underline\">{desc}</a>'",
"log_help_to_get_log": "To view the log of the operation '{desc}', use the command 'yunohost log display {name}'", "log_help_to_get_log": "To view the log of the operation '{desc}', use the command 'yunohost log display {name}'",
"log_link_to_failed_log": "The operation '{desc}' has failed ! To get help, please <a href=\"#/tools/logs/{name}\">provide the full log of this operation</a>", "log_link_to_failed_log": "The operation '{desc}' has failed ! To get help, please <a href=\"#/tools/logs/{name}\">provide the full log of this operation</a>",
"log_help_to_get_failed_log": "The operation '{desc}' has failed ! To get help, please provide the full log of this operation. It can be obtained with the command 'yunohost log display {name}'", "log_help_to_get_failed_log": "The operation '{desc}' has failed ! To get help, please share the full log of this operation using the command 'yunohost log display {name} --share'",
"log_category_404": "The log category '{category}' does not exist", "log_category_404": "The log category '{category}' does not exist",
"log_does_exists": "There is not operation log with the name '{log}', use 'yunohost log list to see all available operation logs'", "log_does_exists": "There is not operation log with the name '{log}', use 'yunohost log list to see all available operation logs'",
"log_operation_unit_unclosed_properly": "Operation unit has not been closed properly", "log_operation_unit_unclosed_properly": "Operation unit has not been closed properly",

View file

@ -36,6 +36,7 @@ from sys import exc_info
from moulinette import m18n, msettings from moulinette import m18n, msettings
from moulinette.core import MoulinetteError from moulinette.core import MoulinetteError
from moulinette.utils.log import getActionLogger from moulinette.utils.log import getActionLogger
from moulinette.utils.filesystem import read_file
CATEGORIES_PATH = '/var/log/yunohost/categories/' CATEGORIES_PATH = '/var/log/yunohost/categories/'
OPERATIONS_PATH = '/var/log/yunohost/categories/operation/' OPERATIONS_PATH = '/var/log/yunohost/categories/operation/'
@ -103,7 +104,7 @@ def log_list(category=[], limit=None):
return result return result
def log_display(path, number=50): def log_display(path, number=50, share=False):
""" """
Display a log file enriched with metadata if any. Display a log file enriched with metadata if any.
@ -113,6 +114,7 @@ def log_display(path, number=50):
Argument: Argument:
file_name file_name
number number
share
""" """
# Normalize log/metadata paths and filenames # Normalize log/metadata paths and filenames
@ -147,6 +149,17 @@ def log_display(path, number=50):
infos["description"] = _get_description_from_name(base_filename) infos["description"] = _get_description_from_name(base_filename)
infos['name'] = base_filename infos['name'] = base_filename
if share:
from yunohost.utils.yunopaste import yunopaste
content = ""
if os.path.exists(md_path):
content += read_file(md_path)
content += "\n============\n\n"
if os.path.exists(log_path):
content += read_file(log_path)
return yunopaste(content)
# Display metadata if exist # Display metadata if exist
if os.path.exists(md_path): if os.path.exists(md_path):
with open(md_path, "r") as md_file: with open(md_path, "r") as md_file: