diff --git a/cps/admin.py b/cps/admin.py index fedee340..0b90327e 100644 --- a/cps/admin.py +++ b/cps/admin.py @@ -159,7 +159,7 @@ def shutdown(): # needed for docker applications, as changes on metadata.db from host are not visible to application @admi.route("/reconnect", methods=['GET']) def reconnect(): - if cli.args.r: + if cli.reconnect_enable: calibre_db.reconnect_db(config, ub.app_DB_path) return json.dumps({}) else: diff --git a/cps/cli.py b/cps/cli.py index a63d7282..36c03513 100644 --- a/cps/cli.py +++ b/cps/cli.py @@ -84,10 +84,14 @@ if args.k == "": # dry run updater dry_run = args.d or None +# enable reconnect endpoint for docker database reconnect +reconnect_enable = args.r or os.environ.get("CALIBRE_RECONNECT", None) # load covers from localhost -allow_localhost = args.l or None +allow_localhost = args.l or os.environ.get("CALIBRE_LOCALHOST", None) # handle and check ip address argument ip_address = args.i or None + + if ip_address: try: # try to parse the given ip address with socket diff --git a/cps/gdriveutils.py b/cps/gdriveutils.py index 0b704db4..e75f3742 100644 --- a/cps/gdriveutils.py +++ b/cps/gdriveutils.py @@ -81,7 +81,7 @@ if gdrive_support: 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) + log.debug("Cannot import pydrive, httplib2, using gdrive will not work: %s", importError) class Singleton: @@ -272,8 +272,7 @@ def getEbooksFolderId(drive=None): try: session.commit() except OperationalError as ex: - log.error("gdrive.db DB is not Writeable") - log.debug('Database error: %s', ex) + log.error_or_exception('Database error: %s', ex) session.rollback() return gDriveId.gdrive_id @@ -322,8 +321,7 @@ def getFolderId(path, drive): else: currentFolderId = storedPathName.gdrive_id except OperationalError as ex: - log.error("gdrive.db DB is not Writeable") - log.debug('Database error: %s', ex) + log.error_or_exception('Database error: %s', ex) session.rollback() except ApiRequestError as ex: log.error('{} {}'.format(ex.error['message'], path)) @@ -547,8 +545,7 @@ def deleteDatabaseOnChange(): session.commit() except (OperationalError, InvalidRequestError) as ex: session.rollback() - log.debug('Database error: %s', ex) - log.error(u"GDrive DB is not Writeable") + log.error_or_exception('Database error: %s', ex) def updateGdriveCalibreFromLocal(): @@ -566,8 +563,7 @@ def updateDatabaseOnEdit(ID,newPath): try: session.commit() except OperationalError as ex: - log.error("gdrive.db DB is not Writeable") - log.debug('Database error: %s', ex) + log.error_or_exception('Database error: %s', ex) session.rollback() @@ -577,8 +573,7 @@ def deleteDatabaseEntry(ID): try: session.commit() except OperationalError as ex: - log.error("gdrive.db DB is not Writeable") - log.debug('Database error: %s', ex) + log.error_or_exception('Database error: %s', ex) session.rollback() @@ -599,8 +594,7 @@ def get_cover_via_gdrive(cover_path): try: session.commit() except OperationalError as ex: - log.error("gdrive.db DB is not Writeable") - log.debug('Database error: %s', ex) + log.error_or_exception('Database error: %s', ex) session.rollback() return df.metadata.get('webContentLink') else: diff --git a/cps/helper.py b/cps/helper.py index 4dabcfce..7dd3ca9f 100644 --- a/cps/helper.py +++ b/cps/helper.py @@ -435,8 +435,7 @@ def rename_all_authors(first_author, renamed_author, calibre_path="", localbook= new_author_path = os.path.join(calibre_path, new_author_rename_dir) shutil.move(os.path.normcase(old_author_path), os.path.normcase(new_author_path)) except OSError as ex: - log.error("Rename author from: %s to %s: %s", old_author_path, new_author_path, ex) - log.debug(ex, exc_info=True) + log.error_or_exception("Rename author from: %s to %s: %s", old_author_path, new_author_path, ex) return _("Rename author from: '%(src)s' to '%(dest)s' failed with error: %(error)s", src=old_author_path, dest=new_author_path, error=str(ex)) else: @@ -550,8 +549,7 @@ def move_files_on_change(calibre_path, new_authordir, new_titledir, localbook, d # change location in database to new author/title path localbook.path = os.path.join(new_authordir, new_titledir).replace('\\', '/') except OSError as ex: - log.error("Rename title from: %s to %s: %s", path, new_path, ex) - log.debug(ex, exc_info=True) + log.error_or_exception("Rename title from: %s to %s: %s", path, new_path, ex) return _("Rename title from: '%(src)s' to '%(dest)s' failed with error: %(error)s", src=path, dest=new_path, error=str(ex)) return False @@ -572,8 +570,7 @@ def rename_files_on_change(first_author, if not gdrive and not renamed_author and not orignal_filepath and len(os.listdir(os.path.dirname(path))) == 0: shutil.rmtree(os.path.dirname(path)) except (OSError, FileNotFoundError) as ex: - log.error("Error in rename file in path %s", ex) - log.debug(ex, exc_info=True) + log.error_or_exception("Error in rename file in path %s", ex) return _("Error in rename file in path: %(error)s", error=str(ex)) return False