Best Python code snippet using localstack_python
install.py
Source:install.py
...423 patch_url = f"{SFN_PATCH_URL_PREFIX}/{patch_class}"424 add_file_to_jar(patch_class, patch_url, target_jar=INSTALL_PATH_STEPFUNCTIONS_JAR)425 # add additional classpath entries to JAR manifest file426 classpath = " ".join([os.path.basename(jar) for jar in JAR_URLS])427 update_jar_manifest(428 "StepFunctionsLocal.jar",429 INSTALL_DIR_STEPFUNCTIONS,430 "Class-Path: . ",431 f"Class-Path: {classpath} . ",432 )433 update_jar_manifest(434 "StepFunctionsLocal.jar",435 INSTALL_DIR_STEPFUNCTIONS,436 re.compile("Main-Class: .+"),437 "Main-Class: cloud.localstack.StepFunctionsStarter",438 )439 # download additional jar libs440 for jar_url in JAR_URLS:441 target = os.path.join(INSTALL_DIR_STEPFUNCTIONS, os.path.basename(jar_url))442 if not file_exists_not_empty(target):443 download(jar_url, target)444 # download aws-sdk lambda handler445 target = os.path.join(INSTALL_DIR_STEPFUNCTIONS, "localstack-internal-awssdk", "awssdk.zip")446 if not file_exists_not_empty(target):447 download(SFN_AWS_SDK_LAMBDA_ZIP_FILE, target)448def add_file_to_jar(class_file, class_url, target_jar, base_dir=None):449 base_dir = base_dir or os.path.dirname(target_jar)450 patch_class_file = os.path.join(base_dir, class_file)451 if not os.path.exists(patch_class_file):452 download(class_url, patch_class_file)453 run(["zip", target_jar, class_file], cwd=base_dir)454def install_dynamodb_local():455 if not os.path.exists(INSTALL_PATH_DDB_JAR):456 log_install_msg("DynamoDB")457 # download and extract archive458 tmp_archive = os.path.join(tempfile.gettempdir(), "localstack.ddb.zip")459 download_and_extract_with_retry(DYNAMODB_JAR_URL, tmp_archive, INSTALL_DIR_DDB)460 # download additional libs for Mac M1 (for local dev mode)461 ddb_local_lib_dir = os.path.join(INSTALL_DIR_DDB, "DynamoDBLocal_lib")462 if is_mac_os() and get_arch() == "arm64":463 target_path = os.path.join(ddb_local_lib_dir, "libsqlite4java-osx-aarch64.dylib")464 if not file_exists_not_empty(target_path):465 download(LIBSQLITE_AARCH64_URL, target_path)466 # fix logging configuration for DynamoDBLocal467 log4j2_config = """<Configuration status="WARN">468 <Appenders>469 <Console name="Console" target="SYSTEM_OUT">470 <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>471 </Console>472 </Appenders>473 <Loggers>474 <Root level="WARN"><AppenderRef ref="Console"/></Root>475 </Loggers>476 </Configuration>"""477 log4j2_file = os.path.join(INSTALL_DIR_DDB, "log4j2.xml")478 save_file(log4j2_file, log4j2_config)479 run_safe(lambda: run(["zip", "-u", "DynamoDBLocal.jar", "log4j2.xml"], cwd=INSTALL_DIR_DDB))480 # download agent JAR481 if not os.path.exists(DDB_AGENT_JAR_PATH):482 download(DDB_AGENT_JAR_URL, DDB_AGENT_JAR_PATH)483 if not os.path.exists(JAVASSIST_JAR_PATH):484 download(JAVASSIST_JAR_URL, JAVASSIST_JAR_PATH)485 # patch/update libraries with known CVEs486 upgrade_jar_file(487 ddb_local_lib_dir,488 "jackson-databind-*.jar",489 "com/fasterxml/jackson/core/jackson-databind:2.13.3",490 )491 upgrade_jar_file(ddb_local_lib_dir, "slf4j-ext-*.jar", "org/slf4j/slf4j-ext:1.8.0-beta4")492 # ensure that javassist.jar is in the manifest classpath493 update_jar_manifest(494 "DynamoDBLocal.jar", INSTALL_DIR_DDB, "Class-Path:", "Class-Path: javassist.jar"495 )496 update_jar_manifest(497 "DynamoDBLocal.jar", INSTALL_DIR_DDB, "databind-2.12.3.jar", "databind-2.13.3.jar"498 )499def update_jar_manifest(500 jar_file_name: str, parent_dir: str, search: Union[str, re.Pattern], replace: str501):502 manifest_file_path = "META-INF/MANIFEST.MF"503 run(["unzip", "-o", jar_file_name, manifest_file_path], cwd=parent_dir)504 manifest_file = os.path.join(parent_dir, manifest_file_path)505 manifest = load_file(manifest_file)506 if replace not in manifest:507 if isinstance(search, re.Pattern):508 manifest = search.sub(replace, manifest, 1)509 else:510 manifest = manifest.replace(search, replace, 1)511 save_file(manifest_file, manifest)512 run(["zip", jar_file_name, manifest_file_path], cwd=parent_dir)513 os.remove(manifest_file)...
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!!