def extract(self, progress, password=None): command = "x" if self.fullpath else "e" # popen thinks process is still alive (just like pexpect) - very strange behavior # so for now progress can not be determined correctly p = self.call_unrar(command, fs_encode(self.file), self.out, password=password) renice(p.pid, self.renice) progress(0) out, err = p.communicate() #wait for process progress(100) if "CRC failed" in err and not password and not self.passwordProtected: raise CRCError elif "CRC failed" in err: raise WrongPassword if err.strip(): #raise error if anything is on stderr raise ArchiveError(err.strip()) if p.returncode: raise ArchiveError("Process terminated") if not self.files: self.password = password self.listContent()
def checkArchive(self): p = self.call_unrar("l", "-v", self.file) out, err = p.communicate() if self.re_wrongpwd.search(err): self.passwordProtected = True self.headerProtected = True return True # output only used to check if passworded files are present if self.re_version.search(out): for attr, size, name in self.re_filelist5.findall(out): if attr.startswith("*"): self.passwordProtected = True return True else: for name, size, packed in self.re_filelist.findall(out): if name.startswith("*"): self.passwordProtected = True return True self.listContent() if not self.files: raise ArchiveError("Empty Archive") return False
def extract(self, progress, password=None): command = "x" if self.fullpath else "e" p = self.call_unrar(command, fs_encode(self.file), self.out, password=password) renice(p.pid, self.renice) progress(0) progressstring = "" while True: c = p.stdout.read(1) # quit loop on eof if not c: break # reading a percentage sign -> set progress and restart if c == '%': progress(int(progressstring)) progressstring = "" # not reading a digit -> therefore restart elif c not in digits: progressstring = "" # add digit to progressstring else: progressstring = progressstring + c progress(100) # retrieve stderr err = p.stderr.read() if "CRC failed" in err and not password and not self.passwordProtected: raise CRCError elif "CRC failed" in err: raise WrongPassword if err.strip(): #: raise error if anything is on stderr raise ArchiveError(err.strip()) if p.returncode: raise ArchiveError("Process terminated") if not self.files: self.password = password self.listContent()
def listContent(self): command = "vb" if self.fullpath else "lb" p = self.call_unrar(command, "-v", self.file, password=self.password) out, err = p.communicate() if "Cannot open" in err: raise ArchiveError("Cannot open file") if err.strip(): #: only log error at this point self.m.logError(err.strip()) result = set() for f in decode(out).splitlines(): f = f.strip() result.add(save_join(self.out, f)) self.files = result