Check versions of dependencies at startup and generate logfile output if not fitting (#2157)
This commit is contained in:
parent
42cc13d1e2
commit
17470b3b56
|
@ -35,6 +35,7 @@ from flask_principal import Principal
|
|||
from . import config_sql, logger, cache_buster, cli, ub, db
|
||||
from .reverseproxy import ReverseProxied
|
||||
from .server import WebServer
|
||||
from .dep_check import dependency_check
|
||||
|
||||
try:
|
||||
import lxml
|
||||
|
@ -100,6 +101,7 @@ _BABEL_TRANSLATIONS = set()
|
|||
|
||||
log = logger.create()
|
||||
|
||||
|
||||
from . import services
|
||||
|
||||
db.CalibreDB.update_config(config)
|
||||
|
@ -126,7 +128,11 @@ def create_app():
|
|||
print('*** "flask-WTF" is needed for calibre-web to run. Please install it using pip: "pip install flask-WTF" ***')
|
||||
web_server.stop(True)
|
||||
sys.exit(7)
|
||||
|
||||
for res in dependency_check() + dependency_check(True):
|
||||
log.info('*** "{}" version does not fit the requirements. Should: {}, Found: {}, please consider updating. ***'
|
||||
.format(res['name'],
|
||||
res['target'],
|
||||
res['found']))
|
||||
app.wsgi_app = ReverseProxied(app.wsgi_app)
|
||||
|
||||
if os.environ.get('FLASK_DEBUG'):
|
||||
|
|
83
cps/dep_check.py
Normal file
83
cps/dep_check.py
Normal file
|
@ -0,0 +1,83 @@
|
|||
import os
|
||||
import re
|
||||
|
||||
from .constants import BASE_DIR
|
||||
try:
|
||||
from importlib_metadata import version
|
||||
importlib = True
|
||||
ImportNotFound = BaseException
|
||||
except ImportError:
|
||||
importlib = False
|
||||
|
||||
|
||||
if not importlib:
|
||||
try:
|
||||
import pkg_resources
|
||||
from pkg_resources import DistributionNotFound as ImportNotFound
|
||||
pkgresources = True
|
||||
except ImportError as e:
|
||||
pkgresources = False
|
||||
|
||||
def dependency_check(optional=False):
|
||||
dep = list()
|
||||
if importlib or pkgresources:
|
||||
if optional:
|
||||
req_path = os.path.join(BASE_DIR, "optional-requirements.txt")
|
||||
else:
|
||||
req_path = os.path.join(BASE_DIR, "requirements.txt")
|
||||
if os.path.exists(req_path):
|
||||
try:
|
||||
with open(req_path, 'r') as f:
|
||||
for line in f:
|
||||
if not line.startswith('#') and not line == '\n' and not line.startswith('git'):
|
||||
res = re.match(r'(.*?)([<=>\s]+)([\d\.]+),?\s?([<=>\s]+)?([\d\.]+)?', line.strip())
|
||||
try:
|
||||
if importlib:
|
||||
dep_version = version(res.group(1))
|
||||
else:
|
||||
dep_version = pkg_resources.get_distribution(res.group(1)).version
|
||||
except ImportNotFound:
|
||||
if optional:
|
||||
continue
|
||||
else:
|
||||
return [{'name':res.group(1),
|
||||
'target': "available",
|
||||
'found': "Not available"
|
||||
}]
|
||||
|
||||
if res.group(2).strip() == "==":
|
||||
if dep_version.split('.') != res.group(3).split('.'):
|
||||
dep.append({'name': res.group(1),
|
||||
'found': dep_version,
|
||||
"target": res.group(2) + res.group(3)})
|
||||
continue
|
||||
elif res.group(2).strip() == ">=":
|
||||
if dep_version.split('.') < res.group(3).split('.'):
|
||||
dep.append({'name': res.group(1),
|
||||
'found': dep_version,
|
||||
"target": res.group(2) + res.group(3)})
|
||||
continue
|
||||
elif res.group(2).strip() == ">":
|
||||
if dep_version.split('.') <= res.group(3).split('.'):
|
||||
dep.append({'name': res.group(1),
|
||||
'found': dep_version,
|
||||
"target": res.group(2) + res.group(3)})
|
||||
continue
|
||||
if res.group(4) and res.group(5):
|
||||
if res.group(4).strip() == "<":
|
||||
if dep_version.split('.') >= res.group(5).split('.'):
|
||||
dep.append(
|
||||
{'name': res.group(1),
|
||||
'found': dep_version,
|
||||
"target": res.group(4) + res.group(5)})
|
||||
continue
|
||||
elif res.group(2).strip() == "<=":
|
||||
if dep_version.split('.') > res.group(5).split('.'):
|
||||
dep.append(
|
||||
{'name': res.group(1),
|
||||
'found': dep_version,
|
||||
"target": res.group(4) + res.group(5)})
|
||||
continue
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return dep
|
|
@ -34,8 +34,8 @@ rarfile>=2.7
|
|||
scholarly>=1.2.0, <1.3
|
||||
|
||||
# other
|
||||
natsort>=2.2.0,<7.2.0
|
||||
comicapi>= 2.2.0,<2.3.0
|
||||
natsort>=2.2.0,<8.1.0
|
||||
comicapi>=2.2.0,<2.3.0
|
||||
|
||||
#Kobo integration
|
||||
jsonschema>=3.2.0,<3.3.0
|
||||
|
|
Loading…
Reference in New Issue
Block a user