Update Gdrive integration (Error Handling on Callback and wording)

pull/1540/head
Ozzie Isaacs 4 years ago
parent 93a0217d5f
commit 66acd1821d

@ -34,18 +34,17 @@ from flask import Blueprint, flash, request, redirect, url_for, abort
from flask_babel import gettext as _
from flask_login import login_required
try:
from googleapiclient.errors import HttpError
except ImportError:
pass
from . import logger, gdriveutils, config, ub, calibre_db
from .web import admin_required
gdrive = Blueprint('gdrive', __name__)
log = logger.create()
try:
from googleapiclient.errors import HttpError
except ImportError as err:
log.debug(("Cannot import googleapiclient, using gdrive will not work: %s", err))
current_milli_time = lambda: int(round(time() * 1000))
gdrive_watch_callback_token = 'target=calibreweb-watch_files'
@ -73,7 +72,7 @@ def google_drive_callback():
credentials = gdriveutils.Gauth.Instance().auth.flow.step2_exchange(auth_code)
with open(gdriveutils.CREDENTIALS, 'w') as f:
f.write(credentials.to_json())
except ValueError as error:
except (ValueError, AttributeError) as error:
log.error(error)
return redirect(url_for('admin.configuration'))
@ -94,7 +93,7 @@ def watch_gdrive():
try:
result = gdriveutils.watchChange(gdriveutils.Gdrive.Instance().drive, notification_id,
'web_hook', address, gdrive_watch_callback_token, current_milli_time() + 604800*1000)
config.config_google_drive_watch_changes_response = json.dumps(result)
# config.config_google_drive_watch_changes_response = json.dumps(result)
# after save(), config_google_drive_watch_changes_response will be a json object, not string
config.save()
except HttpError as e:
@ -118,7 +117,7 @@ def revoke_watch_gdrive():
last_watch_response['resourceId'])
except HttpError:
pass
config.config_google_drive_watch_changes_response = None
config.config_google_drive_watch_changes_response = {}
config.save()
return redirect(url_for('admin.configuration'))

@ -36,7 +36,9 @@ try:
from apiclient import errors
from httplib2 import ServerNotFoundError
gdrive_support = True
except ImportError:
importError = None
except ImportError as err:
importError = err
gdrive_support = False
from . import logger, cli, config
@ -52,6 +54,8 @@ 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)
else:
log.debug("Cannot import pydrive,httplib2, using gdrive will not work: %s", importError)
class Singleton:
@ -99,7 +103,11 @@ class Singleton:
@Singleton
class Gauth:
def __init__(self):
self.auth = GoogleAuth(settings_file=SETTINGS_YAML)
try:
self.auth = GoogleAuth(settings_file=SETTINGS_YAML)
except NameError as error:
log.error(error)
self.auth = None
@Singleton

@ -41,7 +41,7 @@
</div>
{% else %}
{% if show_authenticate_google_drive and g.user.is_authenticated and not config.config_use_google_drive %}
<div >{{_('Please hit submit to continue with setup')}}</div>
<div >{{_('Please hit save to continue with setup')}}</div>
{% endif %}
{% if not g.user.is_authenticated %}
<div >{{_('Please finish Google Drive setup after login')}}</div>

@ -1556,7 +1556,7 @@ msgid "Authenticate Google Drive"
msgstr "Ověřit Google Drive"
#: cps/templates/config_edit.html:44
msgid "Please hit submit to continue with setup"
msgid "Please hit save to continue with setup"
msgstr "Klikněte na odeslat pro pokračování v nastavení"
#: cps/templates/config_edit.html:47

@ -1557,7 +1557,7 @@ msgid "Authenticate Google Drive"
msgstr "Google Drive authentifizieren"
#: cps/templates/config_edit.html:44
msgid "Please hit submit to continue with setup"
msgid "Please hit save to continue with setup"
msgstr "Bitte auf Abschicken drücken, um mit dem Setup fortzufahren"
#: cps/templates/config_edit.html:47

@ -1560,7 +1560,7 @@ msgid "Authenticate Google Drive"
msgstr "Autentificar Google Drive"
#: cps/templates/config_edit.html:44
msgid "Please hit submit to continue with setup"
msgid "Please hit save to continue with setup"
msgstr "Por favor, pulsa enviar para continuar con la configuración"
#: cps/templates/config_edit.html:47

@ -1557,7 +1557,7 @@ msgid "Authenticate Google Drive"
msgstr "Autentikoi Google Drive"
#: cps/templates/config_edit.html:44
msgid "Please hit submit to continue with setup"
msgid "Please hit save to continue with setup"
msgstr "Ole hyvä ja paina lähetä jatkaaksesi asennusta"
#: cps/templates/config_edit.html:47

