def do_zipd(self, inp): file_list = [] for file in os.listdir(os.getcwd()): if not os.path.isfile(os.path.join( os.getcwd(), file)) and not file.startswith('.'): file_list.append(file) questions = [ inquirer.Checkbox( 'files', message= "Select Folders to Zip (use Spacebar to select and Enter to confirm)", choices=file_list) ] answers = inquirer.prompt(questions) try: zipf = ZipFile("MyShellPy.zip", 'w') for dir in answers['files']: for root, dirs, files in os.walk(dir): for file in files: zipf.write( os.path.join(root, file), os.path.relpath(os.path.join(root, file), os.path.join(dir, '..'))) zipf.close() print('All file(s) zipped successfully!') except PermissionError: print("Requires Root Access") args = ['sudo', sys.executable] + sys.argv + [os.environ] os.execlpe('sudo', *args)
class ZipArch: def __init__(self, folder, file_name): self.file_path = os.path.join(folder, file_name) self.zip_file = ZipFile(self.file_path) self.zip_first_item = self.zip_file.namelist()[0] def __del__(self): self.zip_file.close() def check_pwd(self, pwd): try: with self.zip_file.open(self.zip_first_item, "r", pwd=pwd.encode()) as f: f.read1(1) return True except Exception as ex: return False