From 8bfcdffeb62276ff7162bcab778d11417ade6bde Mon Sep 17 00:00:00 2001 From: Ozzieisaacs Date: Sun, 14 Jul 2019 13:20:40 +0200 Subject: [PATCH] Fix feature support --- cps/__init__.py | 1 + cps/config_sql.py | 41 +++++++++++++++++++++++++--------- cps/gdriveutils.py | 8 ++++--- cps/services/simpleldap.py | 2 -- cps/templates/config_edit.html | 2 ++ optional-requirements.txt | 2 +- 6 files changed, 40 insertions(+), 16 deletions(-) diff --git a/cps/__init__.py b/cps/__init__.py index 5808f8ae..fa389a85 100755 --- a/cps/__init__.py +++ b/cps/__init__.py @@ -68,6 +68,7 @@ config = config_sql.load_configuration(ub.session) from . import db, services searched_ids = {} +feature_support = [] from .worker import WorkerThread global_WorkerThread = WorkerThread() diff --git a/cps/config_sql.py b/cps/config_sql.py index 37ea77e5..5a9aa412 100644 --- a/cps/config_sql.py +++ b/cps/config_sql.py @@ -20,6 +20,7 @@ from __future__ import division, print_function, unicode_literals import os import json +import sys from sqlalchemy import exc, Column, String, Integer, SmallInteger, Boolean from sqlalchemy.ext.declarative import declarative_base @@ -43,41 +44,52 @@ class _Settings(_Base): mail_login = Column(String, default='mail@example.com') mail_password = Column(String, default='mypassword') mail_from = Column(String, default='automailer ') + config_calibre_dir = Column(String) config_port = Column(Integer, default=constants.DEFAULT_PORT) config_certfile = Column(String) config_keyfile = Column(String) + config_calibre_web_title = Column(String, default=u'Calibre-Web') config_books_per_page = Column(Integer, default=60) config_random_books = Column(Integer, default=4) config_authors_max = Column(Integer, default=0) config_read_column = Column(Integer, default=0) config_title_regex = Column(String, default=u'^(A|The|An|Der|Die|Das|Den|Ein|Eine|Einen|Dem|Des|Einem|Eines)\s+') + config_mature_content_tags = Column(String, default='') + config_theme = Column(Integer, default=0) + config_log_level = Column(SmallInteger, default=logger.DEFAULT_LOG_LEVEL) + config_logfile = Column(String) config_access_log = Column(SmallInteger, default=0) + config_access_logfile = Column(String) + config_uploading = Column(SmallInteger, default=0) config_anonbrowse = Column(SmallInteger, default=0) config_public_reg = Column(SmallInteger, default=0) + config_remote_login = Column(Boolean, default=False) + + config_default_role = Column(SmallInteger, default=0) config_default_show = Column(SmallInteger, default=6143) config_columns_to_ignore = Column(String) + config_use_google_drive = Column(Boolean, default=False) config_google_drive_folder = Column(String) config_google_drive_watch_changes_response = Column(String) - config_remote_login = Column(Boolean, default=False) + config_use_goodreads = Column(Boolean, default=False) config_goodreads_api_key = Column(String) config_goodreads_api_secret = Column(String) + config_login_type = Column(Integer, default=0) - # config_use_ldap = Column(Boolean) - config_ldap_provider_url = Column(String) - config_ldap_dn = Column(String) - # config_use_github_oauth = Column(Boolean) + + config_oauth_provider = Column(Boolean) config_github_oauth_client_id = Column(String) config_github_oauth_client_secret = Column(String) - # config_use_google_oauth = Column(Boolean) config_google_oauth_client_id = Column(String) config_google_oauth_client_secret = Column(String) + config_ldap_provider_url = Column(String, default='localhost') config_ldap_port = Column(SmallInteger, default=389) config_ldap_schema = Column(String, default='ldap') @@ -90,14 +102,12 @@ class _Settings(_Base): config_ldap_dn = Column(String) config_ldap_user_object = Column(String) config_ldap_openldap = Column(Boolean, default=False) - config_mature_content_tags = Column(String, default='') - config_logfile = Column(String) - config_access_logfile = Column(String) + config_ebookconverter = Column(Integer, default=0) config_converterpath = Column(String) config_calibre = Column(String) config_rarfile_location = Column(String) - config_theme = Column(Integer, default=0) + config_updatechannel = Column(Integer, default=constants.UPDATE_STABLE) def __repr__(self): @@ -270,6 +280,17 @@ def _migrate_table(session, orm_class): if changed: session.commit() +def autodetect_calibre_binary(): + if sys.platform == "win32": + calibre_path = ["C:\\program files\calibre\calibre-convert.exe", + "C:\\program files(x86)\calibre\calibre-convert.exe"] + else: + calibre_path = ["/opt/calibre/ebook-convert"] + for element in calibre_path: + if os.path.isfile(element) and os.access(element, os.X_OK): + return element + return None + def _migrate_database(session): # make sure the table is created, if it does not exist diff --git a/cps/gdriveutils.py b/cps/gdriveutils.py index 4ebbb0c7..6b25959e 100644 --- a/cps/gdriveutils.py +++ b/cps/gdriveutils.py @@ -34,9 +34,11 @@ try: from pydrive.drive import GoogleDrive from pydrive.auth import RefreshError from apiclient import errors - gdrive_support = True + feature_support['gdrive'] = True + # gdrive_support = True except ImportError: - gdrive_support = False + feature_support['gdrive'] = True + #gdrive_support = False from . import logger, cli, config from .constants import CONFIG_DIR as _CONFIG_DIR @@ -574,7 +576,7 @@ def update_settings(client_id, client_secret, redirect_uri): def get_error_text(client_secrets=None): - if not gdrive_support: + if not feature_support['gdrive']: return 'Import of optional Google Drive requirements missing' if not os.path.isfile(CLIENT_SECRETS): diff --git a/cps/services/simpleldap.py b/cps/services/simpleldap.py index f9d0dfff..8dd082b5 100644 --- a/cps/services/simpleldap.py +++ b/cps/services/simpleldap.py @@ -50,8 +50,6 @@ def init_app(app, config): app.config['LDAP_USE_TLS'] = bool(config.config_ldap_use_tls) app.config['LDAP_OPENLDAP'] = bool(config.config_ldap_openldap) - # app.config['LDAP_BASE_DN'] = 'ou=users,dc=yunohost,dc=org' - # app.config['LDAP_USER_OBJECT_FILTER'] = '(uid=%s)' _ldap.init_app(app) diff --git a/cps/templates/config_edit.html b/cps/templates/config_edit.html index de4063c9..0c452bbd 100644 --- a/cps/templates/config_edit.html +++ b/cps/templates/config_edit.html @@ -19,6 +19,7 @@ + {% if feature_support['gdrive'] %}
@@ -66,6 +67,7 @@ {% endif %} {% endif %}
+ {% endif %} diff --git a/optional-requirements.txt b/optional-requirements.txt index d573c299..ed653020 100644 --- a/optional-requirements.txt +++ b/optional-requirements.txt @@ -18,7 +18,7 @@ python-Levenshtein>=0.12.0 # ldap login python_ldap>=3.0.0 -flask-simpleldap +flask-simpleldap>=1.2.0 # extracting metadata lxml>=3.8.0