Unrar cleanup
This commit is contained in:
+14
-14
@@ -41,7 +41,7 @@ def call_unrar(params):
|
|||||||
if rar_executable_cached is None:
|
if rar_executable_cached is None:
|
||||||
for command in ('unrar', 'rar'):
|
for command in ('unrar', 'rar'):
|
||||||
try:
|
try:
|
||||||
subprocess.Popen([command], stdout=subprocess.PIPE)
|
subprocess.Popen([command], stdout = subprocess.PIPE)
|
||||||
rar_executable_cached = command
|
rar_executable_cached = command
|
||||||
break
|
break
|
||||||
except OSError:
|
except OSError:
|
||||||
@@ -53,13 +53,13 @@ def call_unrar(params):
|
|||||||
args = [rar_executable_cached] + params
|
args = [rar_executable_cached] + params
|
||||||
try:
|
try:
|
||||||
gc.disable() # See http://bugs.python.org/issue1336
|
gc.disable() # See http://bugs.python.org/issue1336
|
||||||
return subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
return subprocess.Popen(args, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
|
||||||
finally:
|
finally:
|
||||||
gc.enable()
|
gc.enable()
|
||||||
|
|
||||||
class RarFileImplementation(object):
|
class RarFileImplementation(object):
|
||||||
|
|
||||||
def init(self, password=None):
|
def init(self, password = None):
|
||||||
global rar_executable_version
|
global rar_executable_version
|
||||||
self.password = password
|
self.password = password
|
||||||
|
|
||||||
@@ -69,7 +69,7 @@ class RarFileImplementation(object):
|
|||||||
for line in stderrdata.splitlines():
|
for line in stderrdata.splitlines():
|
||||||
if line.strip().startswith("Cannot open"):
|
if line.strip().startswith("Cannot open"):
|
||||||
raise FileOpenError
|
raise FileOpenError
|
||||||
if line.find("CRC failed")>=0:
|
if line.find("CRC failed") >= 0:
|
||||||
raise IncorrectRARPassword
|
raise IncorrectRARPassword
|
||||||
accum = []
|
accum = []
|
||||||
source = iter(stdoutdata.splitlines())
|
source = iter(stdoutdata.splitlines())
|
||||||
@@ -115,10 +115,10 @@ class RarFileImplementation(object):
|
|||||||
return '-' if self.password == None else self.password
|
return '-' if self.password == None else self.password
|
||||||
|
|
||||||
|
|
||||||
def call(self, cmd, options=[], files=[]):
|
def call(self, cmd, options = [], files = []):
|
||||||
options2 = options + ['p'+self.escaped_password()]
|
options2 = options + ['p' + self.escaped_password()]
|
||||||
soptions = ['-'+x for x in options2]
|
soptions = ['-' + x for x in options2]
|
||||||
return call_unrar([cmd]+soptions+['--',self.archiveName]+files)
|
return call_unrar([cmd] + soptions + ['--', self.archiveName] + files)
|
||||||
|
|
||||||
def infoiter(self):
|
def infoiter(self):
|
||||||
|
|
||||||
@@ -144,7 +144,7 @@ class RarFileImplementation(object):
|
|||||||
if rar_executable_version == 4:
|
if rar_executable_version == 4:
|
||||||
while not line.startswith('-----------'):
|
while not line.startswith('-----------'):
|
||||||
accum.append(line)
|
accum.append(line)
|
||||||
if len(accum)==2:
|
if len(accum) == 2:
|
||||||
data = {}
|
data = {}
|
||||||
data['index'] = i
|
data['index'] = i
|
||||||
# asterisks mark password-encrypted files
|
# asterisks mark password-encrypted files
|
||||||
@@ -153,7 +153,7 @@ class RarFileImplementation(object):
|
|||||||
data['size'] = int(fields[0])
|
data['size'] = int(fields[0])
|
||||||
attr = fields[5]
|
attr = fields[5]
|
||||||
data['isdir'] = 'd' in attr.lower()
|
data['isdir'] = 'd' in attr.lower()
|
||||||
data['datetime'] = time.strptime(fields[3]+" "+fields[4], '%d-%m-%y %H:%M')
|
data['datetime'] = time.strptime(fields[3] + " " + fields[4], '%d-%m-%y %H:%M')
|
||||||
data['comment'] = None
|
data['comment'] = None
|
||||||
yield data
|
yield data
|
||||||
accum = []
|
accum = []
|
||||||
@@ -168,7 +168,7 @@ class RarFileImplementation(object):
|
|||||||
data['size'] = int(fields[1])
|
data['size'] = int(fields[1])
|
||||||
attr = fields[0]
|
attr = fields[0]
|
||||||
data['isdir'] = 'd' in attr.lower()
|
data['isdir'] = 'd' in attr.lower()
|
||||||
data['datetime'] = time.strptime(fields[2]+" "+fields[3], '%d-%m-%y %H:%M')
|
data['datetime'] = time.strptime(fields[2] + " " + fields[3], '%d-%m-%y %H:%M')
|
||||||
data['comment'] = None
|
data['comment'] = None
|
||||||
yield data
|
yield data
|
||||||
i += 1
|
i += 1
|
||||||
@@ -179,7 +179,7 @@ class RarFileImplementation(object):
|
|||||||
res = []
|
res = []
|
||||||
for info in self.infoiter():
|
for info in self.infoiter():
|
||||||
checkres = checker(info)
|
checkres = checker(info)
|
||||||
if checkres==True and not info.isdir:
|
if checkres == True and not info.isdir:
|
||||||
pipe = self.call('p', ['inul'], [info.filename]).stdout
|
pipe = self.call('p', ['inul'], [info.filename]).stdout
|
||||||
res.append((info, pipe.read()))
|
res.append((info, pipe.read()))
|
||||||
return res
|
return res
|
||||||
@@ -202,13 +202,13 @@ class RarFileImplementation(object):
|
|||||||
checkres = checker(info)
|
checkres = checker(info)
|
||||||
if type(checkres) in [str, unicode]:
|
if type(checkres) in [str, unicode]:
|
||||||
raise NotImplementedError("Condition callbacks returning strings are deprecated and only supported in Windows")
|
raise NotImplementedError("Condition callbacks returning strings are deprecated and only supported in Windows")
|
||||||
if checkres==True and not info.isdir:
|
if checkres == True and not info.isdir:
|
||||||
names.append(info.filename)
|
names.append(info.filename)
|
||||||
res.append(info)
|
res.append(info)
|
||||||
names.append(path)
|
names.append(path)
|
||||||
proc = self.call(command, options, names)
|
proc = self.call(command, options, names)
|
||||||
stdoutdata, stderrdata = proc.communicate()
|
stdoutdata, stderrdata = proc.communicate()
|
||||||
if stderrdata.find("CRC failed")>=0 or stderrdata.find("Checksum error")>=0:
|
if stderrdata.find("CRC failed") >= 0 or stderrdata.find("Checksum error") >= 0:
|
||||||
raise IncorrectRARPassword
|
raise IncorrectRARPassword
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user