Merge remote-tracking branch 'chinese_translation/master'

This commit is contained in:
OzzieIsaacs 2017-03-31 16:52:25 +02:00
commit 00462237fe
5 changed files with 52 additions and 49 deletions

View File

@ -7,12 +7,13 @@ import os
import uploader
from iso639 import languages as isoLanguages
def extractCover(zip, coverFile, coverpath, tmp_file_name):
def extractCover(zipFile, coverFile, coverpath, tmp_file_name):
if coverFile is None:
return None
else:
zipCoverPath = os.path.join(coverpath , coverFile).replace('\\','/')
cf = zip.read(zipCoverPath)
cf = zipFile.read(zipCoverPath)
prefix = os.path.splitext(tmp_file_name)[0]
tmp_cover_name = prefix + '.' + os.path.basename(zipCoverPath)
image = open(tmp_cover_name, 'wb')
@ -28,12 +29,12 @@ def get_epub_info(tmp_file_path, original_file_name, original_file_extension):
'dc': 'http://purl.org/dc/elements/1.1/'
}
zip = zipfile.ZipFile(tmp_file_path)
epubZip = zipfile.ZipFile(tmp_file_path)
txt = zip.read('META-INF/container.xml')
txt = epubZip.read('META-INF/container.xml')
tree = etree.fromstring(txt)
cfname = tree.xpath('n:rootfiles/n:rootfile/@full-path', namespaces=ns)[0]
cf = zip.read(cfname)
cf = epubZip.read(cfname)
tree = etree.fromstring(cf)
coverpath = os.path.dirname(cfname)
@ -70,7 +71,7 @@ def get_epub_info(tmp_file_path, original_file_name, original_file_extension):
coversection = tree.xpath("/pkg:package/pkg:manifest/pkg:item[@id='cover-image']/@href", namespaces=ns)
coverfile = None
if len(coversection) > 0:
coverfile = extractCover(zip, coversection[0], coverpath, tmp_file_path)
coverfile = extractCover(epubZip, coversection[0], coverpath, tmp_file_path)
else:
meta_cover = tree.xpath("/pkg:package/pkg:metadata/pkg:meta[@name='cover']/@content", namespaces=ns)
if len(meta_cover) > 0:
@ -78,15 +79,15 @@ def get_epub_info(tmp_file_path, original_file_name, original_file_extension):
if len(coversection) > 0:
filetype = coversection[0].rsplit('.', 1)[-1]
if filetype == "xhtml" or filetype == "html": #if cover is (x)html format
markup = zip.read(os.path.join(coverpath,coversection[0]))
markup = epubZip.read(os.path.join(coverpath, coversection[0]))
markupTree = etree.fromstring(markup)
# no matter xhtml or html with no namespace
imgsrc = markupTree.xpath("//*[local-name() = 'img']/@src")
# imgsrc maybe startwith "../"" so fullpath join then relpath to cwd
filename = os.path.relpath(os.path.join(os.path.dirname(os.path.join(coverpath, coversection[0])), imgsrc[0]))
coverfile = extractCover(zip, filename, "", tmp_file_path)
coverfile = extractCover(epubZip, filename, "", tmp_file_path)
else:
coverfile = extractCover(zip, coversection[0], coverpath, tmp_file_path)
coverfile = extractCover(epubZip, coversection[0], coverpath, tmp_file_path)
if epub_metadata['title'] is None:
title = original_file_name

View File

@ -295,6 +295,7 @@ def update_dir_stucture(book_id, calibrepath):
book.path = new_authordir + '/' + book.path.split('/')[1]
db.session.commit()
def update_dir_structure_gdrive(book_id):
db.session.connection().connection.connection.create_function("title_sort", 1, db.title_sort)
book = db.session.query(db.Books).filter(db.Books.id == book_id).first()
@ -462,7 +463,7 @@ class Updater(threading.Thread):
else:
try:
logging.getLogger('cps.web').debug("Delete file " + item_path)
log_from_thread("Delete file " + item_path)
# log_from_thread("Delete file " + item_path)
os.remove(item_path)
except Exception:
logging.getLogger('cps.web').debug("Could not remove:" + item_path)

View File

