|
|
|
@ -47,6 +47,13 @@ from shutil import move, copyfile
|
|
|
|
|
from tornado.ioloop import IOLoop
|
|
|
|
|
from tornado import version as tornadoVersion
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
from urllib.parse import quote
|
|
|
|
|
from imp import reload
|
|
|
|
|
from past.builtins import xrange
|
|
|
|
|
except ImportError as e:
|
|
|
|
|
from urllib import quote
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
from flask_login import __version__ as flask_loginVersion
|
|
|
|
|
except ImportError, e:
|
|
|
|
@ -56,7 +63,7 @@ try:
|
|
|
|
|
from wand.image import Image
|
|
|
|
|
|
|
|
|
|
use_generic_pdf_cover = False
|
|
|
|
|
except ImportError, e:
|
|
|
|
|
except ImportError as e:
|
|
|
|
|
use_generic_pdf_cover = True
|
|
|
|
|
from cgi import escape
|
|
|
|
|
|
|
|
|
@ -292,7 +299,7 @@ def shortentitle_filter(s):
|
|
|
|
|
def mimetype_filter(val):
|
|
|
|
|
try:
|
|
|
|
|
s = mimetypes.types_map['.' + val]
|
|
|
|
|
except:
|
|
|
|
|
except Exception as e:
|
|
|
|
|
s = 'application/octet-stream'
|
|
|
|
|
return s
|
|
|
|
|
|
|
|
|
@ -773,7 +780,7 @@ def get_updater_status():
|
|
|
|
|
elif request.method == "GET":
|
|
|
|
|
try:
|
|
|
|
|
status['status']=helper.updater_thread.get_update_status()
|
|
|
|
|
except:
|
|
|
|
|
except Exception as e:
|
|
|
|
|
status['status'] = 7
|
|
|
|
|
return json.dumps(status)
|
|
|
|
|
|
|
|
|
@ -788,7 +795,7 @@ def get_languages_json():
|
|
|
|
|
try:
|
|
|
|
|
cur_l = LC.parse(lang.lang_code)
|
|
|
|
|
lang.name = cur_l.get_language_name(get_locale())
|
|
|
|
|
except:
|
|
|
|
|
except Exception as e:
|
|
|
|
|
lang.name = _(isoLanguages.get(part3=lang.lang_code).name)
|
|
|
|
|
entries = [s for s in languages if query in s.name.lower()]
|
|
|
|
|
json_dumps = json.dumps([dict(name=r.name) for r in entries])
|
|
|
|
@ -954,13 +961,13 @@ def language_overview():
|
|
|
|
|
try:
|
|
|
|
|
cur_l = LC.parse(lang.lang_code)
|
|
|
|
|
lang.name = cur_l.get_language_name(get_locale())
|
|
|
|
|
except:
|
|
|
|
|
except Exception as e:
|
|
|
|
|
lang.name = _(isoLanguages.get(part3=lang.lang_code).name)
|
|
|
|
|
else:
|
|
|
|
|
try:
|
|
|
|
|
langfound = 1
|
|
|
|
|
cur_l = LC.parse(current_user.filter_language())
|
|
|
|
|
except:
|
|
|
|
|
except Exception as e:
|
|
|
|
|
langfound = 0
|
|
|
|
|
languages = db.session.query(db.Languages).filter(
|
|
|
|
|
db.Languages.lang_code == current_user.filter_language()).all()
|
|
|
|
@ -984,7 +991,7 @@ def language(name, page):
|
|
|
|
|
try:
|
|
|
|
|
cur_l = LC.parse(name)
|
|
|
|
|
name = cur_l.get_language_name(get_locale())
|
|
|
|
|
except:
|
|
|
|
|
except Exception as e:
|
|
|
|
|
name = _(isoLanguages.get(part3=name).name)
|
|
|
|
|
return render_title_template('index.html', random=random, entries=entries, pagination=pagination,
|
|
|
|
|
title=_(u"Language: %(name)s", name=name))
|
|
|
|
@ -1028,7 +1035,7 @@ def show_book(id):
|
|
|
|
|
try:
|
|
|
|
|
entries.languages[index].language_name = LC.parse(entries.languages[index].lang_code).get_language_name(
|
|
|
|
|
get_locale())
|
|
|
|
|
except:
|
|
|
|
|
except Exception as e:
|
|
|
|
|
entries.languages[index].language_name = _(
|
|
|
|
|
isoLanguages.get(part3=entries.languages[index].lang_code).name)
|
|
|
|
|
cc = db.session.query(db.Custom_Columns).filter(db.Custom_Columns.datatype.notin_(db.cc_exceptions)).all()
|
|
|
|
@ -1069,6 +1076,8 @@ def stats():
|
|
|
|
|
stdin=subprocess.PIPE)
|
|
|
|
|
p.wait()
|
|
|
|
|
for lines in p.stdout.readlines():
|
|
|
|
|
if type(lines) is bytes:
|
|
|
|
|
lines = lines.decode('utf-8')
|
|
|
|
|
if re.search('Amazon kindlegen\(', lines):
|
|
|
|
|
versions['KindlegenVersion'] = lines
|
|
|
|
|
versions['PythonVersion'] = sys.version
|
|
|
|
@ -1177,7 +1186,7 @@ def advanced_search():
|
|
|
|
|
try:
|
|
|
|
|
cur_l = LC.parse(lang.lang_code)
|
|
|
|
|
lang.name = cur_l.get_language_name(get_locale())
|
|
|
|
|
except:
|
|
|
|
|
except Exception as e:
|
|
|
|
|
lang.name = _(isoLanguages.get(part3=lang.lang_code).name)
|
|
|
|
|
searchterm.extend(language.name for language in language_names)
|
|
|
|
|
searchterm = " + ".join(filter(None, searchterm))
|
|
|
|
@ -1209,7 +1218,7 @@ def advanced_search():
|
|
|
|
|
try:
|
|
|
|
|
cur_l = LC.parse(lang.lang_code)
|
|
|
|
|
lang.name = cur_l.get_language_name(get_locale())
|
|
|
|
|
except:
|
|
|
|
|
except Exception as e:
|
|
|
|
|
lang.name = _(isoLanguages.get(part3=lang.lang_code).name)
|
|
|
|
|
else:
|
|
|
|
|
languages = None
|
|
|
|
@ -1311,9 +1320,9 @@ def get_download_link(book_id, format):
|
|
|
|
|
send_from_directory(os.path.join(config.config_calibre_dir, book.path), data.name + "." + format))
|
|
|
|
|
try:
|
|
|
|
|
response.headers["Content-Type"] = mimetypes.types_map['.' + format]
|
|
|
|
|
except:
|
|
|
|
|
except Exception as e:
|
|
|
|
|
pass
|
|
|
|
|
response.headers["Content-Disposition"] = "attachment; filename*=UTF-8''%s.%s" % (urllib.quote(file_name.encode('utf-8')), format)
|
|
|
|
|
response.headers["Content-Disposition"] = "attachment; filename*=UTF-8''%s.%s" % (quote(file_name.encode('utf-8')), format)
|
|
|
|
|
return response
|
|
|
|
|
else:
|
|
|
|
|
abort(404)
|
|
|
|
@ -1343,7 +1352,7 @@ def register():
|
|
|
|
|
try:
|
|
|
|
|
ub.session.add(content)
|
|
|
|
|
ub.session.commit()
|
|
|
|
|
except:
|
|
|
|
|
except Exception as e:
|
|
|
|
|
ub.session.rollback()
|
|
|
|
|
flash(_(u"An unknown error occured. Please try again later."), category="error")
|
|
|
|
|
return render_title_template('register.html', title=_(u"register"))
|
|
|
|
@ -1468,7 +1477,7 @@ def create_shelf():
|
|
|
|
|
ub.session.add(shelf)
|
|
|
|
|
ub.session.commit()
|
|
|
|
|
flash(_(u"Shelf %(title)s created", title=to_save["title"]), category="success")
|
|
|
|
|
except:
|
|
|
|
|
except Exception as e:
|
|
|
|
|
flash(_(u"There was an error"), category="error")
|
|
|
|
|
return render_title_template('shelf_edit.html', shelf=shelf, title=_(u"create a shelf"))
|
|
|
|
|
else:
|
|
|
|
@ -1496,7 +1505,7 @@ def edit_shelf(shelf_id):
|
|
|
|
|
try:
|
|
|
|
|
ub.session.commit()
|
|
|
|
|
flash(_(u"Shelf %(title)s changed", title=to_save["title"]), category="success")
|
|
|
|
|
except:
|
|
|
|
|
except Exception as e:
|
|
|
|
|
flash(_(u"There was an error"), category="error")
|
|
|
|
|
return render_title_template('shelf_edit.html', shelf=shelf, title=_(u"Edit a shelf"))
|
|
|
|
|
else:
|
|
|
|
@ -1584,7 +1593,7 @@ def profile():
|
|
|
|
|
try:
|
|
|
|
|
cur_l = LC.parse(lang.lang_code)
|
|
|
|
|
lang.name = cur_l.get_language_name(get_locale())
|
|
|
|
|
except:
|
|
|
|
|
except Exception as e:
|
|
|
|
|
lang.name = _(isoLanguages.get(part3=lang.lang_code).name)
|
|
|
|
|
translations = babel.list_translations() + [LC('en')]
|
|
|
|
|
for book in content.downloads:
|
|
|
|
@ -1760,7 +1769,7 @@ def new_user():
|
|
|
|
|
try:
|
|
|
|
|
cur_l = LC.parse(lang.lang_code)
|
|
|
|
|
lang.name = cur_l.get_language_name(get_locale())
|
|
|
|
|
except:
|
|
|
|
|
except Exception as e:
|
|
|
|
|
lang.name = _(isoLanguages.get(part3=lang.lang_code).name)
|
|
|
|
|
translations = [LC('en')] + babel.list_translations()
|
|
|
|
|
if request.method == "POST":
|
|
|
|
@ -1858,7 +1867,7 @@ def edit_user(user_id):
|
|
|
|
|
try:
|
|
|
|
|
cur_l = LC.parse(lang.lang_code)
|
|
|
|
|
lang.name = cur_l.get_language_name(get_locale())
|
|
|
|
|
except:
|
|
|
|
|
except Exception as e:
|
|
|
|
|
lang.name = _(isoLanguages.get(part3=lang.lang_code).name)
|
|
|
|
|
translations = babel.list_translations() + [LC('en')]
|
|
|
|
|
for book in content.downloads:
|
|
|
|
@ -1980,7 +1989,7 @@ def edit_book(book_id):
|
|
|
|
|
try:
|
|
|
|
|
book.languages[index].language_name = LC.parse(book.languages[index].lang_code).get_language_name(
|
|
|
|
|
get_locale())
|
|
|
|
|
except:
|
|
|
|
|
except Exception as e:
|
|
|
|
|
book.languages[index].language_name = _(isoLanguages.get(part3=book.languages[index].lang_code).name)
|
|
|
|
|
for author in book.authors:
|
|
|
|
|
author_names.append(author.name)
|
|
|
|
@ -2030,7 +2039,7 @@ def edit_book(book_id):
|
|
|
|
|
for lang in languages:
|
|
|
|
|
try:
|
|
|
|
|
lang.name = LC.parse(lang.lang_code).get_language_name(get_locale()).lower()
|
|
|
|
|
except:
|
|
|
|
|
except Exception as e:
|
|
|
|
|
lang.name = _(isoLanguages.get(part3=lang.lang_code).name).lower()
|
|
|
|
|
for inp_lang in input_languages:
|
|
|
|
|
if inp_lang == lang.name:
|
|
|
|
@ -2216,12 +2225,12 @@ def upload():
|
|
|
|
|
return redirect(url_for('index'))
|
|
|
|
|
try:
|
|
|
|
|
copyfile(meta.file_path, saved_filename)
|
|
|
|
|
except OSError, e:
|
|
|
|
|
except OSError as e:
|
|
|
|
|
flash(_(u"Failed to store file %s (Permission denied)." % saved_filename), category="error")
|
|
|
|
|
return redirect(url_for('index'))
|
|
|
|
|
try:
|
|
|
|
|
os.unlink(meta.file_path)
|
|
|
|
|
except OSError, e:
|
|
|
|
|
except OSError as e:
|
|
|
|
|
flash(_(u"Failed to delete file %s (Permission denied)." % meta.file_path), category="warning")
|
|
|
|
|
|
|
|
|
|
file_size = os.path.getsize(saved_filename)
|
|
|
|
@ -2253,7 +2262,7 @@ def upload():
|
|
|
|
|
db.session.add(db_language)
|
|
|
|
|
# combine path and normalize path from windows systems
|
|
|
|
|
path = os.path.join(author_dir, title_dir).replace('\\','/')
|
|
|
|
|
db_book = db.Books(title, "", db_author.sort, datetime.datetime.now(), datetime.datetime(101, 01, 01), 1,
|
|
|
|
|
db_book = db.Books(title, "", db_author.sort, datetime.datetime.now(), datetime.datetime(101, 1, 1), 1,
|
|
|
|
|
datetime.datetime.now(), path, has_cover, db_author, [], db_language)
|
|
|
|
|
db_book.authors.append(db_author)
|
|
|
|
|
if db_language is not None:
|
|
|
|
|