From 86fe970651e4ae15c818d7fc4e21e2cf9d762537 Mon Sep 17 00:00:00 2001 From: Ozzieisaacs Date: Sat, 14 Dec 2019 22:22:27 +0100 Subject: [PATCH] More fixes for googledrive --- cps/admin.py | 7 ++++++- cps/gdrive.py | 6 +++++- cps/gdriveutils.py | 4 ++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/cps/admin.py b/cps/admin.py index 1862dda8..3c64b01b 100644 --- a/cps/admin.py +++ b/cps/admin.py @@ -170,6 +170,9 @@ def update_view_configuration(): _config_int("config_books_per_page") _config_int("config_authors_max") + if config.config_google_drive_watch_changes_response: + config.config_google_drive_watch_changes_response = json.dumps(config.config_google_drive_watch_changes_response) + config.config_default_role = constants.selected_roles(to_save) config.config_default_role &= ~constants.ROLE_ANONYMOUS @@ -258,6 +261,7 @@ def _configuration_update_helper(): db_change = False to_save = request.form.to_dict() + # _config_dict = lambda x: config.set_from_dictionary(to_save, x, lambda y: y['id']) _config_string = lambda x: config.set_from_dictionary(to_save, x, lambda y: y.strip() if y else y) _config_int = lambda x: config.set_from_dictionary(to_save, x, int) _config_checkbox = lambda x: config.set_from_dictionary(to_save, x, lambda y: y == "on", False) @@ -415,7 +419,8 @@ def _configuration_result(error_flash=None, gdriveError=None): if gdriveError: gdriveError = _(gdriveError) else: - if config.config_use_google_drive and not gdrive_authenticate: + # if config.config_use_google_drive and\ + if not gdrive_authenticate: gdrivefolders = gdriveutils.listRootFolders() show_back_button = current_user.is_authenticated diff --git a/cps/gdrive.py b/cps/gdrive.py index 263c829b..a95060b0 100644 --- a/cps/gdrive.py +++ b/cps/gdrive.py @@ -23,6 +23,7 @@ from __future__ import division, print_function, unicode_literals import os +import sys import hashlib import json import tempfile @@ -141,7 +142,10 @@ def on_received_watch_confirmation(): response = gdriveutils.getChangeById(gdriveutils.Gdrive.Instance().drive, j['id']) log.debug('%r', response) if response: - dbpath = os.path.join(config.config_calibre_dir, "metadata.db") + if sys.version_info < (3, 0): + dbpath = os.path.join(config.config_calibre_dir, "metadata.db") + else: + dbpath = os.path.join(config.config_calibre_dir, "metadata.db").encode() if not response['deleted'] and response['file']['title'] == 'metadata.db' and response['file']['md5Checksum'] != hashlib.md5(dbpath): tmpDir = tempfile.gettempdir() log.info('Database file updated') diff --git a/cps/gdriveutils.py b/cps/gdriveutils.py index d950f738..f70747a6 100644 --- a/cps/gdriveutils.py +++ b/cps/gdriveutils.py @@ -47,6 +47,10 @@ CREDENTIALS = os.path.join(_CONFIG_DIR, 'gdrive_credentials') CLIENT_SECRETS = os.path.join(_CONFIG_DIR, 'client_secrets.json') log = logger.create() +if gdrive_support: + logger.get('googleapiclient.discovery_cache').setLevel(logger.logging.ERROR) + if not logger.is_debug_enabled(): + logger.get('googleapiclient.discovery').setLevel(logger.logging.ERROR) class Singleton: