From c3fc1255010f3d8b19ffd1d7d0abf428e99e48b1 Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Sun, 25 Feb 2024 16:02:01 +0100 Subject: [PATCH] Added command line option or overwriting limiter backend Added logger functions to remove newlines in messages CalibreTask has now a default name --- cps/__init__.py | 2 +- cps/cli.py | 3 +++ cps/logger.py | 13 +++++++++++++ cps/services/worker.py | 3 +++ cps/tasks/convert.py | 4 ++-- 5 files changed, 22 insertions(+), 3 deletions(-) diff --git a/cps/__init__.py b/cps/__init__.py index 536e1bb4..27b25e27 100755 --- a/cps/__init__.py +++ b/cps/__init__.py @@ -198,7 +198,7 @@ def create_app(): # Configure rate limiter # https://limits.readthedocs.io/en/stable/storage.html app.config.update(RATELIMIT_ENABLED=config.config_ratelimiter) - if config.config_limiter_uri != "": + if config.config_limiter_uri != "" and not cli_param.memory_backend: app.config.update(RATELIMIT_STORAGE_URI=config.config_limiter_uri) if config.config_limiter_options != "": app.config.update(RATELIMIT_STORAGE_OPTIONS=config.config_limiter_options) diff --git a/cps/cli.py b/cps/cli.py index 855ad899..64842259 100644 --- a/cps/cli.py +++ b/cps/cli.py @@ -52,6 +52,7 @@ class CliParameter(object): parser.add_argument('-v', '--version', action='version', help='Shows version number and exits Calibre-Web', version=version_info()) parser.add_argument('-i', metavar='ip-address', help='Server IP-Address to listen') + parser.add_argument('-m', action='store_true', help='Use Memory-backend as limiter backend, use this parameter in case of miss configured backend') parser.add_argument('-s', metavar='user:pass', help='Sets specific username to new password and exits Calibre-Web') parser.add_argument('-f', action='store_true', help='Flag is depreciated and will be removed in next version') @@ -98,6 +99,8 @@ class CliParameter(object): if args.k == "": self.keyfilepath = "" + # overwrite limiter backend + self.memory_backend = args.m or None # dry run updater self.dry_run = args.d or None # enable reconnect endpoint for docker database reconnect diff --git a/cps/logger.py b/cps/logger.py index 74f7fb39..5517dc0f 100644 --- a/cps/logger.py +++ b/cps/logger.py @@ -61,6 +61,19 @@ class _Logger(logging.Logger): else: self.debug(message, *args, **kwargs) + def warning(self, message, *args, **kwargs): + message = message.replace("\r", "").replace("\n", "") + list_args = list(args) + for index, arg in enumerate(list_args): + list_args[index] = arg.replace("\r", "").replace("\n", "") + args = tuple(list_args) + super().warning(message, *args, **kwargs) + + def debug(self, message, *args, **kwargs): + message = message.replace("\r", "").replace("\n", "") + super().debug(message, *args, **kwargs) + + def get(name=None): return logging.getLogger(name) diff --git a/cps/services/worker.py b/cps/services/worker.py index 63d83bfb..dce3da79 100644 --- a/cps/services/worker.py +++ b/cps/services/worker.py @@ -266,3 +266,6 @@ class CalibreTask: def _handleSuccess(self): self.stat = STAT_FINISH_SUCCESS self.progress = 1 + + def __str__(self): + return self.name diff --git a/cps/tasks/convert.py b/cps/tasks/convert.py index 7ea30396..3a121a2e 100644 --- a/cps/tasks/convert.py +++ b/cps/tasks/convert.py @@ -316,9 +316,9 @@ class TaskConvert(CalibreTask): def __str__(self): if self.ereader_mail: - return "Convert {} {}".format(self.book_id, self.ereader_mail) + return "Convert Book {} and mail it to {}".format(self.book_id, self.ereader_mail) else: - return "Convert {}".format(self.book_id) + return "Convert Book {}".format(self.book_id) @property def is_cancellable(self):