From 095a51edd0a0baa741b908328590c70f7f284c39 Mon Sep 17 00:00:00 2001 From: Ozzieisaacs Date: Mon, 15 Feb 2021 13:33:42 +0100 Subject: [PATCH 1/3] Convert tabs to spaces in server.py (related to #1862) --- cps/server.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cps/server.py b/cps/server.py index 3148aed6..9358c2d5 100644 --- a/cps/server.py +++ b/cps/server.py @@ -153,10 +153,10 @@ class WebServer(object): # not exist if a setuptools script is installed as an egg. It may be # set incorrectly for entry points created with pip on Windows. if getattr(__main__, "__package__", None) is None or ( - os.name == "nt" - and __main__.__package__ == "" - and not os.path.exists(py_script) - and os.path.exists(f"{py_script}.exe") + os.name == "nt" + and __main__.__package__ == "" + and not os.path.exists(py_script) + and os.path.exists(f"{py_script}.exe") ): # Executed a file, like "python app.py". py_script = os.path.abspath(py_script) From 4aa1a838ed9d8d82c21e18b59af6ca1a8ea74fcb Mon Sep 17 00:00:00 2001 From: Ozzieisaacs Date: Mon, 15 Feb 2021 14:17:05 +0100 Subject: [PATCH 2/3] Removed f-strings, making it compatible with python 3.5 --- cps/server.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cps/server.py b/cps/server.py index 9358c2d5..bf564108 100644 --- a/cps/server.py +++ b/cps/server.py @@ -156,7 +156,7 @@ class WebServer(object): os.name == "nt" and __main__.__package__ == "" and not os.path.exists(py_script) - and os.path.exists(f"{py_script}.exe") + and os.path.exists("{}.exe".format(py_script)) ): # Executed a file, like "python app.py". py_script = os.path.abspath(py_script) @@ -164,7 +164,7 @@ class WebServer(object): if os.name == "nt": # Windows entry points have ".exe" extension and should be # called directly. - if not os.path.exists(py_script) and os.path.exists(f"{py_script}.exe"): + if not os.path.exists(py_script) and os.path.exists("{}.exe".format(py_script)): py_script += ".exe" if ( @@ -185,7 +185,7 @@ class WebServer(object): name = os.path.splitext(os.path.basename(py_script))[0] if name != "__main__": - py_module += f".{name}" + py_module += ".{}".format(name) else: # Incorrectly rewritten by pydevd debugger from "-m script" to "script". py_module = py_script From bc876a159e571b0337c3a327648a5aa097e80dc9 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Thu, 18 Feb 2021 15:51:14 +0100 Subject: [PATCH 3/3] Declare variables before using them It should fix the following stacktrace: ``` [2021-02-18 14:46:14,771] ERROR {cps:1891} Exception on / [GET] Traceback (most recent call last): File "/opt/calibre/vendor/flask/app.py", line 2447, in wsgi_app response = self.full_dispatch_request() File "/opt/calibre/vendor/flask/app.py", line 1952, in full_dispatch_request rv = self.handle_user_exception(e) File "/opt/calibre/vendor/flask/app.py", line 1821, in handle_user_exception reraise(exc_type, exc_value, tb) File "/opt/calibre/vendor/flask/_compat.py", line 39, in reraise raise value File "/opt/calibre/vendor/flask/app.py", line 1950, in full_dispatch_request rv = self.dispatch_request() File "/opt/calibre/vendor/flask/app.py", line 1936, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) File "/opt/calibre/cps/usermanagement.py", line 38, in decorated_view return login_required(func)(*args, **kwargs) File "/opt/calibre/vendor/flask_login/utils.py", line 272, in decorated_view return func(*args, **kwargs) File "/opt/calibre/cps/web.py", line 719, in index return render_books_list("newest", sort_param, 1, page) File "/opt/calibre/cps/web.py", line 422, in render_books_list entries, random, pagination = calibre_db.fill_indexpage(page, 0, db.Books, True, order) File "/opt/calibre/cps/db.py", line 610, in fill_indexpage return self.fill_indexpage_with_archived_books(page, pagesize, database, db_filter, order, False, *join) File "/opt/calibre/cps/db.py", line 635, in fill_indexpage_with_archived_books # book = self.order_authors(book) UnboundLocalError: local variable 'entries' referenced before assignment ``` --- cps/db.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cps/db.py b/cps/db.py index c08a3ea4..2bc0fc51 100644 --- a/cps/db.py +++ b/cps/db.py @@ -624,6 +624,8 @@ class CalibreDB(): .join(*join, isouter=True) \ .filter(db_filter) \ .filter(self.common_filters(allow_show_archived)) + entries = list() + pagination = list() try: pagination = Pagination(page, pagesize, len(query.all()))