Merge branch 'Develop' - Improved compability for python 3.12+

This commit is contained in:
Ozzie Isaacs
2024-11-02 16:59:19 +01:00
16 changed files with 391 additions and 251 deletions
+1 -2
View File
@@ -31,12 +31,10 @@ from flask_principal import Principal
from . import logger
from .cli import CliParameter
from .constants import CONFIG_DIR
from .reverseproxy import ReverseProxied
from .server import WebServer
from .dep_check import dependency_check
from .updater import Updater
from .babel import babel, get_locale
from . import config_sql
from . import cache_buster
from . import ub, db
@@ -183,6 +181,7 @@ def create_app():
app.secret_key = os.getenv('SECRET_KEY', config_sql.get_flask_session_key(ub.session))
web_server.init_app(app, config)
from .cw_babel import babel, get_locale
if hasattr(babel, "localeselector"):
babel.init_app(app)
babel.localeselector(get_locale)
+3 -5
View File
@@ -42,19 +42,17 @@ opt = dep_check.load_dependencies(True)
for i in (req + opt):
modules[i[1]] = i[0]
modules['Jinja2'] = importlib.metadata.version("jinja2")
try:
if sys.version_info < (3, 12):
modules['pySqlite'] = sqlite3.version
except Exception:
pass
modules['SQLite'] = sqlite3.sqlite_version
sorted_modules = OrderedDict((sorted(modules.items(), key=lambda x: x[0].casefold())))
def collect_stats():
if constants.NIGHTLY_VERSION[0] == "$Format:%H$":
calibre_web_version = constants.STABLE_VERSION['version'].replace("b", " Beta")
calibre_web_version = constants.STABLE_VERSION.replace("b", " Beta")
else:
calibre_web_version = (constants.STABLE_VERSION['version'].replace("b", " Beta") + ' - '
calibre_web_version = (constants.STABLE_VERSION.replace("b", " Beta") + ' - '
+ constants.NIGHTLY_VERSION[0].replace('%', '%%') + ' - '
+ constants.NIGHTLY_VERSION[1].replace('%', '%%'))
+2 -2
View File
@@ -52,7 +52,7 @@ from .gdriveutils import is_gdrive_ready, gdrive_support
from .render_template import render_title_template, get_sidebar_config
from .services.worker import WorkerThread
from .usermanagement import user_login_required
from .babel import get_available_translations, get_available_locale, get_user_locale_language
from .cw_babel import get_available_translations, get_available_locale, get_user_locale_language
from . import debug_info
from .string_helper import strip_whitespaces
@@ -219,7 +219,7 @@ def admin():
form_date += timedelta(hours=int(commit[20:22]), minutes=int(commit[23:]))
commit = format_datetime(form_date - tz, format='short')
else:
commit = version['version'].replace("b", " Beta")
commit = version.replace("b", " Beta")
all_user = ub.session.query(ub.User).all()
# email_settings = mail_config.get_mail_settings()
+2 -2
View File
@@ -29,8 +29,8 @@ from .constants import DEFAULT_SETTINGS_FILE, DEFAULT_GDRIVE_FILE
def version_info():
if _NIGHTLY_VERSION[1].startswith('$Format'):
return "Calibre-Web version: %s - unknown git-clone" % _STABLE_VERSION['version'].replace("b", " Beta")
return "Calibre-Web version: %s -%s" % (_STABLE_VERSION['version'].replace("b", " Beta"), _NIGHTLY_VERSION[1])
return "Calibre-Web version: %s - unknown git-clone" % _STABLE_VERSION.replace("b", " Beta")
return "Calibre-Web version: %s -%s" % (_STABLE_VERSION.replace("b", " Beta"), _NIGHTLY_VERSION[1])
class CliParameter(object):
+2 -4
View File
@@ -19,9 +19,6 @@
import sys
import os
from collections import namedtuple
from sqlalchemy import __version__ as sql_version
sqlalchemy_version2 = ([int(x) for x in sql_version.split('.')] >= [2, 0, 0])
# APP_MODE - production, development, or test
APP_MODE = os.environ.get('APP_MODE', 'production')
@@ -175,7 +172,8 @@ BookMeta = namedtuple('BookMeta', 'file_path, extension, title, author, cover, d
'series_id, languages, publisher, pubdate, identifiers')
# python build process likes to have x.y.zbw -> b for beta and w a counting number
STABLE_VERSION = {'version': '0.6.24b'}
STABLE_VERSION = '0.6.24b'
# _version = STABLE_VERSION['version']
NIGHTLY_VERSION = dict()
NIGHTLY_VERSION[0] = '$Format:%H$'
View File
+1 -1
View File
@@ -63,7 +63,7 @@ def dependency_check(optional=False):
deps = load_dependencies(optional)
for dep in deps:
try:
dep_version_int = [int(x) if x.isnumeric() else 0 for x in dep[0].split('.')]
dep_version_int = [int(x) if x.isnumeric() else 0 for x in dep[0].split('.')[:3]]
low_check = [int(x) for x in dep[3].split('.')]
high_check = [int(x) for x in dep[5].split('.')]
except AttributeError:
+6 -14
View File
@@ -25,20 +25,7 @@ log = logger.create()
try:
from iso639 import languages
# iso_version = importlib.metadata.version("iso639")
get = languages.get
try:
if sys.version_info >= (3, 12):
import pkg_resources
except ImportError:
print("Python 3.12 isn't compatible with iso-639. Please install pycountry.")
except ImportError as ex:
from pycountry import languages as pyc_languages
#try:
# iso_version = importlib.metadata.version("pycountry") + ' (PyCountry)'
#except (ImportError, Exception):
# iso_version = "?" + ' (PyCountry)'
def _copy_fields(l):
l.part1 = getattr(l, 'alpha_2', None)
@@ -52,6 +39,11 @@ except ImportError as ex:
return _copy_fields(pyc_languages.get(alpha_2=part1))
if name is not None:
return _copy_fields(pyc_languages.get(name=name))
except ImportError as ex:
if sys.version_info >= (3, 12):
print("Python 3.12 isn't compatible with iso-639. Please install pycountry.")
from iso639 import languages
get = languages.get
def get_language_names(locale):
@@ -109,6 +101,6 @@ def get_lang3(lang):
ret_value = lang
else:
ret_value = ""
except KeyError:
except (KeyError, AttributeError):
ret_value = lang
return ret_value
+1
View File
@@ -42,6 +42,7 @@ class BackgroundScheduler:
if cls._instance is None:
cls._instance = super(BackgroundScheduler, cls).__new__(cls)
cls.log = logger.create()
logger.logging.getLogger('tzlocal').setLevel(logger.logging.WARNING)
cls.scheduler = BScheduler()
cls.scheduler.start()
+1 -1
View File
@@ -614,7 +614,7 @@ class Updater(threading.Thread):
if version is False:
status['current_commit_hash'] = _(u'Unknown')
else:
status['current_commit_hash'] = version['version']
status['current_commit_hash'] = version
try:
headers = {'Accept': 'application/vnd.github.v3+json'}
r = requests.get(repository_url, headers=headers, timeout=10)
+7 -3
View File
@@ -23,6 +23,7 @@ import json
import mimetypes
import chardet # dependency of requests
import copy
import importlib
from flask import Blueprint, jsonify
from flask import request, redirect, send_from_directory, make_response, flash, abort, url_for, Response
@@ -36,7 +37,6 @@ from sqlalchemy.exc import IntegrityError, InvalidRequestError, OperationalError
from sqlalchemy.sql.expression import text, func, false, not_, and_, or_
from sqlalchemy.orm.attributes import flag_modified
from sqlalchemy.sql.functions import coalesce
from werkzeug.datastructures import Headers
from werkzeug.security import generate_password_hash, check_password_hash
@@ -51,7 +51,7 @@ from .helper import check_valid_domain, check_email, check_username, \
edit_book_read_status, valid_password
from .pagination import Pagination
from .redirect import get_redirect_location
from .babel import get_available_locale
from .cw_babel import get_available_locale
from .usermanagement import login_required_if_no_ano
from .kobo_sync_status import remove_synced_book
from .render_template import render_title_template
@@ -86,6 +86,10 @@ except ImportError:
sort = sorted # Just use regular sort then, may cause issues with badly named pages in cbz/cbr files
sql_version = importlib.metadata.version("sqlalchemy")
sqlalchemy_version2 = ([int(x) for x in sql_version.split('.')] >= [2, 0, 0])
@app.after_request
def add_security_headers(resp):
default_src = ([host.strip() for host in config.config_trustedhosts.split(',') if host] +
@@ -532,7 +536,7 @@ def render_author_books(page, author_id, order):
flash(_("Oops! Selected book is unavailable. File does not exist or is not accessible"),
category="error")
return redirect(url_for("web.index"))
if constants.sqlalchemy_version2:
if sqlalchemy_version2:
author = calibre_db.session.get(db.Authors, author_id)
else:
author = calibre_db.session.query(db.Authors).get(author_id)