@ -1571,7 +1571,7 @@ msgid "Authenticate Google Drive"
msgstr "Authentification Google Drive"
#: cps/templates/config_edit.html:44
msgid "Please hit submit to continue with setup"
msgid "Please hit save to continue with setup"
msgstr "Veuillez cliquer sur soumettre pour continuer linitialisation"
#: cps/templates/config_edit.html:47

@ -1557,7 +1557,7 @@ msgid "Authenticate Google Drive"
msgstr "Google Drive hitelesítés"
#: cps/templates/config_edit.html:44
msgid "Please hit submit to continue with setup"
msgid "Please hit save to continue with setup"
msgstr "A beállítás folytatásához kattints a Küldés gombra"
#: cps/templates/config_edit.html:47

@ -1556,7 +1556,7 @@ msgid "Authenticate Google Drive"
msgstr "Autenticazione Google Drive"
#: cps/templates/config_edit.html:44
msgid "Please hit submit to continue with setup"
msgid "Please hit save to continue with setup"
msgstr "Per favore premi invio per proseguire con la configurazione"
#: cps/templates/config_edit.html:47

@ -1557,7 +1557,7 @@ msgid "Authenticate Google Drive"
msgstr "Googleドライブを認証"
#: cps/templates/config_edit.html:44
msgid "Please hit submit to continue with setup"
msgid "Please hit save to continue with setup"
msgstr "決定を押して設定を続けてください"
#: cps/templates/config_edit.html:47

@ -1558,7 +1558,7 @@ msgid "Authenticate Google Drive"
msgstr "វាយបញ្ចូលគណនី Google Drive"
#: cps/templates/config_edit.html:44
msgid "Please hit submit to continue with setup"
msgid "Please hit save to continue with setup"
msgstr ""
#: cps/templates/config_edit.html:47

@ -1558,7 +1558,7 @@ msgid "Authenticate Google Drive"
msgstr "Google Drive goedkeuren"
#: cps/templates/config_edit.html:44
msgid "Please hit submit to continue with setup"
msgid "Please hit save to continue with setup"
msgstr "Druk op 'Opslaan' om door te gaan met instellen"
#: cps/templates/config_edit.html:47

@ -1570,7 +1570,7 @@ msgid "Authenticate Google Drive"
msgstr "Uwierzytelnij Dysk Google"
#: cps/templates/config_edit.html:44
msgid "Please hit submit to continue with setup"
msgid "Please hit save to continue with setup"
msgstr "Kliknij przycisk, aby kontynuować instalację"
#: cps/templates/config_edit.html:47

@ -1558,7 +1558,7 @@ msgid "Authenticate Google Drive"
msgstr "Аутентификация Google Drive"
#: cps/templates/config_edit.html:44
msgid "Please hit submit to continue with setup"
msgid "Please hit save to continue with setup"
msgstr "Пожалуйста, нажмите «Отправить», чтобы продолжить настройку"
#: cps/templates/config_edit.html:47

@ -1557,7 +1557,7 @@ msgid "Authenticate Google Drive"
msgstr "Autentisera Google Drive"
#: cps/templates/config_edit.html:44
msgid "Please hit submit to continue with setup"
msgid "Please hit save to continue with setup"
msgstr "Klicka på skicka för att fortsätta med installationen"
#: cps/templates/config_edit.html:47

@ -1557,7 +1557,7 @@ msgid "Authenticate Google Drive"
msgstr "Google Drive Doğrula"
#: cps/templates/config_edit.html:44
msgid "Please hit submit to continue with setup"
msgid "Please hit save to continue with setup"
msgstr "Kuruluma devam etmek için Gönder'e tıklayın"
#: cps/templates/config_edit.html:47

@ -1556,7 +1556,7 @@ msgid "Authenticate Google Drive"
msgstr "Автентифікація Google Drive"
#: cps/templates/config_edit.html:44
msgid "Please hit submit to continue with setup"
msgid "Please hit save to continue with setup"
msgstr ""
#: cps/templates/config_edit.html:47

@ -1557,7 +1557,7 @@ msgid "Authenticate Google Drive"
msgstr "认证 Google Drive"
#: cps/templates/config_edit.html:44
msgid "Please hit submit to continue with setup"
msgid "Please hit save to continue with setup"
msgstr "请点击提交以继续设置"
#: cps/templates/config_edit.html:47

@ -1556,7 +1556,7 @@ msgid "Authenticate Google Drive"
msgstr ""
#: cps/templates/config_edit.html:44
msgid "Please hit submit to continue with setup"
msgid "Please hit save to continue with setup"
msgstr ""
#: cps/templates/config_edit.html:47

Loading…
Cancel
Save