Fixes for #233 (detection of permission errors)

pull/245/head
OzzieIsaacs 7 years ago
parent bc665fd067
commit 6a9d8efc93

@ -88,12 +88,11 @@ def make_mobi(book_id, calibrepath):
if os.path.exists(file_path + u".epub"): if os.path.exists(file_path + u".epub"):
try: try:
p = subprocess.Popen((kindlegen + " \"" + file_path + u".epub\"").encode(sys.getfilesystemencoding()), p = subprocess.Popen((kindlegen + " \"" + file_path + u".epub\"").encode(sys.getfilesystemencoding()),
stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
except Exception: except Exception:
error_message = _(u"kindlegen failed, no excecution permissions") error_message = _(u"kindlegen failed, no excecution permissions")
app.logger.error("make_mobi: " + error_message) app.logger.error("make_mobi: " + error_message)
return error_message, RET_FAIL return error_message, RET_FAIL
# Poll process for new output until finished # Poll process for new output until finished
while True: while True:
nextline = p.stdout.readline() nextline = p.stdout.readline()
@ -122,11 +121,13 @@ def make_mobi(book_id, calibrepath):
db.session.commit() db.session.commit()
return file_path + ".mobi", RET_SUCCESS return file_path + ".mobi", RET_SUCCESS
else: else:
app.logger.error("make_mobi: kindlegen failed with error while converting book") app.logger.info("make_mobi: kindlegen failed with error while converting book")
return None, RET_FAIL if not error_message:
error_message='kindlegen failed, no excecution permissions'
return error_message, RET_FAIL
else: else:
app.logger.error("make_mobi: epub not found: %s.epub" % file_path) error_message = "make_mobi: epub not found: %s.epub" % file_path
return None, RET_FAIL return error_message, RET_FAIL
class StderrLogger(object): class StderrLogger(object):
@ -226,11 +227,10 @@ def send_mail(book_id, kindle_mail, calibrepath):
msg.attach(get_attachment(formats['mobi'])) msg.attach(get_attachment(formats['mobi']))
elif 'epub' in formats: elif 'epub' in formats:
data, resultCode = make_mobi(book.id, calibrepath) data, resultCode = make_mobi(book.id, calibrepath)
app.logger.error = (data)
if resultCode == RET_SUCCESS: if resultCode == RET_SUCCESS:
msg.attach(get_attachment(data)) msg.attach(get_attachment(data))
else: else:
app.logger.error = (data)
return data #_("Could not convert epub to mobi") return data #_("Could not convert epub to mobi")
elif 'pdf' in formats: elif 'pdf' in formats:
msg.attach(get_attachment(formats['pdf'])) msg.attach(get_attachment(formats['pdf']))

Loading…
Cancel
Save