From d44f49083d9193daf5e676cd5f8be6b80c0f8657 Mon Sep 17 00:00:00 2001 From: "Nicola Spanti (RyDroid)" Date: Thu, 17 Sep 2015 01:19:49 +0200 Subject: [PATCH] Minor changes in Python source files --- bin/yunohost | 27 +++++++++++++++++++++++++++ bin/yunohost-api | 27 +++++++++++++++++++++++++++ lib/yunohost/service.py | 9 ++++++++- 3 files changed, 62 insertions(+), 1 deletion(-) diff --git a/bin/yunohost b/bin/yunohost index b24fffb77..c2bf4cf7a 100755 --- a/bin/yunohost +++ b/bin/yunohost @@ -1,6 +1,25 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +""" License + + Copyright (C) 2015 YunoHost + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program; if not, see https://www.gnu.org/licenses + +""" + import sys import os @@ -54,6 +73,10 @@ def _parse_argv(): argv = list(sys.argv) argv.pop(0) + if '--cache' in argv: + global USE_CACHE + USE_CACHE = True + argv.remove('--cache') if '--no-cache' in argv: global USE_CACHE USE_CACHE = False @@ -66,6 +89,10 @@ def _parse_argv(): global LOGGERS_LEVEL LOGGERS_LEVEL = 'DEBUG' argv.remove('--debug') + if '--no-debug' in argv: + global LOGGERS_LEVEL + LOGGERS_LEVEL = 'INFO' + argv.remove('--no-debug') if '--verbose' in argv: global LOGGERS_HANDLERS if 'console' not in LOGGERS_HANDLERS: diff --git a/bin/yunohost-api b/bin/yunohost-api index 84f38c661..81b38dd19 100755 --- a/bin/yunohost-api +++ b/bin/yunohost-api @@ -1,6 +1,25 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +""" License + + Copyright (C) 2015 YunoHost + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program; if not, see https://www.gnu.org/licenses + +""" + import sys import os.path @@ -54,6 +73,10 @@ def _parse_argv(): argv = list(sys.argv) argv.pop(0) + if '--no-cache' in argv: + global USE_CACHE + USE_CACHE = False + argv.remove('--no-cache') if '--no-cache' in argv: global USE_CACHE USE_CACHE = False @@ -66,6 +89,10 @@ def _parse_argv(): global LOGGERS_LEVEL LOGGERS_LEVEL = 'DEBUG' argv.remove('--debug') + if '--no-debug' in argv: + global LOGGERS_LEVEL + LOGGERS_LEVEL = 'INFO' + argv.remove('--no-debug') if '--verbose' in argv: global LOGGERS_HANDLERS if 'console' not in LOGGERS_HANDLERS: diff --git a/lib/yunohost/service.py b/lib/yunohost/service.py index 86a95933d..a7946a16c 100644 --- a/lib/yunohost/service.py +++ b/lib/yunohost/service.py @@ -225,6 +225,13 @@ def service_status(names=[]): return result +def _get_log_file_list_in_dir(log_path): + return [ + f for f in os.listdir(log_path) + if os.path.isfile(os.path.join(log_path, f)) and f[-4:] == '.log' + ] + + def service_log(name, number=50): """ Log every log files of a service @@ -247,7 +254,7 @@ def service_log(name, number=50): for log_path in log_list: if os.path.isdir(log_path): - for log in [ f for f in os.listdir(log_path) if os.path.isfile(os.path.join(log_path, f)) and f[-4:] == '.log' ]: + for log in _get_log_file_list_in_dir(log_path): result[os.path.join(log_path, log)] = _tail(os.path.join(log_path, log), int(number)) else: result[log_path] = _tail(log_path, int(number))