Negate a condition
- removes two levels of indentation - makes it clear that if the wrong tokens are provided nothing will happen - remove a useless nested function
This commit is contained in:
parent
5792838333
commit
d2617322c6
|
@ -123,38 +123,36 @@ 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 request.headers.get('X-Goog-Channel-Token') != gdrive_watch_callback_token \
|
||||||
|
or request.headers.get('X-Goog-Resource-State') != 'change' \
|
||||||
|
or not request.data:
|
||||||
|
return redirect(url_for('admin.configuration'))
|
||||||
|
|
||||||
log.debug('%r', request.headers)
|
log.debug('%r', request.headers)
|
||||||
if request.headers.get('X-Goog-Channel-Token') == gdrive_watch_callback_token \
|
log.debug('%r', request.data)
|
||||||
and request.headers.get('X-Goog-Resource-State') == 'change' \
|
log.info('Change received from gdrive')
|
||||||
and request.data:
|
|
||||||
|
|
||||||
data = request.data
|
try:
|
||||||
|
j = json.loads(request.data)
|
||||||
def updateMetaData():
|
log.info('Getting change details')
|
||||||
log.info('Change received from gdrive')
|
response = gdriveutils.getChangeById(gdriveutils.Gdrive.Instance().drive, j['id'])
|
||||||
log.debug('%r', data)
|
log.debug('%r', response)
|
||||||
try:
|
if response:
|
||||||
j = json.loads(data)
|
if sys.version_info < (3, 0):
|
||||||
log.info('Getting change details')
|
dbpath = os.path.join(config.config_calibre_dir, "metadata.db")
|
||||||
response = gdriveutils.getChangeById(gdriveutils.Gdrive.Instance().drive, j['id'])
|
else:
|
||||||
log.debug('%r', response)
|
dbpath = os.path.join(config.config_calibre_dir, "metadata.db").encode()
|
||||||
if response:
|
if not response['deleted'] and response['file']['title'] == 'metadata.db' \
|
||||||
if sys.version_info < (3, 0):
|
and response['file']['md5Checksum'] != hashlib.md5(dbpath):
|
||||||
dbpath = os.path.join(config.config_calibre_dir, "metadata.db")
|
tmpDir = tempfile.gettempdir()
|
||||||
else:
|
log.info('Database file updated')
|
||||||
dbpath = os.path.join(config.config_calibre_dir, "metadata.db").encode()
|
copyfile(dbpath, os.path.join(tmpDir, "metadata.db_" + str(current_milli_time())))
|
||||||
if not response['deleted'] and response['file']['title'] == 'metadata.db' \
|
log.info('Backing up existing and downloading updated metadata.db')
|
||||||
and response['file']['md5Checksum'] != hashlib.md5(dbpath):
|
gdriveutils.downloadFile(None, "metadata.db", os.path.join(tmpDir, "tmp_metadata.db"))
|
||||||
tmpDir = tempfile.gettempdir()
|
log.info('Setting up new DB')
|
||||||
log.info('Database file updated')
|
# prevent error on windows, as os.rename does on exisiting files
|
||||||
copyfile(dbpath, os.path.join(tmpDir, "metadata.db_" + str(current_milli_time())))
|
move(os.path.join(tmpDir, "tmp_metadata.db"), dbpath)
|
||||||
log.info('Backing up existing and downloading updated metadata.db')
|
calibre_db.reconnect_db(config, ub.app_DB_path)
|
||||||
gdriveutils.downloadFile(None, "metadata.db", os.path.join(tmpDir, "tmp_metadata.db"))
|
except Exception as e:
|
||||||
log.info('Setting up new DB')
|
log.exception(e)
|
||||||
# prevent error on windows, as os.rename does on exisiting files
|
|
||||||
move(os.path.join(tmpDir, "tmp_metadata.db"), dbpath)
|
|
||||||
calibre_db.reconnect_db(config, ub.app_DB_path)
|
|
||||||
except Exception as e:
|
|
||||||
log.exception(e)
|
|
||||||
updateMetaData()
|
|
||||||
return ''
|
return ''
|
||||||
|
|
Loading…
Reference in New Issue
Block a user