【发布时间】:2018-01-17 23:14:38
【问题描述】:
所以我终于弄清楚了我的 GenEpub.py 程序的主要问题,以及为什么它会产生如 zip -t 和 zipinfo 所证明的压缩的、有效的 zip 文件,但它未能通过 epubcheck 的最终测试。
问题如下,下面的脚本写入了本例中称为IdealogicalEcho的整个文件夹,然后按照说明将其压缩并将压缩文件本身命名为IdealogicalEcho.epub。 epubcheck 但是看不到这个文件夹,然后报告三个核心 ePub 文件都找不到 mimetype META-INF OEBPS。
有没有办法将这些文件移动到 zip 目录的根目录?压缩前还是压缩后?
https://github.com/inferno986return/Damore-essay-ebook
这是EpubGen.py的当前版本:
#!/usr/bin/env python
#GenEpub.py - Generates an .epub file from the data provided.
#Ideally with no errors or warnings from epubcheck (needs to be implemented, maybe with the Python wrapper).
import os
import json
import zipfile
with open('metadata.json') as json_file:
data = json.load(json_file)
#The ePub standard requires deflated compression and a compression order.
zf = zipfile.ZipFile(data["fileName"] + '.epub', mode='w', compression=zipfile.ZIP_STORED)
zf.write(data["fileName"] + '/mimetype')
for dirname, subdirs, files in os.walk(data["fileName"] + '/META-INF'):
zf.write(dirname)
for filename in files:
zf.write(os.path.join(dirname, filename))
for dirname, subdirs, files in os.walk(data["fileName"] + '/OEBPS'):
zf.write(dirname)
for filename in files:
zf.write(os.path.join(dirname, filename))
zf.close()
#zipfile has a built-in validator for debugging
with open(data["fileName"] + '.epub','r') as f:
if zipfile.is_zipfile(f) is True:
print("ZIP file is valid.")
#Extra debugging information
#print(getinfo.compress_type(zf))
#print(getinfo.compress_size(zf))
#print(getinfo.file_size(zf))
还有metadata.json:
{
"comment1": "Metadata.json - Insert the e-book's metadata here. WIP",
"comment2": "Technical metadata - This is the where the cover image is specified. Recommended to use ePub V2.0.1 over 3.0 for epubVersion and Reflowable rather than Fixed for textPresentation (unless doing a project that requires a specific layout). mobiCover and generateKindle are currently unused but added for futureproofing.",
"epubCover": "cover.jpg",
"mobiCover": "cover.jpg",
"fileName": "IdealogicalEcho",
"epubVersion": "2.0.1",
"textPresentation": "Reflowable",
"generateKindle": "no",
"comment3": "Book metadata - Information about the e-book itself. Language is specified with ISO 639-1. Rights can be worldwide, country specific or under a permissable license such as Creative-Commons SA",
"title": "Google's Idealogical Echochamber: How bias clouds our thinking about diversity and inclusion",
"creator": "James Damore",
"subject": "Academic",
"publisher": "Hal Motley",
"ISBN": "-",
"language": "en",
"rights": "Creative Commons BY-SA 4.0",
"comment4": "This is the page order that the e-book has. The first number before the colon is the page order, the second is the indentation, third is the page name and fourth is file itself.",
"pages": [
{
"pageNumber": "0",
"indentation": "0",
"pageName": "Cover",
"fileName": "bookcover.xhtml"
},
{
"pageNumber": "1",
"indentation": "0",
"pageName": "Title",
"fileName": "title.xhtml"
},
{
"pageNumber": "2",
"indentation": "0",
"pageName": "Indicia",
"fileName": "indicia.xhtml"
},
{
"pageNumber": "3",
"indentation": "0",
"pageName": "License",
"fileName": "license.xhtml"
},
{
"pageNumber": "4",
"indentation": "0",
"pageName": "Contents",
"fileName": "toc.xhtml"
},
{
"pageNumber": "5",
"indentation": "0",
"pageName": "Foreword",
"fileName": "foreword.xhtml"
},
{
"pageNumber": "6",
"indentation": "0",
"pageName": "Article",
"fileName": "article.xhtml"
}
]
}
【问题讨论】: