Working again (basically)
This commit is contained in:
@@ -27,11 +27,11 @@ import socket
|
||||
import sys
|
||||
import os
|
||||
from email.generator import Generator
|
||||
import web
|
||||
from cps import config, db # , app
|
||||
# import web
|
||||
from flask_babel import gettext as _
|
||||
import re
|
||||
import gdriveutils as gd
|
||||
# import subprocess
|
||||
# import gdriveutils as gd
|
||||
from subproc_wrapper import process_open
|
||||
|
||||
|
||||
@@ -70,8 +70,8 @@ RET_SUCCESS = 1
|
||||
# it in MIME Base64 encoded to
|
||||
def get_attachment(bookpath, filename):
|
||||
"""Get file as MIMEBase message"""
|
||||
calibrepath = web.config.config_calibre_dir
|
||||
if web.ub.config.config_use_google_drive:
|
||||
calibrepath = config.config_calibre_dir
|
||||
if config.config_use_google_drive:
|
||||
df = gd.getFileFromEbooksFolder(bookpath, filename)
|
||||
if df:
|
||||
datafile = os.path.join(calibrepath, bookpath, filename)
|
||||
@@ -90,8 +90,8 @@ def get_attachment(bookpath, filename):
|
||||
data = file_.read()
|
||||
file_.close()
|
||||
except IOError as e:
|
||||
web.app.logger.exception(e) # traceback.print_exc()
|
||||
web.app.logger.error(u'The requested file could not be read. Maybe wrong permissions?')
|
||||
# web.app.logger.exception(e) # traceback.print_exc()
|
||||
# web.app.logger.error(u'The requested file could not be read. Maybe wrong permissions?')
|
||||
return None
|
||||
|
||||
attachment = MIMEBase('application', 'octet-stream')
|
||||
@@ -235,7 +235,7 @@ class WorkerThread(threading.Thread):
|
||||
curr_task = self.queue[self.current]['taskType']
|
||||
filename = self._convert_ebook_format()
|
||||
if filename:
|
||||
if web.ub.config.config_use_google_drive:
|
||||
if config.config_use_google_drive:
|
||||
gd.updateGdriveCalibreFromLocal()
|
||||
if curr_task == TASK_CONVERT:
|
||||
self.add_email(self.queue[self.current]['settings']['subject'], self.queue[self.current]['path'],
|
||||
@@ -254,8 +254,8 @@ class WorkerThread(threading.Thread):
|
||||
# if it does - mark the conversion task as complete and return a success
|
||||
# this will allow send to kindle workflow to continue to work
|
||||
if os.path.isfile(file_path + format_new_ext):
|
||||
web.app.logger.info("Book id %d already converted to %s", bookid, format_new_ext)
|
||||
cur_book = web.db.session.query(web.db.Books).filter(web.db.Books.id == bookid).first()
|
||||
# web.app.logger.info("Book id %d already converted to %s", bookid, format_new_ext)
|
||||
cur_book = db.session.query(db.Books).filter(db.Books.id == bookid).first()
|
||||
self.queue[self.current]['path'] = file_path
|
||||
self.queue[self.current]['title'] = cur_book.title
|
||||
self._handleSuccess()
|
||||
@@ -264,23 +264,23 @@ class WorkerThread(threading.Thread):
|
||||
web.app.logger.info("Book id %d - target format of %s does not exist. Moving forward with convert.", bookid, format_new_ext)
|
||||
|
||||
# check if converter-executable is existing
|
||||
if not os.path.exists(web.ub.config.config_converterpath):
|
||||
if not os.path.exists(config.config_converterpath):
|
||||
# ToDo Text is not translated
|
||||
self._handleError(u"Convertertool %s not found" % web.ub.config.config_converterpath)
|
||||
self._handleError(u"Convertertool %s not found" % config.config_converterpath)
|
||||
return
|
||||
|
||||
try:
|
||||
# check which converter to use kindlegen is "1"
|
||||
if format_old_ext == '.epub' and format_new_ext == '.mobi':
|
||||
if web.ub.config.config_ebookconverter == 1:
|
||||
if config.config_ebookconverter == 1:
|
||||
'''if os.name == 'nt':
|
||||
command = web.ub.config.config_converterpath + u' "' + file_path + u'.epub"'
|
||||
if sys.version_info < (3, 0):
|
||||
command = command.encode(sys.getfilesystemencoding())
|
||||
else:'''
|
||||
command = [web.ub.config.config_converterpath, file_path + u'.epub']
|
||||
command = [config.config_converterpath, file_path + u'.epub']
|
||||
quotes = (1)
|
||||
if web.ub.config.config_ebookconverter == 2:
|
||||
if config.config_ebookconverter == 2:
|
||||
# Linux py2.7 encode as list without quotes no empty element for parameters
|
||||
# linux py3.x no encode and as list without quotes no empty element for parameters
|
||||
# windows py2.7 encode as string with quotes empty element for parameters is okay
|
||||
@@ -293,11 +293,11 @@ class WorkerThread(threading.Thread):
|
||||
if sys.version_info < (3, 0):
|
||||
command = command.encode(sys.getfilesystemencoding())
|
||||
else:'''
|
||||
command = [web.ub.config.config_converterpath, (file_path + format_old_ext),
|
||||
command = [config.config_converterpath, (file_path + format_old_ext),
|
||||
(file_path + format_new_ext)]
|
||||
index = 3
|
||||
if web.ub.config.config_calibre:
|
||||
parameters = web.ub.config.config_calibre.split(" ")
|
||||
if config.config_calibre:
|
||||
parameters = config.config_calibre.split(" ")
|
||||
for param in parameters:
|
||||
command.append(param)
|
||||
quotes.append(index)
|
||||
@@ -308,7 +308,7 @@ class WorkerThread(threading.Thread):
|
||||
self._handleError(_(u"Ebook-converter failed: %(error)s", error=e))
|
||||
return
|
||||
|
||||
if web.ub.config.config_ebookconverter == 1:
|
||||
if config.config_ebookconverter == 1:
|
||||
nextline = p.communicate()[0]
|
||||
# Format of error message (kindlegen translates its output texts):
|
||||
# Error(prcgen):E23006: Language not recognized in metadata.The dc:Language field is mandatory.Aborting.
|
||||
@@ -336,24 +336,24 @@ class WorkerThread(threading.Thread):
|
||||
# 0 = Info(prcgen):I1036: Mobi file built successfully
|
||||
# 1 = Info(prcgen):I1037: Mobi file built with WARNINGS!
|
||||
# 2 = Info(prcgen):I1038: MOBI file could not be generated because of errors!
|
||||
if (check < 2 and web.ub.config.config_ebookconverter == 1) or \
|
||||
(check == 0 and web.ub.config.config_ebookconverter == 2):
|
||||
cur_book = web.db.session.query(web.db.Books).filter(web.db.Books.id == bookid).first()
|
||||
if (check < 2 and config.config_ebookconverter == 1) or \
|
||||
(check == 0 and config.config_ebookconverter == 2):
|
||||
cur_book = db.session.query(db.Books).filter(db.Books.id == bookid).first()
|
||||
if os.path.isfile(file_path + format_new_ext):
|
||||
new_format = web.db.Data(name=cur_book.data[0].name,
|
||||
new_format = db.Data(name=cur_book.data[0].name,
|
||||
book_format=self.queue[self.current]['settings']['new_book_format'].upper(),
|
||||
book=bookid, uncompressed_size=os.path.getsize(file_path + format_new_ext))
|
||||
cur_book.data.append(new_format)
|
||||
web.db.session.commit()
|
||||
db.session.commit()
|
||||
self.queue[self.current]['path'] = cur_book.path
|
||||
self.queue[self.current]['title'] = cur_book.title
|
||||
if web.ub.config.config_use_google_drive:
|
||||
if config.config_use_google_drive:
|
||||
os.remove(file_path + format_old_ext)
|
||||
self._handleSuccess()
|
||||
return file_path + format_new_ext
|
||||
else:
|
||||
error_message = format_new_ext.upper() + ' format not found on disk'
|
||||
web.app.logger.info("ebook converter failed with error while converting book")
|
||||
# web.app.logger.info("ebook converter failed with error while converting book")
|
||||
if not error_message:
|
||||
error_message = 'Ebook converter failed with unknown error'
|
||||
self._handleError(error_message)
|
||||
|
||||
Reference in New Issue
Block a user