How to use delete_archive method in localstack

Best Python code snippet using localstack_python

extractor.py

Source: extractor.py Github

copy

Full Screen

1#Standart library imports2import zipfile3import os4import shutil5from shutil import copyfile6from pathlib import Path7# Third party imports8import tarfile9#Local imports10from selenium_driver_updater.util.logger import logger11from selenium_driver_updater.util.exceptions import UnknownArchiveFormatException12class Extractor():13 """Class for working with different archive types"""14 @staticmethod15 def extract_all_zip_archive(16 archive_path: str,17 out_path: str, delete_archive: bool = True18 ) -> None:19 """Extract all members in specific zip archive20 Args:21 archive_path (str) : Path to specific archive.22 out_path (str) : Out path, where all members of archive will be gathered.23 delete_archive (bool) : Delete archive after unzip or not. Defaults to True.24 """25 with zipfile.ZipFile(archive_path, 'r') as zip_ref:26 zip_ref.extractall(out_path)27 if Path(archive_path).exists() and delete_archive:28 Path(archive_path).unlink()29 @staticmethod30 def extract_all_tar_gz_archive(31 archive_path: str,32 out_path: str, delete_archive: bool = True33 ) -> None:34 """Extract all members in specific tar.gz archive35 Args:36 archive_path (str) : Path to specific archive.37 out_path (str) : Out path, where all members of archive will be gathered.38 delete_archive (bool) : Delete archive after unzip or not. Defaults to True.39 """40 with tarfile.open(archive_path, "r:gz") as tar_ref:41 tar_ref.extractall(out_path)42 if Path(archive_path).exists() and delete_archive:43 Path(archive_path).unlink()44 @staticmethod45 def extract_all_zip_archive_with_specific_name(46 archive_path: str, out_path: str, filename: str,47 filename_replace: str, delete_archive : bool = True48 ) -> None:49 """Extract all zip archive and replaces name for one of member50 Args:51 archive_path (str) : Path to specific archive.52 out_path (str) : Out path, where all members of archive will be gathered.53 filename (str) : Archive member whose name will be changed.54 filename_replace (str) : Specific name for replacing.55 delete_archive (bool) : Delete archive after unzip or not. Defaults to True.56 """57 driver_folder_path = out_path + 'tmp'58 message = ('Created new safety directory for replacing'59 f'filename: {filename} filename_replace: {filename_replace}')60 logger.info(message)61 if os.path.exists(driver_folder_path):62 shutil.rmtree(driver_folder_path)63 parameters = dict(64 archive_path=archive_path,out_path=driver_folder_path, delete_archive=delete_archive65 )66 if archive_path.endswith('.tar.gz'):67 Extractor.extract_all_tar_gz_archive(**parameters)68 elif archive_path.endswith('.zip'):69 Extractor.extract_all_zip_archive(**parameters)70 else:71 message = f'Unknown archive format was specified archive_path: {archive_path}'72 raise UnknownArchiveFormatException(message)73 old_path = driver_folder_path + os.path.sep + filename74 new_path = driver_folder_path + os.path.sep + filename_replace75 os.rename(old_path, new_path)76 renamed_driver_path = out_path + filename_replace77 if Path(renamed_driver_path).exists():78 Path(renamed_driver_path).unlink()79 copyfile(new_path, renamed_driver_path)80 if Path(driver_folder_path).exists():81 shutil.rmtree(driver_folder_path)82 @staticmethod83 def extract_all_tar_bz2_archive(archive_path: str,84 out_path: str, delete_archive: bool = True) -> None:85 """Extract all members in specific tar.bz2 archive86 Args:87 archive_path (str) : Path to specific archive.88 out_path (str) : Out path, where all members of archive will be gathered.89 delete_archive (bool) : Delete archive after unzip or not. Defaults to True.90 """91 with tarfile.open(archive_path, "r:bz2") as tar_ref:92 tar_ref.extractall(out_path)93 if Path(archive_path).exists() and delete_archive:94 Path(archive_path).unlink()95 @staticmethod96 def extract_all_tar_xz_archive(archive_path: str,97 out_path: str, delete_archive: bool = True) -> None:98 """Extract all members in specific tar.xz archive99 Args:100 archive_path (str) : Path to specific archive.101 out_path (str) : Out path, where all members of archive will be gathered.102 delete_archive (bool) : Delete archive after unzip or not. Defaults to True.103 """104 with tarfile.open(archive_path, "r:xz") as tar_ref:105 tar_ref.extractall(out_path)106 if Path(archive_path).exists() and delete_archive:107 Path(archive_path).unlink()108 @staticmethod109 def extract_and_detect_archive_format(110 archive_path: str,111 out_path: str, delete_archive: bool = True112 ) -> None:113 """Extract and automatic detects archive path format114 Args:115 archive_path (str) : Path to specific archive.116 out_path (str) : Out path, where all members of archive will be gathered.117 delete_archive (bool) : Delete archive after unzip or not. Defaults to True.118 """119 parameters = dict(120 archive_path=archive_path, out_path=out_path, delete_archive=delete_archive121 )122 if archive_path.endswith('.zip'):123 Extractor.extract_all_zip_archive(**parameters)124 elif archive_path.endswith('.tar.gz'):125 Extractor.extract_all_tar_gz_archive(**parameters)126 elif archive_path.endswith('.tar.bz2'):127 Extractor.extract_all_tar_bz2_archive(**parameters)128 else:129 message = f'Unknown archive format was specified archive_path: {archive_path}'130 raise UnknownArchiveFormatException(message)...

