diff --git a/.github/workflows/package-linux.yml b/.github/workflows/package-linux.yml index 10e1306..fdc512c 100644 --- a/.github/workflows/package-linux.yml +++ b/.github/workflows/package-linux.yml @@ -34,7 +34,7 @@ jobs: - name: Install python dependencies run: | sudo apt-get update - sudo apt-get install -y libpng-dev libjpeg-dev 7zip python3-pip squashfs-tools libfuse2 libxcb-cursor0 + sudo apt-get install -y libpng-dev libjpeg-dev p7zip-full p7zip-rar python3-pip squashfs-tools libfuse2 libxcb-cursor0 python -m pip install --upgrade pip setuptools wheel certifi pyinstaller --no-binary pyinstaller python -m pip install -r requirements.txt - name: build binary diff --git a/Dockerfile-base b/Dockerfile-base index 9f2f6d9..a8418b4 100644 --- a/Dockerfile-base +++ b/Dockerfile-base @@ -8,7 +8,7 @@ RUN echo "I'm building for $TARGETOS/$TARGETARCH/$TARGETVARIANT" COPY requirements.txt /opt/kcc/ ENV PATH="/opt/venv/bin:$PATH" RUN DEBIAN_FRONTEND=noninteractive apt-get update -y && apt-get -yq upgrade && \ - apt-get install -y libpng-dev libjpeg-dev 7zip unrar-free libgl1 && \ + apt-get install -y libpng-dev libjpeg-dev p7zip-full unrar-free libgl1 && \ python -m pip install --upgrade pip && \ python -m venv /opt/venv && \ python -m pip install -r /opt/kcc/requirements.txt @@ -55,7 +55,7 @@ RUN set -x && \ KEPT_PACKAGES+=(locales-all) && \ KEPT_PACKAGES+=(libfreetype6) && \ KEPT_PACKAGES+=(libfontconfig1) && \ - KEPT_PACKAGES+=(7zip) && \ + KEPT_PACKAGES+=(p7zip-full) && \ KEPT_PACKAGES+=(python3) && \ KEPT_PACKAGES+=(python3-pip) && \ KEPT_PACKAGES+=(unrar-free) && \ @@ -113,7 +113,7 @@ RUN set -x && \ KEPT_PACKAGES+=(locales-all) && \ KEPT_PACKAGES+=(libfreetype6) && \ KEPT_PACKAGES+=(libfontconfig1) && \ - KEPT_PACKAGES+=(7zip) && \ + KEPT_PACKAGES+=(p7zip-full) && \ KEPT_PACKAGES+=(python3) && \ KEPT_PACKAGES+=(python3-pip) && \ KEPT_PACKAGES+=(unrar-free) && \ @@ -158,7 +158,7 @@ LABEL org.opencontainers.image.title="Kindle Comic Converter" ENV PATH="/opt/venv/bin:$PATH" WORKDIR /app RUN DEBIAN_FRONTEND=noninteractive apt-get update -y && apt-get -yq upgrade && \ - apt-get install -y 7zip unrar-free && \ + apt-get install -y p7zip-full unrar-free && \ ln -s /app/kindlegen /bin/kindlegen && \ echo docker-base-20241116 > /IMAGE_VERSION diff --git a/README.md b/README.md index 85984eb..920bae2 100644 --- a/README.md +++ b/README.md @@ -155,7 +155,7 @@ Please check [our wiki](https://github.com/ciromattia/kcc/wiki/) for more detail CLI version of **KCC** is intended for power users. It allows using options that might not be compatible and decrease the quality of output. CLI version has reduced dependencies, on Debian based distributions this commands should install all needed dependencies: ``` -sudo apt-get install python3 7zip python3-pil python3-psutil python3-slugify +sudo apt-get install python3 p7zip-full python3-pil python3-psutil python3-slugify ``` ### Profiles: diff --git a/kindlecomicconverter/KCC_gui.py b/kindlecomicconverter/KCC_gui.py index 2bff604..cc8e38b 100644 --- a/kindlecomicconverter/KCC_gui.py +++ b/kindlecomicconverter/KCC_gui.py @@ -40,10 +40,10 @@ from packaging.version import Version from raven import Client from tempfile import gettempdir -from .shared import HTMLStripper, sanitizeTrace, walkLevel, subprocess_run -from .comicarchive import SEVENZIP, available_archive_tools +from .shared import HTMLStripper, available_archive_tools, sanitizeTrace, walkLevel, subprocess_run from . import __version__ from . import comic2ebook +from . import image from . import metadata from . import kindle from . import KCC_ui @@ -1166,7 +1166,7 @@ class KCCGUI(KCC_ui.Ui_mainWindow): 'info') self.tar = 'tar' in available_archive_tools() - self.sevenzip = SEVENZIP in available_archive_tools() + self.sevenzip = '7z' in available_archive_tools() if not any([self.tar, self.sevenzip]): self.addMessage('Install 7z (link)' ' to enable CBZ/CBR/ZIP/etc processing.', 'warning') diff --git a/kindlecomicconverter/comic2ebook.py b/kindlecomicconverter/comic2ebook.py index b24c362..48259cd 100755 --- a/kindlecomicconverter/comic2ebook.py +++ b/kindlecomicconverter/comic2ebook.py @@ -42,8 +42,7 @@ from subprocess import STDOUT, PIPE, CalledProcessError from psutil import virtual_memory, disk_usage from html import escape as hescape -from .shared import getImageFileName, walkSort, walkLevel, sanitizeTrace, subprocess_run -from .comicarchive import SEVENZIP, available_archive_tools +from .shared import available_archive_tools, getImageFileName, walkSort, walkLevel, sanitizeTrace, subprocess_run from . import comic2panel from . import image from . import comicarchive @@ -1029,12 +1028,12 @@ def slugify(value): def makeZIP(zipfilename, basedir, isepub=False): start = perf_counter() zipfilename = os.path.abspath(zipfilename) + '.zip' - if SEVENZIP in available_archive_tools(): + if '7z' in available_archive_tools(): if isepub: mimetypeFile = open(os.path.join(basedir, 'mimetype'), 'w') mimetypeFile.write('application/epub+zip') mimetypeFile.close() - subprocess_run([SEVENZIP, 'a', '-tzip', zipfilename, os.path.join(basedir, "*")], capture_output=True, check=True) + subprocess_run(['7z', 'a', '-tzip', zipfilename, os.path.join(basedir, "*")], capture_output=True, check=True) else: zipOutput = ZipFile(zipfilename, 'w', ZIP_DEFLATED) if isepub: @@ -1234,7 +1233,7 @@ def checkTools(source): source = source.upper() if source.endswith('.CB7') or source.endswith('.7Z') or source.endswith('.RAR') or source.endswith('.CBR') or \ source.endswith('.ZIP') or source.endswith('.CBZ'): - if SEVENZIP not in available_archive_tools(): + if '7z' not in available_archive_tools(): print('ERROR: 7z is missing!') sys.exit(1) if options.format == 'MOBI': diff --git a/kindlecomicconverter/comicarchive.py b/kindlecomicconverter/comicarchive.py index ee08658..bb20abd 100644 --- a/kindlecomicconverter/comicarchive.py +++ b/kindlecomicconverter/comicarchive.py @@ -18,7 +18,7 @@ # PERFORMANCE OF THIS SOFTWARE. # -from functools import cached_property, lru_cache +from functools import cached_property import os import platform import distro @@ -28,7 +28,6 @@ from xml.parsers.expat import ExpatError from .shared import subprocess_run EXTRACTION_ERROR = 'Failed to extract archive. Try extracting file outside of KCC.' -SEVENZIP = '7z' if os.name == 'nt' else '7zz' class ComicArchive: @@ -40,7 +39,7 @@ class ComicArchive: @cached_property def type(self): extraction_commands = [ - [SEVENZIP, 'l', '-y', '-p1', self.filepath], + ['7z', 'l', '-y', '-p1', self.filepath], ] if distro.id() == 'fedora' or distro.like() == 'fedora': @@ -69,7 +68,7 @@ class ComicArchive: extraction_commands = [ ['tar', '--exclude', '__MACOSX', '--exclude', '.DS_Store', '--exclude', 'thumbs.db', '--exclude', 'Thumbs.db', '-xf', self.filepath, '-C', targetdir], - [SEVENZIP, 'x', '-y', '-xr!__MACOSX', '-xr!.DS_Store', '-xr!thumbs.db', '-xr!Thumbs.db', '-o' + targetdir, self.filepath], + ['7z', 'x', '-y', '-xr!__MACOSX', '-xr!.DS_Store', '-xr!thumbs.db', '-xr!Thumbs.db', '-o' + targetdir, self.filepath], ] if platform.system() == 'Darwin': @@ -101,13 +100,13 @@ class ComicArchive: def addFile(self, sourcefile): if self.type in ['RAR', 'RAR5']: raise NotImplementedError - process = subprocess_run([SEVENZIP, 'a', '-y', self.filepath, sourcefile], + process = subprocess_run(['7z', 'a', '-y', self.filepath, sourcefile], stdout=PIPE, stderr=STDOUT) if process.returncode != 0: raise OSError('Failed to add the file.') def extractMetadata(self): - process = subprocess_run([SEVENZIP, 'x', '-y', '-so', self.filepath, 'ComicInfo.xml'], + process = subprocess_run(['7z', 'x', '-y', '-so', self.filepath, 'ComicInfo.xml'], stdout=PIPE, stderr=STDOUT) if process.returncode != 0: raise OSError(EXTRACTION_ERROR) @@ -115,16 +114,3 @@ class ComicArchive: return parseString(process.stdout) except ExpatError: return None - -@lru_cache -def available_archive_tools(): - available = [] - - for tool in ['tar', SEVENZIP, 'unar', 'unrar']: - try: - subprocess_run([tool], stdout=PIPE, stderr=STDOUT) - available.append(tool) - except (FileNotFoundError, CalledProcessError): - pass - - return available diff --git a/kindlecomicconverter/shared.py b/kindlecomicconverter/shared.py index 3993391..153f2d7 100644 --- a/kindlecomicconverter/shared.py +++ b/kindlecomicconverter/shared.py @@ -18,6 +18,7 @@ # PERFORMANCE OF THIS SOFTWARE. # +from functools import lru_cache import os from html.parser import HTMLParser import subprocess @@ -124,6 +125,19 @@ def dependencyCheck(level): print('ERROR: ' + ', '.join(missing) + ' is not installed!') sys.exit(1) +@lru_cache +def available_archive_tools(): + available = [] + + for tool in ['tar', '7z', 'unar', 'unrar']: + try: + subprocess_run([tool], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + available.append(tool) + except (FileNotFoundError, subprocess.CalledProcessError): + pass + + return available + def subprocess_run(command, **kwargs): if (os.name == 'nt'): kwargs.setdefault('creationflags', subprocess.CREATE_NO_WINDOW)