Bugfix session commit

Bugfix get_locale
Bugfix reconnect database schedule
Bugfix no permission error message logging
Bugfix updater
pull/2262/head^2
Ozzie Isaacs 2 years ago
parent 5d5a94c9e5
commit e8e4d87d39

@ -185,7 +185,6 @@ def update_thumbnails():
@login_required
@admin_required
def admin():
locale = get_locale()
version = updater_thread.get_current_version_info()
if version is False:
commit = _(u'Unknown')
@ -1460,7 +1459,7 @@ def download_debug():
def get_update_status():
if feature_support['updater']:
log.info(u"Update status requested")
return updater_thread.get_available_updates(request.method, locale=get_locale())
return updater_thread.get_available_updates(request.method)
else:
return ''

@ -441,10 +441,13 @@ class CalibreDB:
# instances alive once they reach the end of their respective scopes
instances = WeakSet()
def __init__(self):
def __init__(self, expire_on_commit=True, init=False):
""" Initialize a new CalibreDB session
"""
self.session = None
if init:
self.init_db(expire_on_commit)
def init_db(self, expire_on_commit=True):
if self._init:

@ -39,7 +39,7 @@ class FileSystem:
makedirs(self._cache_dir)
except OSError:
self.log.info(f'Failed to create path {self._cache_dir} (Permission denied).')
return False
raise
path = join(self._cache_dir, cache_type)
if cache_type and not isdir(path):
@ -47,7 +47,7 @@ class FileSystem:
makedirs(path)
except OSError:
self.log.info(f'Failed to create path {path} (Permission denied).')
return False
raise
return path if cache_type else self._cache_dir
@ -58,7 +58,7 @@ class FileSystem:
makedirs(path)
except OSError:
self.log.info(f'Failed to create path {path} (Permission denied).')
return False
raise
return path
@ -75,7 +75,7 @@ class FileSystem:
rmtree(self._cache_dir)
except OSError:
self.log.info(f'Failed to delete path {self._cache_dir} (Permission denied).')
return False
raise
path = join(self._cache_dir, cache_type)
if cache_type and isdir(path):
@ -83,7 +83,7 @@ class FileSystem:
rmtree(path)
except OSError:
self.log.info(f'Failed to delete path {path} (Permission denied).')
return False
raise
def delete_cache_file(self, filename, cache_type=None):
path = self.get_cache_file_path(filename, cache_type)
@ -92,4 +92,4 @@ class FileSystem:
remove(path)
except OSError:
self.log.info(f'Failed to delete path {path} (Permission denied).')
return False
raise

@ -1015,8 +1015,7 @@ def replace_cover_thumbnail_cache(book_id):
def delete_thumbnail_cache():
if config.schedule_generate_book_covers:
WorkerThread.add(None, TaskClearCoverThumbnailCache(-1))
WorkerThread.add(None, TaskClearCoverThumbnailCache(-1))
def add_book_to_thumbnail_cache(book_id):

@ -62,7 +62,7 @@ def register_scheduled_tasks(reconnect=True):
duration = config.schedule_duration
# Register scheduled tasks
scheduler.schedule_tasks(tasks=get_scheduled_tasks(), trigger='cron', hour=start)
scheduler.schedule_tasks(tasks=get_scheduled_tasks(reconnect), trigger='cron', hour=start)
end_time = calclulate_end_time(start, duration)
scheduler.schedule(func=end_scheduled_tasks, trigger='cron', name="end scheduled task", hour=end_time.hour,
minute=end_time.minute)

@ -55,8 +55,7 @@ class TaskConvert(CalibreTask):
def run(self, worker_thread):
self.worker_thread = worker_thread
if config.config_use_google_drive:
worker_db = db.CalibreDB()
worker_db.init_db(expire_on_commit=False)
worker_db = db.CalibreDB(expire_on_commit=False, init=True)
cur_book = worker_db.get_book(self.book_id)
self.title = cur_book.title
data = worker_db.get_book_format(self.book_id, self.settings['old_book_format'])
@ -105,8 +104,7 @@ class TaskConvert(CalibreTask):
def _convert_ebook_format(self):
error_message = None
local_db = db.CalibreDB()
local_db.init_db(expire_on_commit=False)
local_db = db.CalibreDB(expire_on_commit=False, init=True)
file_path = self.file_path
book_id = self.book_id
format_old_ext = u'.' + self.settings['old_book_format'].lower()