Full Screen

Full Screen

delete_archive.py

Source: delete_archive.py Github

copy

Full Screen

...22# language governing permissions and limitations under the License.23import logging24import boto325from botocore.exceptions import ClientError26def delete_archive(vault_name, archive_id):27 """Delete an archive from an Amazon S3 Glacier vault28 :param vault_name: string29 :param archive_id: string30 :return: True if archive was deleted, otherwise False31 """32 # Delete the archive33 glacier = boto3.client('glacier')34 try:35 response = glacier.delete_archive(vaultName=vault_name,36 archiveId=archive_id)37 except ClientError as e:38 logging.error(e)39 return False40 return True41def main():42 """Exercise delete_vault()"""43 # Assign these values before running the program44 test_vault_name = 'VAULT_NAME'45 test_archive_id = 'ARCHIVE_ID'46 # Set up logging47 logging.basicConfig(level=logging.DEBUG,48 format='%(levelname)s: %(asctime)s: %(message)s')49 # Delete the archive50 success = delete_archive(test_vault_name, test_archive_id)51 if success:52 logging.info(f'Deleted archive {test_archive_id} from {test_vault_name}')53if __name__ == '__main__':...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

13 Best Java Testing Frameworks For 2023

The fact is not alien to us anymore that cross browser testing is imperative to enhance your application’s user experience. Enhanced knowledge of popular and highly acclaimed testing frameworks goes a long way in developing a new app. It holds more significance if you are a full-stack developer or expert programmer.

QA Innovation – Using the senseshaping concept to discover customer needs

QA Innovation - Using the senseshaping concept to discover customer needsQA testers have a unique role and responsibility to serve the customer. Serving the customer in software testing means protecting customers from application defects, failures, and perceived failures from missing or misunderstood requirements. Testing for known requirements based on documentation or discussion is the core of the testing profession. One unique way QA testers can both differentiate themselves and be innovative occurs when senseshaping is used to improve the application user experience.

Best 23 Web Design Trends To Follow In 2023

Having a good web design can empower business and make your brand stand out. According to a survey by Top Design Firms, 50% of users believe that website design is crucial to an organization’s overall brand. Therefore, businesses should prioritize website design to meet customer expectations and build their brand identity. Your website is the face of your business, so it’s important that it’s updated regularly as per the current web design trends.

Acquiring Employee Support for Change Management Implementation

Enterprise resource planning (ERP) is a form of business process management software—typically a suite of integrated applications—that assists a company in managing its operations, interpreting data, and automating various back-office processes. The introduction of a new ERP system is analogous to the introduction of a new product into the market. If the product is not handled appropriately, it will fail, resulting in significant losses for the business. Most significantly, the employees’ time, effort, and morale would suffer as a result of the procedure.

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