Fix for existing book format with gdrive
This commit is contained in:
parent
8f36128fe3
commit
d39b28b011
|
@ -84,6 +84,7 @@ def watch_gdrive():
|
||||||
if not config.config_google_drive_watch_changes_response:
|
if not config.config_google_drive_watch_changes_response:
|
||||||
with open(gdriveutils.CLIENT_SECRETS, 'r') as settings:
|
with open(gdriveutils.CLIENT_SECRETS, 'r') as settings:
|
||||||
filedata = json.load(settings)
|
filedata = json.load(settings)
|
||||||
|
# ToDo: Easier: rstrip('/')
|
||||||
if filedata['web']['redirect_uris'][0].endswith('/'):
|
if filedata['web']['redirect_uris'][0].endswith('/'):
|
||||||
filedata['web']['redirect_uris'][0] = filedata['web']['redirect_uris'][0][:-((len('/gdrive/callback')+1))]
|
filedata['web']['redirect_uris'][0] = filedata['web']['redirect_uris'][0][:-((len('/gdrive/callback')+1))]
|
||||||
else:
|
else:
|
||||||
|
@ -123,6 +124,8 @@ def revoke_watch_gdrive():
|
||||||
|
|
||||||
@gdrive.route("/gdrive/watch/callback", methods=['GET', 'POST'])
|
@gdrive.route("/gdrive/watch/callback", methods=['GET', 'POST'])
|
||||||
def on_received_watch_confirmation():
|
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 \
|
if request.headers.get('X-Goog-Channel-Token') != gdrive_watch_callback_token \
|
||||||
or request.headers.get('X-Goog-Resource-State') != 'change' \
|
or request.headers.get('X-Goog-Resource-State') != 'change' \
|
||||||
or not request.data:
|
or not request.data:
|
||||||
|
|
|
@ -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
|
# 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
|
# possible file / database corruption
|
||||||
item = self.queue.get(timeout=1)
|
item = self.queue.get(timeout=1)
|
||||||
except queue.Empty as ex:
|
except queue.Empty:
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
|
@ -80,10 +80,11 @@ class TaskConvert(CalibreTask):
|
||||||
format_old_ext = u'.' + self.settings['old_book_format'].lower()
|
format_old_ext = u'.' + self.settings['old_book_format'].lower()
|
||||||
format_new_ext = u'.' + self.settings['new_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
|
# if it does - mark the conversion task as complete and return a success
|
||||||
# this will allow send to kindle workflow to continue to work
|
# 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)
|
log.info("Book id %d already converted to %s", book_id, format_new_ext)
|
||||||
cur_book = local_db.get_book(book_id)
|
cur_book = local_db.get_book(book_id)
|
||||||
self.results['path'] = file_path
|
self.results['path'] = file_path
|
||||||
|
@ -111,7 +112,7 @@ class TaskConvert(CalibreTask):
|
||||||
if check == 0:
|
if check == 0:
|
||||||
cur_book = local_db.get_book(book_id)
|
cur_book = local_db.get_book(book_id)
|
||||||
if os.path.isfile(file_path + format_new_ext):
|
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,
|
new_format = db.Data(name=cur_book.data[0].name,
|
||||||
book_format=self.settings['new_book_format'].upper(),
|
book_format=self.settings['new_book_format'].upper(),
|
||||||
book=book_id, uncompressed_size=os.path.getsize(file_path + format_new_ext))
|
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.merge(new_format)
|
||||||
local_db.session.commit()
|
local_db.session.commit()
|
||||||
except SQLAlchemyError as e:
|
except SQLAlchemyError as e:
|
||||||
local_db.rollback()
|
local_db.session.rollback()
|
||||||
log.error("Database error: %s", e)
|
log.error("Database error: %s", e)
|
||||||
local_db.session.close()
|
local_db.session.close()
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue
Block a user