@ -68,8 +68,7 @@ class TaskGenerateCoverThumbnails(CalibreTask):
self.log = logger.create()
self.book_id = book_id
self.app_db_session = ub.get_new_session_instance()
self.calibre_db = db.CalibreDB()
self.calibre_db.init_db(expire_on_commit=False)
# self.calibre_db = db.CalibreDB(expire_on_commit=False, init=True)
self.cache = fs.FileSystem()
self.resolutions = [
constants.COVER_THUMBNAIL_SMALL,
@ -77,7 +76,7 @@ class TaskGenerateCoverThumbnails(CalibreTask):
]
def run(self, worker_thread):
if self.calibre_db.session and use_IM and self.stat != STAT_CANCELLED and self.stat != STAT_ENDED:
if use_IM and self.stat != STAT_CANCELLED and self.stat != STAT_ENDED:
self.message = 'Scanning Books'
books_with_covers = self.get_books_with_covers(self.book_id)
count = len(books_with_covers)
@ -112,11 +111,10 @@ class TaskGenerateCoverThumbnails(CalibreTask):
def get_books_with_covers(self, book_id=-1):
filter_exp = (db.Books.id == book_id) if book_id != -1 else True
return self.calibre_db.session \
.query(db.Books) \
.filter(db.Books.has_cover == 1) \
.filter(filter_exp) \
.all()
calibre_db = db.CalibreDB(expire_on_commit=False, init=True)
books_cover = calibre_db.session.query(db.Books).filter(db.Books.has_cover == 1).filter(filter_exp).all()
calibre_db.session.close()
return books_cover
def get_book_cover_thumbnails(self, book_id):
return self.app_db_session \
@ -160,7 +158,7 @@ class TaskGenerateCoverThumbnails(CalibreTask):
self.app_db_session.commit()
self.generate_book_thumbnail(book, thumbnail)
except Exception as ex:
self.log.info('Error creating book thumbnail: ' + str(ex))
self.log.debug('Error creating book thumbnail: ' + str(ex))
self._handleError('Error creating book thumbnail: ' + str(ex))
self.app_db_session.rollback()
@ -172,7 +170,7 @@ class TaskGenerateCoverThumbnails(CalibreTask):
self.cache.delete_cache_file(thumbnail.filename, constants.CACHE_TYPE_THUMBNAILS)
self.generate_book_thumbnail(book, thumbnail)
except Exception as ex:
self.log.info('Error updating book thumbnail: ' + str(ex))
self.log.debug('Error updating book thumbnail: ' + str(ex))
self._handleError('Error updating book thumbnail: ' + str(ex))
self.app_db_session.rollback()
@ -200,7 +198,7 @@ class TaskGenerateCoverThumbnails(CalibreTask):
img.save(filename=filename)
except Exception as ex:
# Bubble exception to calling function
self.log.info('Error generating thumbnail file: ' + str(ex))
self.log.debug('Error generating thumbnail file: ' + str(ex))
raise ex
finally:
if stream is not None:
@ -239,8 +237,7 @@ class TaskGenerateSeriesThumbnails(CalibreTask):
super(TaskGenerateSeriesThumbnails, self).__init__(task_message)
self.log = logger.create()
self.app_db_session = ub.get_new_session_instance()
self.calibre_db = db.CalibreDB()
self.calibre_db.init_db(expire_on_commit=False)
self.calibre_db = db.CalibreDB(expire_on_commit=False, init=True)
self.cache = fs.FileSystem()
self.resolutions = [
constants.COVER_THUMBNAIL_SMALL,
@ -337,7 +334,7 @@ class TaskGenerateSeriesThumbnails(CalibreTask):
self.app_db_session.commit()
self.generate_series_thumbnail(series_books, thumbnail)
except Exception as ex:
self.log.info('Error creating book thumbnail: ' + str(ex))
self.log.debug('Error creating book thumbnail: ' + str(ex))
self._handleError('Error creating book thumbnail: ' + str(ex))
self.app_db_session.rollback()
@ -349,7 +346,7 @@ class TaskGenerateSeriesThumbnails(CalibreTask):
self.cache.delete_cache_file(thumbnail.filename, constants.CACHE_TYPE_THUMBNAILS)
self.generate_series_thumbnail(series_books, thumbnail)
except Exception as ex:
self.log.info('Error updating book thumbnail: ' + str(ex))
self.log.debug('Error updating book thumbnail: ' + str(ex))
self._handleError('Error updating book thumbnail: ' + str(ex))
self.app_db_session.rollback()
@ -393,7 +390,7 @@ class TaskGenerateSeriesThumbnails(CalibreTask):
canvas.composite(img, left, top)
except Exception as ex:
self.log.info('Error generating thumbnail file: ' + str(ex))
self.log.debug('Error generating thumbnail file: ' + str(ex))
raise ex
finally:
if stream is not None:
@ -450,18 +447,18 @@ class TaskClearCoverThumbnailCache(CalibreTask):
super(TaskClearCoverThumbnailCache, self).__init__(task_message)
self.log = logger.create()
self.book_id = book_id
self.calibre_db = db.CalibreDB()
self.calibre_db.init_db(expire_on_commit=False)
self.app_db_session = ub.get_new_session_instance()
self.cache = fs.FileSystem()
def run(self, worker_thread):
if self.app_db_session:
if self.book_id == 0: # delete superfluous thumbnails
thumbnails = (self.calibre_db.session.query(ub.Thumbnail)
calibre_db = db.CalibreDB(expire_on_commit=False, init=True)
thumbnails = (calibre_db.session.query(ub.Thumbnail)
.join(db.Books, ub.Thumbnail.entity_id == db.Books.id, isouter=True)
.filter(db.Books.id == None)
.all())
calibre_db.session.close()
elif self.book_id > 0: # make sure single book is selected
thumbnails = self.get_thumbnails_for_book(self.book_id)
if self.book_id < 0:
@ -489,7 +486,7 @@ class TaskClearCoverThumbnailCache(CalibreTask):
.delete()
self.app_db_session.commit()
except Exception as ex:
self.log.info('Error deleting book thumbnail: ' + str(ex))
self.log.debug('Error deleting book thumbnail: ' + str(ex))
self._handleError('Error deleting book thumbnail: ' + str(ex))
def delete_all_thumbnails(self):
@ -498,7 +495,7 @@ class TaskClearCoverThumbnailCache(CalibreTask):
self.app_db_session.commit()
self.cache.delete_cache_dir(constants.CACHE_TYPE_THUMBNAILS)
except Exception as ex:
self.log.info('Error deleting thumbnail directory: ' + str(ex))
self.log.debug('Error deleting thumbnail directory: ' + str(ex))
self._handleError('Error deleting thumbnail directory: ' + str(ex))
@property

@ -33,7 +33,7 @@
<label for="schedule_generate_series_covers">{{_('Generate Series Cover Thumbnails')}}</label>
</div-->
<div class="form-group">
<input type="checkbox" id="schedule_reconnect" name="schedule_reconnect" {% if config.schedule_generate_book_covers %}checked{% endif %}>
<input type="checkbox" id="schedule_reconnect" name="schedule_reconnect" {% if config.schedule_reconnect %}checked{% endif %}>
<label for="schedule_reconnect">{{_('Reconnect to Calibre Library')}}</label>
</div>

@ -67,10 +67,10 @@ class Updater(threading.Thread):
return self._stable_version_info()
return self._nightly_version_info()
def get_available_updates(self, request_method, locale):
def get_available_updates(self, request_method):
if self.config.config_updatechannel == constants.UPDATE_STABLE:
return self._stable_available_updates(request_method)
return self._nightly_available_updates(request_method, locale)
return self._nightly_available_updates(request_method)
def do_work(self):
try:
@ -335,7 +335,7 @@ class Updater(threading.Thread):
print("\n*** Finished ***")
@staticmethod
def _populate_parent_commits(update_data, status, locale, tz, parents):
def _populate_parent_commits(update_data, status, tz, parents):
try:
parent_commit = update_data['parents'][0]
# limit the maximum search depth
@ -360,7 +360,7 @@ class Updater(threading.Thread):
parent_commit_date = datetime.datetime.strptime(
parent_data['committer']['date'], '%Y-%m-%dT%H:%M:%SZ') - tz
parent_commit_date = format_datetime(
parent_commit_date, format='short', locale=locale)
parent_commit_date, format='short')
parents.append([parent_commit_date,
parent_data['message'].replace('\r\n', '<p>').replace('\n', '<p>')])
@ -418,7 +418,7 @@ class Updater(threading.Thread):
log_function("Excluded file list for updater not found, or not accessible")
return excluded_files
def _nightly_available_updates(self, request_method, locale):
def _nightly_available_updates(self, request_method):
tz = datetime.timedelta(seconds=time.timezone if (time.localtime().tm_isdst == 0) else time.altzone)
if request_method == "GET":
repository_url = _REPOSITORY_API_URL
@ -459,14 +459,14 @@ class Updater(threading.Thread):
update_data['committer']['date'], '%Y-%m-%dT%H:%M:%SZ') - tz
parents.append(
[
format_datetime(new_commit_date, format='short', locale=locale),
format_datetime(new_commit_date, format='short'),
update_data['message'],
update_data['sha']
]
)
# it only makes sense to analyze the parents if we know the current commit hash
if status['current_commit_hash'] != '':
parents = self._populate_parent_commits(update_data, status, locale, tz, parents)
parents = self._populate_parent_commits(update_data, status, tz, parents)
status['history'] = parents[::-1]
except (IndexError, KeyError):
status['success'] = False
@ -595,7 +595,7 @@ class Updater(threading.Thread):
return json.dumps(status)
def _get_request_path(self):
if config.config_updatechannel == constants.UPDATE_STABLE:
if self.config.config_updatechannel == constants.UPDATE_STABLE:
return self.updateFile
return _REPOSITORY_API_URL + '/zipball/master'
@ -623,7 +623,7 @@ class Updater(threading.Thread):
status['message'] = _(u'HTTP Error') + ': ' + commit['message']
else:
status['message'] = _(u'HTTP Error') + ': ' + str(e)
except requests.exceptions.ConnectionError:
except requests.exceptions.ConnectionError as e:
status['message'] = _(u'Connection error')
except requests.exceptions.Timeout:
status['message'] = _(u'Timeout while establishing connection')

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save