From d39b28b011ffb68bd425d9a8c8e17f223769c249 Mon Sep 17 00:00:00 2001 From: OzzieIsaacs Date: Tue, 8 Dec 2020 13:34:15 +0100 Subject: [PATCH] Fix for existing book format with gdrive --- cps/gdrive.py | 3 +++ cps/services/worker.py | 2 +- cps/tasks/convert.py | 9 +++++---- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/cps/gdrive.py b/cps/gdrive.py index 584c90cf..8f8b9aa8 100644 --- a/cps/gdrive.py +++ b/cps/gdrive.py @@ -84,6 +84,7 @@ def watch_gdrive(): if not config.config_google_drive_watch_changes_response: with open(gdriveutils.CLIENT_SECRETS, 'r') as settings: filedata = json.load(settings) + # ToDo: Easier: rstrip('/') if filedata['web']['redirect_uris'][0].endswith('/'): filedata['web']['redirect_uris'][0] = filedata['web']['redirect_uris'][0][:-((len('/gdrive/callback')+1))] else: @@ -123,6 +124,8 @@ def revoke_watch_gdrive(): @gdrive.route("/gdrive/watch/callback", methods=['GET', 'POST']) def on_received_watch_confirmation(): + if not config.config_google_drive_watch_changes_response: + return '' if request.headers.get('X-Goog-Channel-Token') != gdrive_watch_callback_token \ or request.headers.get('X-Goog-Resource-State') != 'change' \ or not request.data: diff --git a/cps/services/worker.py b/cps/services/worker.py index c2ea594c..7018a05a 100644 --- a/cps/services/worker.py +++ b/cps/services/worker.py @@ -110,7 +110,7 @@ class WorkerThread(threading.Thread): # We don't use a daemon here because we don't want the tasks to just be abruptly halted, leading to # possible file / database corruption item = self.queue.get(timeout=1) - except queue.Empty as ex: + except queue.Empty: time.sleep(1) continue diff --git a/cps/tasks/convert.py b/cps/tasks/convert.py index 5e38b8ef..39d42dcd 100644 --- a/cps/tasks/convert.py +++ b/cps/tasks/convert.py @@ -80,10 +80,11 @@ class TaskConvert(CalibreTask): format_old_ext = u'.' + self.settings['old_book_format'].lower() format_new_ext = u'.' + self.settings['new_book_format'].lower() - # check to see if destination format already exists - + # check to see if destination format already exists - or if book is in database # if it does - mark the conversion task as complete and return a success # this will allow send to kindle workflow to continue to work - if os.path.isfile(file_path + format_new_ext): + if os.path.isfile(file_path + format_new_ext) or\ + local_db.get_book_format(self.bookid, self.settings['new_book_format']): log.info("Book id %d already converted to %s", book_id, format_new_ext) cur_book = local_db.get_book(book_id) self.results['path'] = file_path @@ -111,7 +112,7 @@ class TaskConvert(CalibreTask): if check == 0: cur_book = local_db.get_book(book_id) if os.path.isfile(file_path + format_new_ext): - # self.db_queue.join() + # check if format is already there and replace it if so, problem with gdrive kepub upload (why?) new_format = db.Data(name=cur_book.data[0].name, book_format=self.settings['new_book_format'].upper(), book=book_id, uncompressed_size=os.path.getsize(file_path + format_new_ext)) @@ -119,7 +120,7 @@ class TaskConvert(CalibreTask): local_db.session.merge(new_format) local_db.session.commit() except SQLAlchemyError as e: - local_db.rollback() + local_db.session.rollback() log.error("Database error: %s", e) local_db.session.close() return