Skip to content

Commit

Permalink
Bugfixes after testrun
Browse files Browse the repository at this point in the history
Enabled re-encode of bookformats
  • Loading branch information
OzzieIsaacs committed Feb 7, 2022
1 parent 3bb41ac commit 7c62394
Show file tree
Hide file tree
Showing 3 changed files with 167 additions and 107 deletions.
2 changes: 1 addition & 1 deletion cps/editbooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ def upload_single_file(request, book, book_id):
# Queue uploader info
link = '<a href="{}">{}</a>'.format(url_for('web.show_book', book_id=book.id), escape(book.title))
uploadText=_(u"File format %(ext)s added to %(book)s", ext=file_ext.upper(), book=link)
WorkerThread.add(current_user.name, TaskUpload(uploadText), escape(book.title))
WorkerThread.add(current_user.name, TaskUpload(uploadText, escape(book.title)))

return uploader.process(
saved_filename, *os.path.splitext(requested_file.filename),
Expand Down
62 changes: 34 additions & 28 deletions cps/tasks/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,21 +118,24 @@ def _convert_ebook_format(self):
self.title = cur_book.title
self.results['path'] = cur_book.path
self.results['title'] = self.title
new_format = db.Data(name=os.path.basename(file_path),
book_format=self.settings['new_book_format'].upper(),
book=book_id, uncompressed_size=os.path.getsize(file_path + format_new_ext))
try:
local_db.session.merge(new_format)
local_db.session.commit()
except SQLAlchemyError as e:
local_db.session.rollback()
log.error("Database error: %s", e)
new_format = local_db.session.query(db.Data).filter(db.Data.book == book_id)\
.filter(db.Data.format == self.settings['new_book_format'].upper()).one_or_none()
if not new_format:
new_format = db.Data(name=os.path.basename(file_path),
book_format=self.settings['new_book_format'].upper(),
book=book_id, uncompressed_size=os.path.getsize(file_path + format_new_ext))
try:
local_db.session.merge(new_format)
local_db.session.commit()
except SQLAlchemyError as e:
local_db.session.rollback()
log.error("Database error: %s", e)
local_db.session.close()
self._handleError(error_message)
return
self._handleSuccess()
local_db.session.close()
self._handleError(error_message)
return
self._handleSuccess()
local_db.session.close()
return os.path.basename(file_path + format_new_ext)
return os.path.basename(file_path + format_new_ext)
else:
log.info("Book id %d - target format of %s does not exist. Moving forward with convert.",
book_id,
Expand All @@ -153,22 +156,25 @@ def _convert_ebook_format(self):
if check == 0:
cur_book = local_db.get_book(book_id)
if os.path.isfile(file_path + format_new_ext):
new_format = db.Data(name=cur_book.data[0].name,
new_format = local_db.session.query(db.Data).filter(db.Data.book == book_id) \
.filter(db.Data.format == self.settings['new_book_format'].upper()).one_or_none()
if not new_format:
new_format = db.Data(name=cur_book.data[0].name,
book_format=self.settings['new_book_format'].upper(),
book=book_id, uncompressed_size=os.path.getsize(file_path + format_new_ext))
try:
local_db.session.merge(new_format)
local_db.session.commit()
if self.settings['new_book_format'].upper() in ['KEPUB', 'EPUB', 'EPUB3']:
ub_session = ini()
remove_synced_book(book_id, True, ub_session)
ub_session.close()
except SQLAlchemyError as e:
local_db.session.rollback()
log.error("Database error: %s", e)
local_db.session.close()
self._handleError(error_message)
return
try:
local_db.session.merge(new_format)
local_db.session.commit()
if self.settings['new_book_format'].upper() in ['KEPUB', 'EPUB', 'EPUB3']:
ub_session = ini()
remove_synced_book(book_id, True, ub_session)
ub_session.close()
except SQLAlchemyError as e:
local_db.session.rollback()
log.error("Database error: %s", e)
local_db.session.close()
self._handleError(error_message)
return
self.results['path'] = cur_book.path
self.title = cur_book.title
self.results['title'] = self.title
Expand Down
Loading

0 comments on commit 7c62394

Please sign in to comment.