How to use create_zip_file method in localstack

Best Python code snippet using localstack_python

zip_utils.py

Source:zip_utils.py Github

copy

Full Screen

...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)...

Full Screen

Full Screen

s3_zip.py

Source:s3_zip.py Github

copy

Full Screen

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')...

Full Screen

Full Screen

zip.py

Source:zip.py Github

copy

Full Screen

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) ...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful