1
0
mirror of https://github.com/janeczku/calibre-web synced 2024-12-04 23:40:01 +00:00

Bugfixes after testrun

This commit is contained in:
Ozzie Isaacs 2024-11-26 20:22:20 +01:00
parent 190ee09e60
commit 344c0c7bc3
6 changed files with 3498 additions and 3191 deletions

View File

@ -118,7 +118,7 @@ def before_request():
g.allow_upload = config.config_uploading g.allow_upload = config.config_uploading
g.current_theme = config.config_theme g.current_theme = config.config_theme
g.config_authors_max = config.config_authors_max g.config_authors_max = config.config_authors_max
if '/static/' not in request.path and not config.db_configured and \ if ('/static/' not in request.path and not config.db_configured and
request.endpoint not in ('admin.ajax_db_config', request.endpoint not in ('admin.ajax_db_config',
'admin.simulatedbchange', 'admin.simulatedbchange',
'admin.db_configuration', 'admin.db_configuration',
@ -126,7 +126,7 @@ def before_request():
'web.login_post', 'web.login_post',
'web.logout', 'web.logout',
'admin.load_dialogtexts', 'admin.load_dialogtexts',
'admin.ajax_pathchooser'): 'admin.ajax_pathchooser')):
return redirect(url_for('admin.db_configuration')) return redirect(url_for('admin.db_configuration'))
@ -1736,14 +1736,12 @@ def _db_configuration_update_helper():
return _db_configuration_result(_("Books path not valid"), gdrive_error) return _db_configuration_result(_("Books path not valid"), gdrive_error)
else: else:
_config_string(to_save, "config_calibre_split_dir") _config_string(to_save, "config_calibre_split_dir")
if (db_change or not db_valid or not config.db_configured
if db_change or not db_valid or not config.db_configured \ or config.config_calibre_dir != to_save["config_calibre_dir"]):
or config.config_calibre_dir != to_save["config_calibre_dir"]:
if not os.path.exists(metadata_db) or not to_save['config_calibre_dir']: if not os.path.exists(metadata_db) or not to_save['config_calibre_dir']:
return _db_configuration_result(_('DB Location is not Valid, Please Enter Correct Path'), gdrive_error) return _db_configuration_result(_('DB Location is not Valid, Please Enter Correct Path'), gdrive_error)
else: else:
calibre_db.setup_db(to_save['config_calibre_dir'], ub.app_DB_path) calibre_db.setup_db(to_save['config_calibre_dir'], ub.app_DB_path)
config.store_calibre_uuid(calibre_db, db.Library_Id)
# if db changed -> delete shelfs, delete download books, delete read books, kobo sync... # if db changed -> delete shelfs, delete download books, delete read books, kobo sync...
if db_change: if db_change:
log.info("Calibre Database changed, all Calibre-Web info related to old Database gets deleted") log.info("Calibre Database changed, all Calibre-Web info related to old Database gets deleted")
@ -1767,6 +1765,7 @@ def _db_configuration_update_helper():
config.config_read_column = 0 config.config_read_column = 0
_config_string(to_save, "config_calibre_dir") _config_string(to_save, "config_calibre_dir")
calibre_db.update_config(config, config.config_calibre_dir, ub.app_DB_path) calibre_db.update_config(config, config.config_calibre_dir, ub.app_DB_path)
config.store_calibre_uuid(calibre_db, db.Library_Id)
if not os.access(os.path.join(config.config_calibre_dir, "metadata.db"), os.W_OK): if not os.access(os.path.join(config.config_calibre_dir, "metadata.db"), os.W_OK):
flash(_("DB is not Writeable"), category="warning") flash(_("DB is not Writeable"), category="warning")
calibre_db.update_config(config, config.config_calibre_dir, ub.app_DB_path) calibre_db.update_config(config, config.config_calibre_dir, ub.app_DB_path)

View File

@ -538,7 +538,7 @@ class CalibreDB:
self.Session = None self.Session = None
#if init: #if init:
# self.init_db(expire_on_commit) # self.init_db(expire_on_commit)
if _app is not None: if _app is not None and not _app._got_first_request:
self.init_app(_app) self.init_app(_app)
def init_app(self, _app): def init_app(self, _app):
@ -1072,7 +1072,7 @@ class CalibreDB:
# self.dispose() # self.dispose()
# self.engine.dispose() # self.engine.dispose()
self.setup_db(config.config_calibre_dir, app_db_path) self.setup_db(config.config_calibre_dir, app_db_path)
self.update_config(config) self.update_config(config, config.config_calibre_dir, app_db_path)
def lcase(s): def lcase(s):

View File

@ -215,6 +215,7 @@ def table_get_custom_enum(c_id):
def edit_list_book(param): def edit_list_book(param):
vals = request.form.to_dict() vals = request.form.to_dict()
book = calibre_db.get_book(vals['pk']) book = calibre_db.get_book(vals['pk'])
calibre_db.create_functions(config)
sort_param = "" sort_param = ""
ret = "" ret = ""
try: try:

View File

