mirror of
https://github.com/ciromattia/kcc
synced 2026-05-14 11:31:37 +00:00
Added 7z/CB7 support
This commit is contained in:
@@ -321,11 +321,19 @@ class Ui_KCC(object):
|
||||
self.needClean = False
|
||||
GUI.JobList.clear()
|
||||
if self.UnRAR:
|
||||
fnames = QtGui.QFileDialog.getOpenFileNames(MainWindow, 'Select file', self.lastPath,
|
||||
'*.cbz *.cbr *.zip *.rar *.pdf')
|
||||
if self.sevenza:
|
||||
fnames = QtGui.QFileDialog.getOpenFileNames(MainWindow, 'Select file', self.lastPath,
|
||||
'*.cbz *.cbr *.cb7 *.zip *.rar *.7z *.pdf')
|
||||
else:
|
||||
fnames = QtGui.QFileDialog.getOpenFileNames(MainWindow, 'Select file', self.lastPath,
|
||||
'*.cbz *.cbr *.zip *.rar *.pdf')
|
||||
else:
|
||||
fnames = QtGui.QFileDialog.getOpenFileNames(MainWindow, 'Select file', self.lastPath,
|
||||
'*.cbz *.zip *.pdf')
|
||||
if self.sevenza:
|
||||
fnames = QtGui.QFileDialog.getOpenFileNames(MainWindow, 'Select file', self.lastPath,
|
||||
'*.cbz *.cb7 *.zip *.7z *.pdf')
|
||||
else:
|
||||
fnames = QtGui.QFileDialog.getOpenFileNames(MainWindow, 'Select file', self.lastPath,
|
||||
'*.cbz *.zip *.pdf')
|
||||
# Lame UTF-8 security measure
|
||||
for fname in fnames:
|
||||
try:
|
||||
@@ -629,6 +637,13 @@ class Ui_KCC(object):
|
||||
self.UnRAR = False
|
||||
self.addMessage('Cannot find <a href="http://www.rarlab.com/rar_add.htm">UnRAR</a>!'
|
||||
' Processing of CBR/RAR files will be disabled.', 'warning')
|
||||
sevenzaExitCode = call('7za', stdout=PIPE, stderr=STDOUT, shell=True)
|
||||
if sevenzaExitCode == 0 or sevenzaExitCode == 7:
|
||||
self.sevenza = True
|
||||
else:
|
||||
self.sevenza = False
|
||||
self.addMessage('Cannot find <a href="http://www.7-zip.org/download.html>7za</a>!'
|
||||
' Processing of CB7/7Z files will be disabled.', 'warning')
|
||||
|
||||
GUI.BasicModeButton.clicked.connect(self.modeBasic)
|
||||
GUI.AdvModeButton.clicked.connect(self.modeAdvanced)
|
||||
|
||||
@@ -22,6 +22,7 @@ __docformat__ = 'restructuredtext en'
|
||||
import os
|
||||
import zipfile
|
||||
import rarfile
|
||||
from subprocess import Popen, STDOUT, PIPE
|
||||
|
||||
|
||||
# noinspection PyBroadException
|
||||
@@ -32,6 +33,8 @@ class CBxArchive:
|
||||
self.compressor = 'zip'
|
||||
elif rarfile.is_rarfile(origFileName):
|
||||
self.compressor = 'rar'
|
||||
elif origFileName.endswith('.7z') or origFileName.endswith('.cb7'):
|
||||
self.compressor = '7z'
|
||||
else:
|
||||
self.compressor = None
|
||||
|
||||
@@ -68,12 +71,24 @@ class CBxArchive:
|
||||
filelist.append(f)
|
||||
cbrFile.extractall(targetdir, filelist)
|
||||
|
||||
def extractCB7(self, targetdir):
|
||||
output = Popen('7za x "' + self.origFileName + '" -xr!__MACOSX -xr!.DS_Store -xr!thumbs.db -o"' + targetdir +
|
||||
'"', stdout=PIPE, stderr=STDOUT, shell=True)
|
||||
extracted = False
|
||||
for line in output.stdout:
|
||||
if "Everything is Ok" in line:
|
||||
extracted = True
|
||||
if not extracted:
|
||||
raise OSError
|
||||
|
||||
def extract(self, targetdir):
|
||||
print "\n" + targetdir + "\n"
|
||||
if self.compressor == 'rar':
|
||||
self.extractCBR(targetdir)
|
||||
elif self.compressor == 'zip':
|
||||
self.extractCBZ(targetdir)
|
||||
elif self.compressor == '7z':
|
||||
self.extractCB7(targetdir)
|
||||
adir = os.listdir(targetdir)
|
||||
if len(adir) == 1 and os.path.isdir(os.path.join(targetdir, adir[0])):
|
||||
import shutil
|
||||
|
||||
@@ -569,8 +569,7 @@ def getWorkFolder(afile):
|
||||
path = cbx.extract(workdir)
|
||||
except OSError:
|
||||
rmtree(workdir)
|
||||
print 'Unrar not found, please download from ' + \
|
||||
'http://www.rarlab.com/download.htm and put into your PATH.'
|
||||
print 'UnRAR/7za not found or file failed to extract!'
|
||||
sys.exit(21)
|
||||
else:
|
||||
rmtree(workdir)
|
||||
|
||||
Reference in New Issue
Block a user