about page: build the versions dictionary only once

pull/961/head
Daniel Pavel 5 years ago
parent 63634961d4
commit a334ef28e7

@ -1,4 +1,3 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# This file is part of the Calibre-Web (https://github.com/janeczku/calibre-web) # This file is part of the Calibre-Web (https://github.com/janeczku/calibre-web)
@ -23,56 +22,46 @@
from __future__ import division, print_function, unicode_literals from __future__ import division, print_function, unicode_literals
import sys import sys
import requests import sqlite3
from collections import OrderedDict
from flask import Blueprint import babel, pytz, requests, sqlalchemy
from flask import __version__ as flaskVersion import werkzeug, flask, flask_login, flask_principal, jinja2
from flask_babel import gettext as _ from flask_babel import gettext as _
from flask_principal import __version__ as flask_principalVersion
from flask_login import login_required
try:
from flask_login import __version__ as flask_loginVersion
except ImportError:
from flask_login.__about__ import __version__ as flask_loginVersion
from werkzeug import __version__ as werkzeugVersion
from babel import __version__ as babelVersion from . import db, converter, uploader, server, isoLanguages
from jinja2 import __version__ as jinja2Version
from pytz import __version__ as pytzVersion
from sqlalchemy import __version__ as sqlalchemyVersion
from . import db, converter, uploader
from .isoLanguages import __version__ as iso639Version
from .server import VERSION as serverVersion
from .web import render_title_template from .web import render_title_template
about = Blueprint('about', __name__) about = flask.Blueprint('about', __name__)
_VERSIONS = OrderedDict(
Python=sys.version,
WebServer=server.VERSION,
Flask=flask.__version__,
Flask_Login=flask_login.__version__,
Flask_Principal=flask_principal.__version__,
Werkzeug=werkzeug.__version__,
Babel=babel.__version__,
Jinja2=jinja2.__version__,
Requests=requests.__version__,
SqlAlchemy=sqlalchemy.__version__,
pySqlite=sqlite3.version,
SQLite=sqlite3.sqlite_version,
iso639=isoLanguages.__version__,
pytz=pytz.__version__,
)
_VERSIONS.update(uploader.get_versions())
@about.route("/stats") @about.route("/stats")
@login_required @flask_login.login_required
def stats(): def stats():
counter = db.session.query(db.Books).count() counter = db.session.query(db.Books).count()
authors = db.session.query(db.Authors).count() authors = db.session.query(db.Authors).count()
categorys = db.session.query(db.Tags).count() categorys = db.session.query(db.Tags).count()
series = db.session.query(db.Series).count() series = db.session.query(db.Series).count()
versions = uploader.get_versions() _VERSIONS['ebook converter'] = _(converter.get_version())
versions['Babel'] = 'v' + babelVersion return render_title_template('stats.html', bookcounter=counter, authorcounter=authors, versions=_VERSIONS,
versions['Sqlalchemy'] = 'v' + sqlalchemyVersion
versions['Werkzeug'] = 'v' + werkzeugVersion
versions['Jinja2'] = 'v' + jinja2Version
versions['Flask'] = 'v' + flaskVersion
versions['Flask Login'] = 'v' + flask_loginVersion
versions['Flask Principal'] = 'v' + flask_principalVersion
versions['Iso 639'] = 'v' + iso639Version
versions['pytz'] = 'v' + pytzVersion
versions['Requests'] = 'v' + requests.__version__
versions['pySqlite'] = 'v' + db.session.bind.dialect.dbapi.version
versions['Sqlite'] = 'v' + db.session.bind.dialect.dbapi.sqlite_version
versions.update(converter.versioncheck())
versions.update(serverVersion)
versions['Python'] = sys.version
return render_title_template('stats.html', bookcounter=counter, authorcounter=authors, versions=versions,
categorycounter=categorys, seriecounter=series, title=_(u"Statistics"), page="stat") categorycounter=categorys, seriecounter=series, title=_(u"Statistics"), page="stat")

@ -1,4 +1,3 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# This file is part of the Calibre-Web (https://github.com/janeczku/calibre-web) # This file is part of the Calibre-Web (https://github.com/janeczku/calibre-web)
@ -21,41 +20,36 @@ from __future__ import division, print_function, unicode_literals
import os import os
import re import re
from flask_babel import gettext as _ from . import config, logger
from . import config
from .subproc_wrapper import process_wait from .subproc_wrapper import process_wait
def versionKindle(): log = logger.create()
versions = _(u'not installed')
if os.path.exists(config.config_converterpath):
try:
for lines in process_wait(config.config_converterpath):
if re.search('Amazon kindlegen\(', lines):
versions = lines
except Exception:
versions = _(u'Excecution permissions missing')
return {'kindlegen' : versions}
_NOT_CONFIGURED = 'not configured'
_NOT_INSTALLED = 'not installed'
_EXECUTION_ERROR = 'Execution permissions missing'
def versionCalibre():
versions = _(u'not installed') def _get_command_version(path, pattern, argument=None):
if os.path.exists(config.config_converterpath): if os.path.exists(path):
command = [path]
if argument:
command.append(argument)
try: try:
for lines in process_wait([config.config_converterpath, '--version']): for line in process_wait(command):
if re.search('ebook-convert.*\(calibre', lines): if re.search(pattern, line):
versions = lines return line
except Exception: except Exception as ex:
versions = _(u'Excecution permissions missing') log.warning("%s: %s", path, ex)
return {'Calibre converter' : versions} return _EXECUTION_ERROR
return _NOT_INSTALLED
def versioncheck(): def get_version():
version = None
if config.config_ebookconverter == 1: if config.config_ebookconverter == 1:
return versionKindle() version = _get_command_version(config.config_converterpath, r'Amazon kindlegen\(')
elif config.config_ebookconverter == 2: elif config.config_ebookconverter == 2:
return versionCalibre() version = _get_command_version(config.config_converterpath, r'ebook-convert.*\(calibre', '--version')
else: return version or _NOT_CONFIGURED
return {'ebook_converter':_(u'not configured')}

@ -1,4 +1,3 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# This file is part of the Calibre-Web (https://github.com/janeczku/calibre-web) # This file is part of the Calibre-Web (https://github.com/janeczku/calibre-web)
@ -28,14 +27,14 @@ try:
from gevent.pywsgi import WSGIServer from gevent.pywsgi import WSGIServer
from gevent.pool import Pool from gevent.pool import Pool
from gevent import __version__ as _version from gevent import __version__ as _version
VERSION = {'Gevent': 'v' + _version} VERSION = 'Gevent ' + _version
_GEVENT = True _GEVENT = True
except ImportError: except ImportError:
from tornado.wsgi import WSGIContainer from tornado.wsgi import WSGIContainer
from tornado.httpserver import HTTPServer from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop from tornado.ioloop import IOLoop
from tornado import version as _version from tornado import version as _version
VERSION = {'Tornado': 'v' + _version} VERSION = 'Tornado ' + _version
_GEVENT = False _GEVENT = False
from . import logger from . import logger

Loading…
Cancel
Save