Best Python code snippet using localstack_python
zip_utils.py
Source:zip_utils.py
...4import asyncio5from typing import List6from nonebot.log import logger7from omega_miya.utils.Omega_Base import Result8def __create_zip_file(files: List[str], file_path: str, file_name: str) -> Result.TextResult:9 # æ£æ¥æ件路å¾10 folder_path = os.path.abspath(file_path)11 if not os.path.exists(folder_path):12 os.makedirs(folder_path)13 zip_file_path = os.path.abspath(os.path.join(folder_path, f'{file_name}.zip'))14 with zipfile.ZipFile(zip_file_path, mode='w', compression=zipfile.ZIP_STORED) as zipf:15 for file in files:16 file_path = os.path.abspath(file)17 arcname = os.path.basename(file_path)18 if os.path.exists(file_path):19 zipf.write(file_path, arcname=arcname)20 else:21 logger.warning(f'create_zip_file: file not exists: {file}, ignore')22 return Result.TextResult(error=False, info=f'{file_name}.zip', result=zip_file_path)23async def create_zip_file(files: List[str], file_path: str, file_name: str) -> Result.TextResult:24 def __handle():25 return __create_zip_file(files, file_path, file_name)26 loop = asyncio.get_running_loop()27 try:28 result = await loop.run_in_executor(None, __handle)29 except Exception as e:30 result = Result.TextResult(error=True, info=f'create_zip_file failed: {repr(e)}', result='')31 return result32def __create_7z_file(files: List[str], file_path: str, file_name: str, password: str) -> Result.TextResult:33 # æ£æ¥æ件路å¾34 folder_path = os.path.abspath(file_path)35 if not os.path.exists(folder_path):36 os.makedirs(folder_path)37 z7z_file_path = os.path.abspath(os.path.join(folder_path, f'{file_name}.7z'))38 with py7zr.SevenZipFile(z7z_file_path, mode='w', password=password) as zf:39 zf.set_encrypted_header(True)...
s3_zip.py
Source:s3_zip.py
1from zipfile import ZipFile2import os3from os.path import basename4from misc import user_feedback5def create_zip_file(path, zip_name):6 """7 Creating a zip file for each category8 :param path: the path of the folder to be compressed9 :param zip_name: the name of the output zip file10 :return: None11 """12 with ZipFile(zip_name, 'w') as zipObj:13 for folderName, subfolders, filenames in os.walk(path):14 user_feedback('Compressing --- ' + folderName, task = 'main')15 for index, filename in enumerate(filenames):16 print('Adding file --- ' + filename + ' --- ' + str(index + 1) + '/' + str(len(filenames)), end = '\r')17 filePath = os.path.join(folderName, filename)18 zipObj.write(filePath, basename(filePath))19if __name__ == '__main__':20 main_path = '../../../capstone data/imgFeatures'21 zip_path = '../../../capstone data/compressed/'22 create_zip_file(main_path + '/plant', zip_path + 'plant.zip')23 create_zip_file(main_path + '/animal', zip_path + 'animal.zip')...
zip.py
Source:zip.py
1import zipfile2from pathlib import Path34# å¨æå®zipå缩æ件ç®å½ä¸å建zipæ件5create_zip_file = zipfile.ZipFile(r"C:\Users\Administrator\Desktop\CarGame\resource\jsonData.zip", mode='a', compression=zipfile.ZIP_DEFLATED)67# zip æ¾å
¥æ件8for i in Path(r"C:\Users\Administrator\Desktop\CarGame\resource\json").glob("*.json"):9 print(str(i),i.name)10 create_zip_file.write(str(i),i.name)
...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!