@ -60,6 +60,8 @@ class TaskConvert(CalibreTask):
self.results = dict() self.results = dict()
def run(self, worker_thread): def run(self, worker_thread):
df_cover = None
cur_book = None
self.worker_thread = worker_thread self.worker_thread = worker_thread
if config.config_use_google_drive: if config.config_use_google_drive:
with app.app_context(): with app.app_context():
@ -90,38 +92,38 @@ class TaskConvert(CalibreTask):
format=self.settings['old_book_format'], format=self.settings['old_book_format'],
fn=data.name + "." + self.settings['old_book_format'].lower()) fn=data.name + "." + self.settings['old_book_format'].lower())
# worker_db.session.close() # worker_db.session.close()
return self._handleError(error_message) return self._handleError(error_message)
filename = self._convert_ebook_format() filename = self._convert_ebook_format()
if config.config_use_google_drive:
os.remove(self.file_path + '.' + self.settings['old_book_format'].lower())
if df_cover:
os.remove(os.path.join(config.config_calibre_dir, cur_book.path, "cover.jpg"))
if filename:
if config.config_use_google_drive: if config.config_use_google_drive:
os.remove(self.file_path + '.' + self.settings['old_book_format'].lower()) # Upload files to gdrive
if df_cover: gdriveutils.updateGdriveCalibreFromLocal()
os.remove(os.path.join(config.config_calibre_dir, cur_book.path, "cover.jpg")) self._handleSuccess()
if self.ereader_mail:
if filename: # if we're sending to E-Reader after converting, create a one-off task and run it immediately
if config.config_use_google_drive: # todo: figure out how to incorporate this into the progress
# Upload files to gdrive try:
gdriveutils.updateGdriveCalibreFromLocal() EmailText = N_(u"%(book)s send to E-Reader", book=escape(self.title))
self._handleSuccess() for email in self.ereader_mail.split(','):
if self.ereader_mail: email = strip_whitespaces(email)
# if we're sending to E-Reader after converting, create a one-off task and run it immediately worker_thread.add(self.user, TaskEmail(self.settings['subject'],
# todo: figure out how to incorporate this into the progress self.results["path"],
try: filename,
EmailText = N_(u"%(book)s send to E-Reader", book=escape(self.title)) self.settings,
for email in self.ereader_mail.split(','): email,
email = strip_whitespaces(email) EmailText,
worker_thread.add(self.user, TaskEmail(self.settings['subject'], self.settings['body'],
self.results["path"], id=self.book_id,
filename, internal=True)
self.settings, )
email, except Exception as ex:
EmailText, return self._handleError(str(ex))
self.settings['body'],
id=self.book_id,
internal=True)
)
except Exception as ex:
return self._handleError(str(ex))
def _convert_ebook_format(self): def _convert_ebook_format(self):
error_message = None error_message = None

View File

@ -47,35 +47,35 @@ class TaskBackupMetadata(CalibreTask):
def set_all_books_dirty(self): def set_all_books_dirty(self):
with app.app_context(): with app.app_context():
calibre_db = db.CalibreDB(app) calibre_dbb = db.CalibreDB(app)
try: try:
books = calibre_db.session.query(db.Books).all() books = calibre_dbb.session.query(db.Books).all()
for book in books: for book in books:
calibre_db.set_metadata_dirty(book.id) calibre_dbb.set_metadata_dirty(book.id)
calibre_db.session.commit() calibre_dbb.session.commit()
self._handleSuccess() self._handleSuccess()
except Exception as ex: except Exception as ex:
self.log.debug('Error adding book for backup: ' + str(ex)) self.log.debug('Error adding book for backup: ' + str(ex))
self._handleError('Error adding book for backup: ' + str(ex)) self._handleError('Error adding book for backup: ' + str(ex))
calibre_db.session.rollback() calibre_dbb.session.rollback()
# self.calibre_db.session.close() # self.calibre_db.session.close()
def backup_metadata(self): def backup_metadata(self):
with app.app_context(): with app.app_context():
try: try:
calibre_db = db.CalibreDB(app) calibre_dbb = db.CalibreDB(app)
metadata_backup = calibre_db.session.query(db.Metadata_Dirtied).all() metadata_backup = calibre_dbb.session.query(db.Metadata_Dirtied).all()
custom_columns = (calibre_db.session.query(db.CustomColumns) custom_columns = (calibre_dbb.session.query(db.CustomColumns)
.filter(db.CustomColumns.mark_for_delete == 0) .filter(db.CustomColumns.mark_for_delete == 0)
.filter(db.CustomColumns.datatype.notin_(db.cc_exceptions)) .filter(db.CustomColumns.datatype.notin_(db.cc_exceptions))
.order_by(db.CustomColumns.label).all()) .order_by(db.CustomColumns.label).all())
count = len(metadata_backup) count = len(metadata_backup)
i = 0 i = 0
for backup in metadata_backup: for backup in metadata_backup:
book = calibre_db.session.query(db.Books).filter(db.Books.id == backup.book).one_or_none() book = calibre_dbb.session.query(db.Books).filter(db.Books.id == backup.book).one_or_none()
calibre_db.session.query(db.Metadata_Dirtied).filter( calibre_dbb.session.query(db.Metadata_Dirtied).filter(
db.Metadata_Dirtied.book == backup.book).delete() db.Metadata_Dirtied.book == backup.book).delete()
calibre_db.session.commit() calibre_dbb.session.commit()
if book: if book:
self.open_metadata(book, custom_columns) self.open_metadata(book, custom_columns)
else: else:
@ -89,7 +89,7 @@ class TaskBackupMetadata(CalibreTask):
b = "NaN" if not hasattr(book, 'id') else book.id b = "NaN" if not hasattr(book, 'id') else book.id
self.log.debug('Error creating metadata backup for book {}: '.format(b) + str(ex)) self.log.debug('Error creating metadata backup for book {}: '.format(b) + str(ex))
self._handleError('Error creating metadata backup: ' + str(ex)) self._handleError('Error creating metadata backup: ' + str(ex))
calibre_db.session.rollback() calibre_dbb.session.rollback()
# self.calibre_db.session.close() # self.calibre_db.session.close()
def open_metadata(self, book, custom_columns): def open_metadata(self, book, custom_columns):

File diff suppressed because it is too large Load Diff