26
26
from subprocess import STDOUT , PIPE
27
27
from xml .dom .minidom import parseString
28
28
from xml .parsers .expat import ExpatError
29
+ from .shared import subprocess_run_silent
29
30
30
31
EXTRACTION_ERROR = 'Failed to extract archive. Try extracting file outside of KCC.'
31
32
@@ -36,13 +37,13 @@ def __init__(self, filepath):
36
37
self .type = None
37
38
if not os .path .isfile (self .filepath ):
38
39
raise OSError ('File not found.' )
39
- process = subprocess . run (['7z' , 'l' , '-y' , '-p1' , self .filepath ], stderr = STDOUT , stdout = PIPE )
40
+ process = subprocess_run_silent (['7z' , 'l' , '-y' , '-p1' , self .filepath ], stderr = STDOUT , stdout = PIPE )
40
41
for line in process .stdout .splitlines ():
41
42
if b'Type =' in line :
42
43
self .type = line .rstrip ().decode ().split (' = ' )[1 ].upper ()
43
44
break
44
45
if process .returncode != 0 and distro .id () == 'fedora' :
45
- process = subprocess . run (['unrar' , 'l' , '-y' , '-p1' , self .filepath ], stderr = STDOUT , stdout = PIPE )
46
+ process = subprocess_run_silent (['unrar' , 'l' , '-y' , '-p1' , self .filepath ], stderr = STDOUT , stdout = PIPE )
46
47
for line in process .stdout .splitlines ():
47
48
if b'Details: ' in line :
48
49
self .type = line .rstrip ().decode ().split (' ' )[1 ].upper ()
@@ -53,15 +54,15 @@ def __init__(self, filepath):
53
54
def extract (self , targetdir ):
54
55
if not os .path .isdir (targetdir ):
55
56
raise OSError ('Target directory doesn\' t exist.' )
56
- process = subprocess . run (['7z' , 'x' , '-y' , '-xr!__MACOSX' , '-xr!.DS_Store' , '-xr!thumbs.db' , '-xr!Thumbs.db' , '-o' + targetdir , self .filepath ],
57
+ process = subprocess_run_silent (['7z' , 'x' , '-y' , '-xr!__MACOSX' , '-xr!.DS_Store' , '-xr!thumbs.db' , '-xr!Thumbs.db' , '-o' + targetdir , self .filepath ],
57
58
stdout = PIPE , stderr = STDOUT )
58
59
if process .returncode != 0 and distro .id () == 'fedora' :
59
- process = subprocess . run (['unrar' , 'x' , '-y' , '-x__MACOSX' , '-x.DS_Store' , '-xthumbs.db' , '-xThumbs.db' , self .filepath , targetdir ]
60
+ process = subprocess_run_silent (['unrar' , 'x' , '-y' , '-x__MACOSX' , '-x.DS_Store' , '-xthumbs.db' , '-xThumbs.db' , self .filepath , targetdir ]
60
61
, stdout = PIPE , stderr = STDOUT )
61
62
if process .returncode != 0 :
62
63
raise OSError (EXTRACTION_ERROR )
63
64
elif process .returncode != 0 and platform .system () == 'Darwin' :
64
- process = subprocess . run (['unar' , self .filepath , '-f' , '-o' , targetdir ],
65
+ process = subprocess_run_silent (['unar' , self .filepath , '-f' , '-o' , targetdir ],
65
66
stdout = PIPE , stderr = STDOUT )
66
67
elif process .returncode != 0 :
67
68
raise OSError (EXTRACTION_ERROR )
@@ -73,13 +74,13 @@ def extract(self, targetdir):
73
74
def addFile (self , sourcefile ):
74
75
if self .type in ['RAR' , 'RAR5' ]:
75
76
raise NotImplementedError
76
- process = subprocess . run (['7z' , 'a' , '-y' , self .filepath , sourcefile ],
77
+ process = subprocess_run_silent (['7z' , 'a' , '-y' , self .filepath , sourcefile ],
77
78
stdout = PIPE , stderr = STDOUT )
78
79
if process .returncode != 0 :
79
80
raise OSError ('Failed to add the file.' )
80
81
81
82
def extractMetadata (self ):
82
- process = subprocess . run (['7z' , 'x' , '-y' , '-so' , self .filepath , 'ComicInfo.xml' ],
83
+ process = subprocess_run_silent (['7z' , 'x' , '-y' , '-so' , self .filepath , 'ComicInfo.xml' ],
83
84
stdout = PIPE , stderr = STDOUT )
84
85
if process .returncode != 0 :
85
86
raise OSError (EXTRACTION_ERROR )
0 commit comments