diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2010-10-07 12:25:17 +0200 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2010-10-07 12:25:17 +0200 |
commit | 7b8bccc5f221a7f4af5e41a21b44ed6e6002601c (patch) | |
tree | 8d94f373011b93ebf45d4d077df2d2fc815f79d8 /module/pyunrar.py | |
parent | pycurl cleanup (diff) | |
download | pyload-7b8bccc5f221a7f4af5e41a21b44ed6e6002601c.tar.xz |
unrar ram check
Diffstat (limited to 'module/pyunrar.py')
-rw-r--r-- | module/pyunrar.py | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/module/pyunrar.py b/module/pyunrar.py index a2810b66e..11b19330b 100644 --- a/module/pyunrar.py +++ b/module/pyunrar.py @@ -51,6 +51,9 @@ class NoFilesError(Exception): class WrongPasswordError(Exception): pass +class LowRamError(Exception): + pass + class CommandError(Exception): def __init__(self, ret=None, stdout=None, stderr=None): self.ret = ret @@ -73,7 +76,7 @@ class CommandError(Exception): return EXITMAP[self.ret] class Unrar(): - def __init__(self, archive, tmpdir=None): + def __init__(self, archive, tmpdir=None, ramSize=0): """ archive should be be first or only part """ @@ -96,7 +99,10 @@ class Unrar(): self.tmpdir = mkdtemp() else: self.tmpdir = tmpdir +"_" + basename(archive).replace(".rar", "").replace(".","") - + + self.ram = ramSize + + def listContent(self, password=None): """ returns a list with all infos to the files in the archive @@ -173,12 +179,16 @@ class Unrar(): """ files = self.listContent(password=password) smallest = (-1, -1) + biggest = (-1, -1) for i, f in enumerate(files): if f["size"] < smallest[1] or smallest[1] == -1: smallest = (i, f["size"]) - if smallest[0] == -1: + if f["size"] > biggest[1] or biggest[1] == -1: + biggest = (i, f["size"]) + if smallest[0] == -1 or biggest[0] == -1: raise UnknownError() self.smallestFiles = files[smallest[0]] + self.biggestFiles = files[biggest[0]] return files[smallest[0]] def needPassword(self): @@ -267,6 +277,16 @@ class Unrar(): sf.append(self.getSmallestFile(password)["name"]) except WrongPasswordError: continue + + if self.ram: + size = self.biggestFiles["size"] / 1024 ** 2 + if self.ram < 127 and size > 50: + raise LowRamError + elif self.ram < 256 and size > 500: + raise LowRamError + elif self.ram < 512 and size > 2000: + raise LowRamError + tdir = self.tmpdir if not exists(tdir): makedirs(tdir) |