1
0
mirror of https://github.com/ciromattia/kcc synced 2025-12-15 18:56:28 +00:00

reduce dependency on 7z, unar, homebrew by using builtin tar

This commit is contained in:
Alex Xu
2024-05-11 17:49:10 -07:00
parent f6475f4c61
commit d48bf7580d
3 changed files with 24 additions and 9 deletions

View File

@@ -462,7 +462,7 @@ class KCCGUI(KCC_ui.Ui_mainWindow):
if self.needClean:
self.needClean = False
GUI.jobList.clear()
if self.sevenzip:
if self.tar or self.sevenzip:
fnames = QtWidgets.QFileDialog.getOpenFileNames(MW, 'Select file', self.lastPath,
'Comic (*.cbz *.cbr *.cb7 *.zip *.rar *.7z *.pdf);;All (*.*)')
else:
@@ -802,7 +802,7 @@ class KCCGUI(KCC_ui.Ui_mainWindow):
self.needClean = False
GUI.jobList.clear()
formats = ['.pdf']
if self.sevenzip:
if self.tar or self.sevenzip:
formats.extend(['.cb7', '.7z', '.cbz', '.zip', '.cbr', '.rar'])
if os.path.isdir(message):
GUI.jobList.addItem(message)
@@ -1028,13 +1028,19 @@ class KCCGUI(KCC_ui.Ui_mainWindow):
self.addMessage('Since you are a new user of <b>KCC</b> please see few '
'<a href="https://github.com/ciromattia/kcc/wiki/Important-tips">important tips</a>.',
'info')
try:
subprocess_run_silent(['tar'], stdout=PIPE, stderr=STDOUT)
self.tar = True
except FileNotFoundError:
self.tar = False
try:
subprocess_run_silent(['7z'], stdout=PIPE, stderr=STDOUT)
self.sevenzip = True
except FileNotFoundError:
self.sevenzip = False
self.addMessage('<a href="https://github.com/ciromattia/kcc#7-zip">Install 7z (link)</a>'
' to enable CBZ/CBR/ZIP/etc processing.', 'warning')
if not self.tar:
self.addMessage('<a href="https://github.com/ciromattia/kcc#7-zip">Install 7z (link)</a>'
' to enable CBZ/CBR/ZIP/etc processing.', 'warning')
self.detectKindleGen(True)
APP.messageFromOtherInstance.connect(self.handleMessage)

View File

@@ -644,6 +644,9 @@ def getWorkFolder(afile):
try:
cbx = comicarchive.ComicArchive(afile)
path = cbx.extract(workdir)
tdir = os.listdir(workdir)
if 'ComicInfo.xml' in tdir:
tdir.remove('ComicInfo.xml')
except OSError as e:
rmtree(workdir, True)
raise UserWarning(e)

View File

@@ -23,7 +23,7 @@ import platform
import subprocess
import distro
from shutil import move
from subprocess import STDOUT, PIPE
from subprocess import STDOUT, PIPE, CalledProcessError
from xml.dom.minidom import parseString
from xml.parsers.expat import ExpatError
from .shared import subprocess_run_silent
@@ -37,7 +37,10 @@ class ComicArchive:
self.type = None
if not os.path.isfile(self.filepath):
raise OSError('File not found.')
process = subprocess_run_silent(['7z', 'l', '-y', '-p1', self.filepath], stderr=STDOUT, stdout=PIPE)
try:
process = subprocess_run_silent(['7z', 'l', '-y', '-p1', self.filepath], stderr=STDOUT, stdout=PIPE)
except FileNotFoundError:
return
for line in process.stdout.splitlines():
if b'Type =' in line:
self.type = line.rstrip().decode().split(' = ')[1].upper()
@@ -54,6 +57,12 @@ class ComicArchive:
def extract(self, targetdir):
if not os.path.isdir(targetdir):
raise OSError('Target directory doesn\'t exist.')
try:
process = subprocess_run_silent(['tar', '-xf', self.filepath, '-C', targetdir],
stdout=PIPE, stderr=STDOUT, check=True)
return targetdir
except (FileNotFoundError, CalledProcessError):
pass
process = subprocess_run_silent(['7z', 'x', '-y', '-xr!__MACOSX', '-xr!.DS_Store', '-xr!thumbs.db', '-xr!Thumbs.db', '-o' + targetdir, self.filepath],
stdout=PIPE, stderr=STDOUT)
if process.returncode != 0 and distro.id() == 'fedora':
@@ -66,9 +75,6 @@ class ComicArchive:
stdout=PIPE, stderr=STDOUT)
elif process.returncode != 0:
raise OSError(EXTRACTION_ERROR)
tdir = os.listdir(targetdir)
if 'ComicInfo.xml' in tdir:
tdir.remove('ComicInfo.xml')
return targetdir
def addFile(self, sourcefile):