Browse Source

feat: calibre dependency generation

master
Dnomd343 2 years ago
parent
commit
5d6d8483b8
  1. 4
      src/release/release.py
  2. 2
      src/release/utils/__init__.py
  3. 2
      src/release/utils/common.py
  4. 43
      src/release/utils/release.py

4
src/release/release.py

@ -4,7 +4,7 @@
from utils import loadBook from utils import loadBook
from utils import txtRelease from utils import txtRelease
from utils import jsonRelease from utils import jsonRelease
from utils import htmlRelease from utils import mobiRelease
from utils import staticRelease from utils import staticRelease
from utils import gitbookRelease from utils import gitbookRelease
@ -13,6 +13,6 @@ metadata, content = loadBook('rc-5')
# txtRelease(metadata, content) # txtRelease(metadata, content)
# jsonRelease(metadata, content) # jsonRelease(metadata, content)
htmlRelease(metadata, content) mobiRelease(metadata, content)
# staticRelease(metadata, content) # staticRelease(metadata, content)
# gitbookRelease(metadata, content) # gitbookRelease(metadata, content)

2
src/release/utils/__init__.py

@ -5,6 +5,6 @@ from .common import loadBook
from .release import txtRelease from .release import txtRelease
from .release import jsonRelease from .release import jsonRelease
from .release import htmlRelease from .release import mobiRelease
from .release import staticRelease from .release import staticRelease
from .release import gitbookRelease from .release import gitbookRelease

2
src/release/utils/common.py

@ -20,8 +20,8 @@ releaseInfo = { # release file name
'epub': '栩栩若生.epub', 'epub': '栩栩若生.epub',
'mobi': '栩栩若生.mobi', 'mobi': '栩栩若生.mobi',
'static': 'XXRS.tar.xz', 'static': 'XXRS.tar.xz',
'calibre': 'xxrs.html',
'gitbook': 'xxrs-online/', 'gitbook': 'xxrs-online/',
'calibre': 'xxrs-calibre/',
} }
releaseInfo = { # convert to absolute path releaseInfo = { # convert to absolute path
key: os.path.join(releasePath, file) for (key, file) in releaseInfo.items() key: os.path.join(releasePath, file) for (key, file) in releaseInfo.items()

43
src/release/utils/release.py

@ -129,3 +129,46 @@ def staticRelease(metadata: dict, content: dict) -> None:
staticDepends(tempDir.name, metadata, content) staticDepends(tempDir.name, metadata, content)
staticBuild(tempDir.name) staticBuild(tempDir.name)
tempDir.cleanup() tempDir.cleanup()
def calibreDepends(workDir: str, metadata: dict, content: dict) -> None:
metaInfo = [
'<?xml version="1.0"?>',
'<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">',
'<rootfiles>',
'<rootfile full-path="content.opf" media-type="application/oebps-package+xml"/>',
'</rootfiles>',
'</container>',
]
opfInfo = [
'<?xml version="1.0" encoding="utf-8"?>',
'<package xmlns="http://www.idpf.org/2007/opf" version="2.0" unique-identifier="uuid_id">',
'<opf:metadata xmlns:opf="http://www.idpf.org/2007/opf" xmlns:dc="http://purl.org/dc/elements/1.1/">',
'<dc:title>%s</dc:title>' % metadata['name'],
'<dc:language>zho</dc:language>',
'<dc:publisher>Dnomd343</dc:publisher>',
'<dc:creator opf:file-as="%(aut)s" opf:role="aut">%(aut)s</dc:creator>' % {'aut': metadata['author']},
'<dc:contributor opf:file-as="calibre" opf:role="bkp">%s</dc:contributor>' % projectUrl,
'<dc:description>%s</dc:description>' % '&lt;div&gt;%s&lt;/div&gt;' % (
''.join(['&lt;p&gt;%s&lt;/p&gt;' % x for x in metadata['desc']])
),
'<meta name="calibre:author_link_map" content="{&quot;%s&quot;: &quot;&quot;}"/>' % metadata['author'],
'<meta name="calibre:title_sort" content="%s"/>' % metadata['name'],
'</opf:metadata>',
'<manifest>',
'<item id="html" href="xxrs.html" media-type="application/xhtml+xml"/>',
'<item id="ncx" href="toc.ncx" media-type="application/x-dtbncx+xml"/>',
'</manifest>',
'<spine toc="ncx">', '<itemref idref="html"/>', '</spine>',
'</package>',
]
createFolder(os.path.join(workDir, 'META-INF'))
saveFile(os.path.join(workDir, 'mimetype'), 'application/epub+zip')
saveFile(os.path.join(workDir, 'content.opf'), '\n'.join(opfInfo) + '\n')
saveFile(os.path.join(workDir, 'xxrs.html'), htmlSerialize(metadata, content))
saveFile(os.path.join(workDir, 'META-INF', 'container.xml'), '\n'.join(metaInfo) + '\n')
def mobiRelease(metadata: dict, content: dict) -> None:
createFolder(releaseInfo['calibre'])
calibreDepends(releaseInfo['calibre'], metadata, content)

Loading…
Cancel
Save