Browse Source

feat: mobi release automatically

master
Dnomd343 2 years ago
parent
commit
0d9bd0737f
  1. 18
      src/release/release.py
  2. 1
      src/release/utils/__init__.py
  3. 48
      src/release/utils/release.py

18
src/release/release.py

@ -6,13 +6,19 @@ from utils import txtRelease
from utils import jsonRelease from utils import jsonRelease
from utils import mobiRelease from utils import mobiRelease
from utils import staticRelease from utils import staticRelease
from utils import calibreRelease
from utils import gitbookRelease from utils import gitbookRelease
releaseEntry = {
'txt': txtRelease,
'json': jsonRelease,
'mobi': mobiRelease,
'static': staticRelease,
'calibre': calibreRelease,
'gitbook': gitbookRelease,
}
metadata, content = loadBook('rc-5')
# txtRelease(metadata, content) releaseSrc = 'rc-5'
# jsonRelease(metadata, content) metadata, content = loadBook(releaseSrc)
mobiRelease(metadata, content) releaseEntry['mobi'](metadata, content)
# staticRelease(metadata, content)
# gitbookRelease(metadata, content)

1
src/release/utils/__init__.py

@ -7,4 +7,5 @@ from .release import txtRelease
from .release import jsonRelease from .release import jsonRelease
from .release import mobiRelease from .release import mobiRelease
from .release import staticRelease from .release import staticRelease
from .release import calibreRelease
from .release import gitbookRelease from .release import gitbookRelease

48
src/release/utils/release.py

@ -32,10 +32,6 @@ def jsonRelease(metadata: dict, content: dict) -> None:
saveFile(releaseInfo['json'], jsonSerialize(metadata, content)) saveFile(releaseInfo['json'], jsonSerialize(metadata, content))
def htmlRelease(metadata: dict, content: dict) -> None:
saveFile(releaseInfo['calibre'], htmlSerialize(metadata, content))
def gitbookRelease(metadata: dict, content: dict) -> None: def gitbookRelease(metadata: dict, content: dict) -> None:
createFolder(releaseInfo['gitbook']) createFolder(releaseInfo['gitbook'])
createFolder(os.path.join(releaseInfo['gitbook'], './assets/')) createFolder(os.path.join(releaseInfo['gitbook'], './assets/'))
@ -177,13 +173,10 @@ def calibreRelease(metadata: dict, content: dict) -> None:
tempDir.cleanup() tempDir.cleanup()
def calibreBuild(workDir: str, suffix: str, extOption: list) -> None: def calibreBuild(workDir: str, suffix: str, extOption: list, metadata: dict, content: dict) -> None:
buildDir = '/xxrs/'
# TODO: xxrs.zip + cover.jpg -> temp folder calibreImage = 'linuxserver/calibre'
calibreCommand = [
# TODO: combine calibre options as command (with file suffix)
command = [
'ebook-convert', 'ebook-convert',
'xxrs.zip', 'xxrs%s' % suffix, 'xxrs.zip', 'xxrs%s' % suffix,
'--output-profile=generic_eink', '--output-profile=generic_eink',
@ -193,16 +186,18 @@ def calibreBuild(workDir: str, suffix: str, extOption: list) -> None:
'--remove-paragraph-spacing', '--remove-paragraph-spacing',
'--remove-paragraph-spacing-indent-size=2', '--remove-paragraph-spacing-indent-size=2',
'--verbose', '--verbose',
] + extOption ]
buildCommand = 'docker run --rm -t -v %s:%s --workdir %s --entrypoint bash %s -c "%s"' % (
workDir, buildDir, buildDir, calibreImage, ' '.join(calibreCommand + extOption)
print(' '.join(command)) )
shutil.copy( # ebook cover
# TODO: start docker container and run calibre build os.path.join(rootPath, './assets/cover.jpg'),
os.path.join(workDir, './cover.jpg')
# TODO: release target format )
os.chdir(workDir)
pass calibreDepends(workDir, metadata, content)
os.system('zip -qr xxrs.zip *') # generate calibre input format
subprocess.Popen(buildCommand, shell = True).wait() # blocking wait
# MOBI Type: KF7 = 0 (old) / KF7 + KF8 = 1 (both) / KF8 = 2 (new) # MOBI Type: KF7 = 0 (old) / KF7 + KF8 = 1 (both) / KF8 = 2 (new)
@ -217,15 +212,8 @@ def mobiRelease(metadata: dict, content: dict, mobiType: int = 1) -> None:
else: else:
print('Unknown MOBI type') print('Unknown MOBI type')
return return
tempDir = tempfile.TemporaryDirectory() # access temporary directory tempDir = tempfile.TemporaryDirectory() # access temporary directory
print('Calibre MOBI Build: %s' % tempDir.name) print('Calibre MOBI Build: %s' % tempDir.name)
shutil.copy( # ebook cover calibreBuild(tempDir.name, '.mobi', mobiOption, metadata, content)
os.path.join(rootPath, './assets/cover.jpg'), shutil.copy(os.path.join(tempDir.name, './xxrs.mobi'), releaseInfo['mobi'])
os.path.join(tempDir.name, './cover.jpg')
)
calibreDepends(tempDir.name, metadata, content)
os.chdir(tempDir.name)
os.system('zip -r xxrs.zip *') # generate calibre input format
calibreBuild(tempDir.name, '.mobi', mobiOption)
tempDir.cleanup() tempDir.cleanup()

Loading…
Cancel
Save