mirror of
https://github.com/janeczku/calibre-web
synced 2024-12-04 15:29:59 +00:00
Bugfixes after testrun
This commit is contained in:
parent
190ee09e60
commit
344c0c7bc3
11
cps/admin.py
11
cps/admin.py
@ -118,7 +118,7 @@ def before_request():
|
||||
g.allow_upload = config.config_uploading
|
||||
g.current_theme = config.config_theme
|
||||
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',
|
||||
'admin.simulatedbchange',
|
||||
'admin.db_configuration',
|
||||
@ -126,7 +126,7 @@ def before_request():
|
||||
'web.login_post',
|
||||
'web.logout',
|
||||
'admin.load_dialogtexts',
|
||||
'admin.ajax_pathchooser'):
|
||||
'admin.ajax_pathchooser')):
|
||||
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)
|
||||
else:
|
||||
_config_string(to_save, "config_calibre_split_dir")
|
||||
|
||||
if db_change or not db_valid or not config.db_configured \
|
||||
or config.config_calibre_dir != to_save["config_calibre_dir"]:
|
||||
if (db_change or not db_valid or not config.db_configured
|
||||
or config.config_calibre_dir != 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)
|
||||
else:
|
||||
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_change:
|
||||
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_string(to_save, "config_calibre_dir")
|
||||
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):
|
||||
flash(_("DB is not Writeable"), category="warning")
|
||||
calibre_db.update_config(config, config.config_calibre_dir, ub.app_DB_path)
|
||||
|
@ -538,7 +538,7 @@ class CalibreDB:
|
||||
self.Session = None
|
||||
#if init:
|
||||
# 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)
|
||||
|
||||
def init_app(self, _app):
|
||||
@ -1072,7 +1072,7 @@ class CalibreDB:
|
||||
# self.dispose()
|
||||
# self.engine.dispose()
|
||||
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):
|
||||
|
@ -215,6 +215,7 @@ def table_get_custom_enum(c_id):
|
||||
def edit_list_book(param):
|
||||
vals = request.form.to_dict()
|
||||
book = calibre_db.get_book(vals['pk'])
|
||||
calibre_db.create_functions(config)
|
||||
sort_param = ""
|
||||
ret = ""
|
||||
try:
|
||||
|
@ -60,6 +60,8 @@ class TaskConvert(CalibreTask):
|
||||
self.results = dict()
|
||||
|
||||
def run(self, worker_thread):
|
||||
df_cover = None
|
||||
cur_book = None
|
||||
self.worker_thread = worker_thread
|
||||
if config.config_use_google_drive:
|
||||
with app.app_context():
|
||||
@ -90,38 +92,38 @@ class TaskConvert(CalibreTask):
|
||||
format=self.settings['old_book_format'],
|
||||
fn=data.name + "." + self.settings['old_book_format'].lower())
|
||||
# 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:
|
||||
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:
|
||||
# Upload files to gdrive
|
||||
gdriveutils.updateGdriveCalibreFromLocal()
|
||||
self._handleSuccess()
|
||||
if self.ereader_mail:
|
||||
# if we're sending to E-Reader after converting, create a one-off task and run it immediately
|
||||
# todo: figure out how to incorporate this into the progress
|
||||
try:
|
||||
EmailText = N_(u"%(book)s send to E-Reader", book=escape(self.title))
|
||||
for email in self.ereader_mail.split(','):
|
||||
email = strip_whitespaces(email)
|
||||
worker_thread.add(self.user, TaskEmail(self.settings['subject'],
|
||||
self.results["path"],
|
||||
filename,
|
||||
self.settings,
|
||||
email,
|
||||
EmailText,
|
||||
self.settings['body'],
|
||||
id=self.book_id,
|
||||
internal=True)
|
||||
)
|
||||
except Exception as ex:
|
||||
return self._handleError(str(ex))
|
||||
# Upload files to gdrive
|
||||
gdriveutils.updateGdriveCalibreFromLocal()
|
||||
self._handleSuccess()
|
||||
if self.ereader_mail:
|
||||
# if we're sending to E-Reader after converting, create a one-off task and run it immediately
|
||||
# todo: figure out how to incorporate this into the progress
|
||||
try:
|
||||
EmailText = N_(u"%(book)s send to E-Reader", book=escape(self.title))
|
||||
for email in self.ereader_mail.split(','):
|
||||
email = strip_whitespaces(email)
|
||||
worker_thread.add(self.user, TaskEmail(self.settings['subject'],
|
||||
self.results["path"],
|
||||
filename,
|
||||
self.settings,
|
||||
email,
|
||||
EmailText,
|
||||
self.settings['body'],
|
||||
id=self.book_id,
|
||||
internal=True)
|
||||
)
|
||||
except Exception as ex:
|
||||
return self._handleError(str(ex))
|
||||
|
||||
def _convert_ebook_format(self):
|
||||
error_message = None
|
||||
|
@ -47,35 +47,35 @@ class TaskBackupMetadata(CalibreTask):
|
||||
|
||||
def set_all_books_dirty(self):
|
||||
with app.app_context():
|
||||
calibre_db = db.CalibreDB(app)
|
||||
calibre_dbb = db.CalibreDB(app)
|
||||
try:
|
||||
books = calibre_db.session.query(db.Books).all()
|
||||
books = calibre_dbb.session.query(db.Books).all()
|
||||
for book in books:
|
||||
calibre_db.set_metadata_dirty(book.id)
|
||||
calibre_db.session.commit()
|
||||
calibre_dbb.set_metadata_dirty(book.id)
|
||||
calibre_dbb.session.commit()
|
||||
self._handleSuccess()
|
||||
except Exception as ex:
|
||||
self.log.debug('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()
|
||||
|
||||
def backup_metadata(self):
|
||||
with app.app_context():
|
||||
try:
|
||||
calibre_db = db.CalibreDB(app)
|
||||
metadata_backup = calibre_db.session.query(db.Metadata_Dirtied).all()
|
||||
custom_columns = (calibre_db.session.query(db.CustomColumns)
|
||||
calibre_dbb = db.CalibreDB(app)
|
||||
metadata_backup = calibre_dbb.session.query(db.Metadata_Dirtied).all()
|
||||
custom_columns = (calibre_dbb.session.query(db.CustomColumns)
|
||||
.filter(db.CustomColumns.mark_for_delete == 0)
|
||||
.filter(db.CustomColumns.datatype.notin_(db.cc_exceptions))
|
||||
.order_by(db.CustomColumns.label).all())
|
||||
count = len(metadata_backup)
|
||||
i = 0
|
||||
for backup in metadata_backup:
|
||||
book = calibre_db.session.query(db.Books).filter(db.Books.id == backup.book).one_or_none()
|
||||
calibre_db.session.query(db.Metadata_Dirtied).filter(
|
||||
book = calibre_dbb.session.query(db.Books).filter(db.Books.id == backup.book).one_or_none()
|
||||
calibre_dbb.session.query(db.Metadata_Dirtied).filter(
|
||||
db.Metadata_Dirtied.book == backup.book).delete()
|
||||
calibre_db.session.commit()
|
||||
calibre_dbb.session.commit()
|
||||
if book:
|
||||
self.open_metadata(book, custom_columns)
|
||||
else:
|
||||
@ -89,7 +89,7 @@ class TaskBackupMetadata(CalibreTask):
|
||||
b = "NaN" if not hasattr(book, 'id') else book.id
|
||||
self.log.debug('Error creating metadata backup for book {}: '.format(b) + str(ex))
|
||||
self._handleError('Error creating metadata backup: ' + str(ex))
|
||||
calibre_db.session.rollback()
|
||||
calibre_dbb.session.rollback()
|
||||
# self.calibre_db.session.close()
|
||||
|
||||
def open_metadata(self, book, custom_columns):
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user