diff --git a/cps/gdriveutils.py b/cps/gdriveutils.py index ffddb9d3..cb36a413 100644 --- a/cps/gdriveutils.py +++ b/cps/gdriveutils.py @@ -20,7 +20,7 @@ try: from pydrive.auth import GoogleAuth from pydrive.drive import GoogleDrive - from pydrive.auth import RefreshError + from pydrive.auth import RefreshError, InvalidConfigError from apiclient import errors gdrive_support = True except ImportError: @@ -166,7 +166,10 @@ def getDrive(drive=None, gauth=None): # Save the current credentials to a file return GoogleDrive(gauth) if drive.auth.access_token_expired: - drive.auth.Refresh() + try: + drive.auth.Refresh() + except RefreshError as e: + web.app.logger.error("Google Drive error: " + e.message) return drive def listRootFolders(): @@ -454,6 +457,10 @@ def getChangeById (drive, change_id): except (errors.HttpError) as error: web.app.logger.info(error.message) return None + except Exception as e: + web.app.logger.info(e) + return None + # Deletes the local hashes database to force search for new folder names def deleteDatabaseOnChange(): diff --git a/cps/helper.py b/cps/helper.py index 94da9e5c..31d82e73 100644 --- a/cps/helper.py +++ b/cps/helper.py @@ -427,6 +427,8 @@ def delete_book(book, calibrepath, book_format): def get_book_cover(cover_path): if ub.config.config_use_google_drive: try: + if not web.is_gdrive_ready(): + return send_from_directory(os.path.join(os.path.dirname(__file__), "static"), "generic_cover.jpg") path=gd.get_cover_via_gdrive(cover_path) if path: return redirect(path) @@ -434,7 +436,7 @@ def get_book_cover(cover_path): web.app.logger.error(cover_path + '/cover.jpg not found on Google Drive') return send_from_directory(os.path.join(os.path.dirname(__file__), "static"), "generic_cover.jpg") except Exception as e: - web.app.logger.error("Error Message: "+e.message) + web.app.logger.error("Error Message: " + e.message) web.app.logger.exception(e) # traceback.print_exc() return send_from_directory(os.path.join(os.path.dirname(__file__), "static"),"generic_cover.jpg") diff --git a/cps/templates/config_edit.html b/cps/templates/config_edit.html index bdd72946..cef969d3 100644 --- a/cps/templates/config_edit.html +++ b/cps/templates/config_edit.html @@ -31,15 +31,19 @@ {% else %} - {% if show_authenticate_google_drive and g.user.is_authenticated %} + {% if show_authenticate_google_drive and g.user.is_authenticated and content.config_use_google_drive %}
{{_('Authenticate Google Drive')}}
{% else %} - {% if show_authenticate_google_drive and not g.user.is_authenticated %} + {% if show_authenticate_google_drive and g.user.is_authenticated and not content.config_use_google_drive %} +
{{_('Please hit submit to continue with setup')}}
+ {% endif %} + {% if not g.user.is_authenticated %}
{{_('Please finish Google Drive setup after login')}}
- {% endif %} - {% if not show_authenticate_google_drive %} + {% endif %} + {% if g.user.is_authenticated %} + {% if not show_authenticate_google_drive %}