@ -307,7 +307,7 @@ msgstr "用户 '%(user)s' 已被创建"
#: cps/web.py:2198
msgid "Found an existing account for this email address or nickname."
msgstr "已找到使用此邮箱或昵称的账号。"
msgstr "已存在使用此邮箱或昵称的账号。"
#: cps/web.py:2220
msgid "Mail settings updated"
@ -496,7 +496,7 @@ msgstr "最新提交时间戳"
#: cps/templates/admin.html:83
msgid "Reconnect to Calibre DB"
msgstr ""
msgstr "重新连接到Calibre数据库"
#: cps/templates/admin.html:84
msgid "Restart Calibre-web"
@ -590,7 +590,7 @@ msgstr "编辑后查看书籍"
#: cps/templates/book_edit.html:107 cps/templates/book_edit.html:118
msgid "Get metadata"
msgstr ""
msgstr "获取元数据"
#: cps/templates/book_edit.html:108 cps/templates/config_edit.html:117
#: cps/templates/login.html:19 cps/templates/search_form.html:79
@ -600,11 +600,11 @@ msgstr "提交"
#: cps/templates/book_edit.html:121
msgid "Keyword"
msgstr ""
msgstr "关键字"
#: cps/templates/book_edit.html:122
msgid " Search keyword "
msgstr ""
msgstr "搜索关键字"
#: cps/templates/book_edit.html:124 cps/templates/layout.html:60
msgid "Go!"
@ -612,32 +612,32 @@ msgstr "走起!"
#: cps/templates/book_edit.html:125
msgid "Click the cover to load metadata to the form"
msgstr ""
msgstr "点击封面加载元数据到表单"
#: cps/templates/book_edit.html:129 cps/templates/book_edit.html:142
msgid "Loading..."
msgstr ""
msgstr "加载中..."
#: cps/templates/book_edit.html:132
msgid "Close"
msgstr ""
msgstr "关闭"
#: cps/templates/book_edit.html:143
msgid "Search error!"
msgstr ""
msgstr "搜索错误"
#: cps/templates/book_edit.html:144
msgid "No Result! Please try anonther keyword."
msgstr ""
msgstr "没有结果!请尝试别的关键字."
#: cps/templates/book_edit.html:146 cps/templates/detail.html:76
#: cps/templates/search_form.html:14
msgid "Publisher"
msgstr ""
msgstr "出版社"
#: cps/templates/book_edit.html:148
msgid "Source"
msgstr ""
msgstr "来源"
#: cps/templates/config_edit.html:7
msgid "Location of Calibre database"
@ -645,7 +645,7 @@ msgstr "Calibre 数据库位置"
#: cps/templates/config_edit.html:13
msgid "Use google drive?"
msgstr ""
msgstr "是否使用google drive?"
#: cps/templates/config_edit.html:17
msgid "Client id"
@ -660,8 +660,8 @@ msgid "Calibre Base URL"
msgstr ""
#: cps/templates/config_edit.html:29
msgid "Google drive Calibre folder"
msgstr ""
msgid "Google drive Calibre folde"
msgstr "Google drive Calibre 文件夹"
#: cps/templates/config_edit.html:38
msgid "Metadata Watch Channel ID"
@ -843,12 +843,12 @@ msgstr "显示随机书籍"
#: cps/templates/index.xml:43 cps/templates/index.xml:47
#: cps/templates/layout.html:132
msgid "Read Books"
msgstr ""
msgstr "已读书籍"
#: cps/templates/index.xml:50 cps/templates/index.xml:54
#: cps/templates/layout.html:133
msgid "Unread Books"
msgstr ""
msgstr "未读书籍"
#: cps/templates/index.xml:57 cps/templates/layout.html:144
msgid "Authors"
@ -1082,7 +1082,7 @@ msgstr "显示作者选择"
#: cps/templates/user_edit.html:75
msgid "Show read and unread"
msgstr ""
msgstr "显示已读和未读"
#: cps/templates/user_edit.html:79
msgid "Show random books in detail view"

View File

@ -131,6 +131,7 @@ class Singleton:
def __instancecheck__(self, inst):
return isinstance(inst, self._decorated)
@Singleton
class Gauth:
def __init__(self):
@ -1466,7 +1467,7 @@ def advanced_search():
try:
cur_l = LC.parse(lang.lang_code)
lang.name = cur_l.get_language_name(get_locale())
except Exception as e:
except Exception:
lang.name = _(isoLanguages.get(part3=lang.lang_code).name)
else:
languages = None