1
0
mirror of https://github.com/janeczku/calibre-web synced 2024-11-24 18:47:23 +00:00

No error 500 if kindlegen is not excecutable

This commit is contained in:
OzzieIsaacs 2017-05-25 09:30:20 +02:00
parent 0a08a07193
commit e6c6c26fd1
2 changed files with 19 additions and 10 deletions

View File

@ -86,8 +86,14 @@ def make_mobi(book_id, calibrepath):
file_path = os.path.join(calibrepath, book.path, data.name) file_path = os.path.join(calibrepath, book.path, data.name)
if os.path.exists(file_path + u".epub"): if os.path.exists(file_path + u".epub"):
p = subprocess.Popen((kindlegen + " \"" + file_path + u".epub\"").encode(sys.getfilesystemencoding()), try:
stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) p = subprocess.Popen((kindlegen + " \"" + file_path + u".epub\"").encode(sys.getfilesystemencoding()),
stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
except:
error_message = _(u"kindlegen failed, no excecution permissions")
app.logger.error("make_mobi: "+error_message)
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()
@ -117,7 +123,7 @@ def make_mobi(book_id, calibrepath):
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.error("make_mobi: kindlegen failed with error while converting book")
return error_message, RET_FAIL return None, RET_FAIL
else: else:
app.logger.error("make_mobi: epub not found: %s.epub" % file_path) app.logger.error("make_mobi: epub not found: %s.epub" % file_path)
return None, RET_FAIL return None, RET_FAIL

View File

@ -1261,13 +1261,16 @@ def stats():
kindlegen = os.path.join(vendorpath, u"kindlegen") kindlegen = os.path.join(vendorpath, u"kindlegen")
versions['KindlegenVersion'] = _('not installed') versions['KindlegenVersion'] = _('not installed')
if os.path.exists(kindlegen): if os.path.exists(kindlegen):
p = subprocess.Popen(kindlegen, stdout=subprocess.PIPE, stderr=subprocess.PIPE) try:
p.wait() p = subprocess.Popen(kindlegen, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
for lines in p.stdout.readlines(): p.wait()
if isinstance(lines, bytes): for lines in p.stdout.readlines():
lines = lines.decode('utf-8') if isinstance(lines, bytes):
if re.search('Amazon kindlegen\(', lines): lines = lines.decode('utf-8')
versions['KindlegenVersion'] = lines if re.search('Amazon kindlegen\(', lines):
versions['KindlegenVersion'] = lines
except:
versions['KindlegenVersion'] = _('Excecution permissions missing')
versions['PythonVersion'] = sys.version versions['PythonVersion'] = sys.version
versions['babel'] = babelVersion versions['babel'] = babelVersion
versions['sqlalchemy'] = sqlalchemyVersion versions['sqlalchemy'] = sqlalchemyVersion