Bugfixes after testrun

This commit is contained in:
Ozzie Isaacs
2024-11-28 14:47:52 +01:00
parent 190ee09e60
commit 344c0c7bc3
6 changed files with 3498 additions and 3191 deletions
+32 -30
View File
@@ -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
+12 -12
View File
@@ -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):