mirror of
https://github.com/ciromattia/kcc
synced 2025-12-13 09:46:25 +00:00
makeZIP now prefers 7z for SPEED (#844)
This commit is contained in:
@@ -37,7 +37,7 @@ from packaging.version import Version
|
|||||||
from raven import Client
|
from raven import Client
|
||||||
from tempfile import gettempdir
|
from tempfile import gettempdir
|
||||||
|
|
||||||
from .shared import HTMLStripper, sanitizeTrace, walkLevel, subprocess_run
|
from .shared import HTMLStripper, available_archive_tools, sanitizeTrace, walkLevel, subprocess_run
|
||||||
from . import __version__
|
from . import __version__
|
||||||
from . import comic2ebook
|
from . import comic2ebook
|
||||||
from . import metadata
|
from . import metadata
|
||||||
@@ -1066,19 +1066,12 @@ class KCCGUI(KCC_ui.Ui_mainWindow):
|
|||||||
self.addMessage('Since you are a new user of <b>KCC</b> please see few '
|
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>.',
|
'<a href="https://github.com/ciromattia/kcc/wiki/Important-tips">important tips</a>.',
|
||||||
'info')
|
'info')
|
||||||
try:
|
|
||||||
subprocess_run(['tar'], stdout=PIPE, stderr=STDOUT)
|
self.tar = 'tar' in available_archive_tools()
|
||||||
self.tar = True
|
self.sevenzip = '7z' in available_archive_tools()
|
||||||
except FileNotFoundError:
|
if not any([self.tar, self.sevenzip]):
|
||||||
self.tar = False
|
self.addMessage('<a href="https://github.com/ciromattia/kcc#7-zip">Install 7z (link)</a>'
|
||||||
try:
|
' to enable CBZ/CBR/ZIP/etc processing.', 'warning')
|
||||||
subprocess_run(['7z'], stdout=PIPE, stderr=STDOUT)
|
|
||||||
self.sevenzip = True
|
|
||||||
except FileNotFoundError:
|
|
||||||
self.sevenzip = False
|
|
||||||
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)
|
self.detectKindleGen(True)
|
||||||
|
|
||||||
APP.messageFromOtherInstance.connect(self.handleMessage)
|
APP.messageFromOtherInstance.connect(self.handleMessage)
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import pathlib
|
|||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
from time import strftime, gmtime
|
from time import perf_counter, strftime, gmtime
|
||||||
from copy import copy
|
from copy import copy
|
||||||
from glob import glob, escape
|
from glob import glob, escape
|
||||||
from re import sub
|
from re import sub
|
||||||
@@ -40,7 +40,7 @@ from subprocess import STDOUT, PIPE
|
|||||||
from psutil import virtual_memory, disk_usage
|
from psutil import virtual_memory, disk_usage
|
||||||
from html import escape as hescape
|
from html import escape as hescape
|
||||||
|
|
||||||
from .shared import md5Checksum, getImageFileName, walkSort, walkLevel, sanitizeTrace, subprocess_run
|
from .shared import available_archive_tools, md5Checksum, getImageFileName, walkSort, walkLevel, sanitizeTrace, subprocess_run
|
||||||
from . import comic2panel
|
from . import comic2panel
|
||||||
from . import image
|
from . import image
|
||||||
from . import comicarchive
|
from . import comicarchive
|
||||||
@@ -946,17 +946,27 @@ def slugify(value):
|
|||||||
|
|
||||||
|
|
||||||
def makeZIP(zipfilename, basedir, isepub=False):
|
def makeZIP(zipfilename, basedir, isepub=False):
|
||||||
|
start = perf_counter()
|
||||||
zipfilename = os.path.abspath(zipfilename) + '.zip'
|
zipfilename = os.path.abspath(zipfilename) + '.zip'
|
||||||
zipOutput = ZipFile(zipfilename, 'w', ZIP_DEFLATED)
|
if '7z' in available_archive_tools():
|
||||||
if isepub:
|
if isepub:
|
||||||
zipOutput.writestr('mimetype', 'application/epub+zip', ZIP_STORED)
|
mimetypeFile = open(os.path.join(basedir, 'mimetype'), 'w')
|
||||||
for dirpath, _, filenames in os.walk(basedir):
|
mimetypeFile.write('application/epub+zip')
|
||||||
for name in filenames:
|
mimetypeFile.close()
|
||||||
path = os.path.normpath(os.path.join(dirpath, name))
|
subprocess_run(['7z', 'a', '-tzip', zipfilename, basedir], capture_output=True, check=True)
|
||||||
aPath = os.path.normpath(os.path.join(dirpath.replace(basedir, ''), name))
|
else:
|
||||||
if os.path.isfile(path):
|
zipOutput = ZipFile(zipfilename, 'w', ZIP_DEFLATED)
|
||||||
zipOutput.write(path, aPath)
|
if isepub:
|
||||||
zipOutput.close()
|
zipOutput.writestr('mimetype', 'application/epub+zip', ZIP_STORED)
|
||||||
|
for dirpath, _, filenames in os.walk(basedir):
|
||||||
|
for name in filenames:
|
||||||
|
path = os.path.normpath(os.path.join(dirpath, name))
|
||||||
|
aPath = os.path.normpath(os.path.join(dirpath.replace(basedir, ''), name))
|
||||||
|
if os.path.isfile(path):
|
||||||
|
zipOutput.write(path, aPath)
|
||||||
|
zipOutput.close()
|
||||||
|
end = perf_counter()
|
||||||
|
print(f"makeZIP time: {end - start} seconds")
|
||||||
return zipfilename
|
return zipfilename
|
||||||
|
|
||||||
|
|
||||||
@@ -1131,9 +1141,7 @@ def checkTools(source):
|
|||||||
source = source.upper()
|
source = source.upper()
|
||||||
if source.endswith('.CB7') or source.endswith('.7Z') or source.endswith('.RAR') or source.endswith('.CBR') or \
|
if source.endswith('.CB7') or source.endswith('.7Z') or source.endswith('.RAR') or source.endswith('.CBR') or \
|
||||||
source.endswith('.ZIP') or source.endswith('.CBZ'):
|
source.endswith('.ZIP') or source.endswith('.CBZ'):
|
||||||
try:
|
if '7z' not in available_archive_tools():
|
||||||
subprocess_run(['7z'], stdout=PIPE, stderr=STDOUT)
|
|
||||||
except FileNotFoundError:
|
|
||||||
print('ERROR: 7z is missing!')
|
print('ERROR: 7z is missing!')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
if options.format == 'MOBI':
|
if options.format == 'MOBI':
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
# PERFORMANCE OF THIS SOFTWARE.
|
# PERFORMANCE OF THIS SOFTWARE.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
from functools import lru_cache
|
||||||
import os
|
import os
|
||||||
from hashlib import md5
|
from hashlib import md5
|
||||||
from html.parser import HTMLParser
|
from html.parser import HTMLParser
|
||||||
@@ -137,6 +138,19 @@ def dependencyCheck(level):
|
|||||||
print('ERROR: ' + ', '.join(missing) + ' is not installed!')
|
print('ERROR: ' + ', '.join(missing) + ' is not installed!')
|
||||||
sys.exit(1)
|
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:
|
||||||
|
pass
|
||||||
|
|
||||||
|
return available
|
||||||
|
|
||||||
def subprocess_run(command, **kwargs):
|
def subprocess_run(command, **kwargs):
|
||||||
if (os.name == 'nt'):
|
if (os.name == 'nt'):
|
||||||
kwargs.setdefault('creationflags', subprocess.CREATE_NO_WINDOW)
|
kwargs.setdefault('creationflags', subprocess.CREATE_NO_WINDOW)
|
||||||
|
|||||||
Reference in New Issue
Block a user