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