class UNRARModel: def __init__(self, filepath): self.rar = rarfile.RarFile(filepath) self.infolist = self.rar.infolist() def extral_list(self, selected_dir): selected_infolist = [] for d in selected_dir: for info in self.infolist: filename = info.filename.replace("\", "/") # in win if filename.find(d) != -1 and info.file_size != 0L: selected_infolist.append(info) return selected_infolist def decompression_list(self, selected_infolist, to_dir): """ extract the Specified directory :param selected_infolist: Specified directory :param to_dir: destination :return: """ self.rar.extractall(path=to_dir, members=selected_infolist)
def rar_decompression(from_path, to_path): from_path = from_path.replace("\", "/") # in win rar = rarfile.RarFile(from_path) rar.extractall(to_path) standout_print("Info: decompression %s to %s finish." % (from_path, to_path)) def remove_file(file_path): """ remove file :param file_path: :return: """ os.remove(file_path) standout_print("Info: remove files %s finish." % file_path)