From a2e2f46426be68d096cc3721f3082565caabe300 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Sun, 19 Mar 2023 14:54:59 +0800 Subject: [PATCH] feat: command line parameters of release script --- src/release/release.py | 15 +++++++++------ src/release/utils/common.py | 5 ++++- src/release/utils/release.py | 11 +++++------ 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/release/release.py b/src/release/release.py index 02babd1..82ece9d 100755 --- a/src/release/release.py +++ b/src/release/release.py @@ -1,6 +1,8 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- +import sys +import multiprocessing from copy import deepcopy from concurrent import futures @@ -14,17 +16,17 @@ from utils import staticRelease from utils import calibreRelease from utils import gitbookRelease -# TODO: update gitbook links ''' In order to avoid unintentional modification of the content, using deepcopy function here. ''' def allRelease(metadata: dict, content: dict) -> None: + cpuCount = multiprocessing.cpu_count() txtRelease(deepcopy(metadata), deepcopy(content)) jsonRelease(deepcopy(metadata), deepcopy(content)) gitbookRelease(deepcopy(metadata), deepcopy(content)) - threadPool = futures.ThreadPoolExecutor(max_workers = 4) + threadPool = futures.ThreadPoolExecutor(max_workers = cpuCount) azw3Task = threadPool.submit(azw3Release, deepcopy(metadata), deepcopy(content)) epubTask = threadPool.submit(epubRelease, deepcopy(metadata), deepcopy(content)) mobiTask = threadPool.submit(mobiRelease, deepcopy(metadata), deepcopy(content)) @@ -33,7 +35,7 @@ def allRelease(metadata: dict, content: dict) -> None: print('All build complete') -releaseEntry = { +releaseEntry = { # release functions 'all': allRelease, 'txt': txtRelease, 'json': jsonRelease, @@ -46,6 +48,7 @@ releaseEntry = { } -releaseSrc = 'rc-5' -bookMetadata, bookContent = loadBook(releaseSrc) -releaseEntry['all'](bookMetadata, bookContent) +if sys.argv[1] not in releaseEntry: + print('Unknown target `%s` in %s' % (sys.argv[1], [x for x in releaseEntry])) +bookMetadata, bookContent = loadBook(sys.argv[2]) +releaseEntry[sys.argv[1]](bookMetadata, bookContent) diff --git a/src/release/utils/common.py b/src/release/utils/common.py index 735214c..e36a9e3 100644 --- a/src/release/utils/common.py +++ b/src/release/utils/common.py @@ -4,7 +4,6 @@ import os import json -projectDesc = '《栩栩若生》电子书' projectUrl = 'https://github.com/dnomd343/xxrs-crawler' rootPath = os.path.join( # project root directory @@ -33,6 +32,10 @@ resourceInfo = { # resource download links 'https://res.343.re/Share/XXRS/%E6%A0%A9%E6%A0%A9%E8%8B%A5%E7%94%9F.txt', 'https://cdn.dnomd343.top/xxrs/%E6%A0%A9%E6%A0%A9%E8%8B%A5%E7%94%9F.txt', ], + 'AZW3 下载': [ + 'https://res.343.re/Share/XXRS/%E6%A0%A9%E6%A0%A9%E8%8B%A5%E7%94%9F.azw3', + 'https://cdn.dnomd343.top/xxrs/%E6%A0%A9%E6%A0%A9%E8%8B%A5%E7%94%9F.azw3', + ], 'EPUB 下载': [ 'https://res.343.re/Share/XXRS/%E6%A0%A9%E6%A0%A9%E8%8B%A5%E7%94%9F.epub', 'https://cdn.dnomd343.top/xxrs/%E6%A0%A9%E6%A0%A9%E8%8B%A5%E7%94%9F.epub', diff --git a/src/release/utils/release.py b/src/release/utils/release.py index cfa9edc..ba2e385 100644 --- a/src/release/utils/release.py +++ b/src/release/utils/release.py @@ -11,7 +11,6 @@ from .common import isRoot from .common import rootPath from .common import saveFile from .common import projectUrl -from .common import projectDesc from .common import releaseInfo from .common import createFolder from .common import resourceInfo @@ -40,7 +39,7 @@ def gitbookRelease(metadata: dict, content: dict) -> None: cover = gitbookMetadata(metadata) for (resName, resUrls) in resourceInfo.items(): cover += '{% hint style="success" %}\n' \ - + '### >>> [%s](%s) <<<\n' % (resName, resUrls[0]) \ + + '### [%s](%s)([备用地址](%s))\n' % (resName, resUrls[1], resUrls[0]) \ + '{% endhint %}\n\n' cover += '{%% embed url="%s" %%}\n项目地址\n{%% endembed %%}\n' % projectUrl @@ -60,14 +59,14 @@ def staticDepends(workDir: str, metadata: dict, content: dict) -> None: cover = gitbookMetadata(metadata) + '
\n' for (resName, resUrls) in resourceInfo.items(): - cover += '\n{% hint style="tip" %}\n' \ - + '#### [%s](%s)([备用地址](%s))\n' % (resName, resUrls[0], resUrls[1]) \ + cover += '\n{% hint style="none" %}\n' \ + + '#### [%s](%s)([备用地址](%s))\n' % (resName, resUrls[1], resUrls[0]) \ + '{% endhint %}\n' bookInfo = json.dumps({ 'title': metadata['name'], 'author': metadata['author'], - 'description': projectDesc, + 'description': '《%s》在线阅读' % metadata['name'], "language": "zh-hans", 'plugins': [ '-lunr', '-search', '-sharing', 'hints', 'github', @@ -174,7 +173,7 @@ def calibreRelease(metadata: dict, content: dict) -> None: def calibreBuild(workDir: str, suffix: str, extOption: list, metadata: dict, content: dict) -> None: buildDir = '/xxrs/' - calibreImage = 'linuxserver/calibre' + calibreImage = 'linuxserver/calibre:6.14.1' calibreCommand = [ 'ebook-convert', 'xxrs.zip', 'xxrs%s' % suffix,