Best Python code snippet using localstack_python
localstack.py
Source:localstack.py  
...52    try:53        health = requests.get(f"{url}/health")54        doc = health.json()55        services = doc.get("services", [])56        print_service_table(services)57    except requests.ConnectionError:58        err = "[bold][red]:heavy_multiplication_x: ERROR[/red][/bold]"59        console.print(f"{err}: could not connect to LocalStack health endpoint at {url}")60        if config.DEBUG:61            console.print_exception()62        sys.exit(1)63@localstack.command(name="start", help="Start LocalStack")64@click.option("--docker", is_flag=True, help="Start LocalStack in a docker container (default)")65@click.option("--host", is_flag=True, help="Start LocalStack directly on the host")66@click.option("--no-banner", is_flag=True, help="Disable LocalStack banner", default=False)67def cmd_start(docker: bool, host: bool, no_banner: bool):68    if docker and host:69        raise click.ClickException("Please specify either --docker or --host")70    if not no_banner:71        print_banner()72        print_version()73        console.line()74    from localstack.utils import bootstrap75    if not no_banner:76        if host:77            console.log("starting LocalStack in host mode :laptop_computer:")78        else:79            console.log("starting LocalStack in Docker mode :whale:")80        console.rule("LocalStack Runtime Log (press [bold][yellow]CTRL-C[/yellow][/bold] to quit)")81    if host:82        bootstrap.start_infra_locally()83    else:84        bootstrap.start_infra_in_docker()85@localstack_config.command(86    name="validate", help="Validate your LocalStack configuration (e.g., your docker-compose.yml)"87)88@click.option(89    "--file",90    default="docker-compose.yml",91    type=click.Path(exists=True, file_okay=True, readable=True),92)93def cmd_config_validate(file):94    from rich.panel import Panel95    from localstack.utils import bootstrap96    try:97        if bootstrap.validate_localstack_config(file):98            console.print("[green]:heavy_check_mark:[/green] config valid")99            sys.exit(0)100        else:101            console.print("[red]:heavy_multiplication_x:[/red] validation error")102            sys.exit(1)103    except Exception as e:104        console.print(Panel(str(e), title="[red]Error[/red]", expand=False))105        console.print("[red]:heavy_multiplication_x:[/red] validation error")106        sys.exit(1)107@localstack.command(name="ssh", help="Obtain a shell in the running LocalStack container")108def cmd_ssh():109    from localstack import config110    from localstack.utils.docker_utils import DOCKER_CLIENT111    from localstack.utils.run import run112    if not DOCKER_CLIENT.is_container_running(config.MAIN_CONTAINER_NAME):113        raise click.ClickException(114            'Expected a running container named "%s", but found none' % config.MAIN_CONTAINER_NAME115        )116    try:117        process = run("docker exec -it %s bash" % config.MAIN_CONTAINER_NAME, tty=True)118        process.wait()119    except KeyboardInterrupt:120        pass121# legacy support122@localstack.group(123    name="infra",124    help="Manipulate LocalStack infrastructure (legacy)",125)126def infra():127    pass128@infra.command("start")129@click.pass_context130@click.option("--docker", is_flag=True, help="Start LocalStack in a docker container (default)")131@click.option("--host", is_flag=True, help="Start LocalStack directly on the host")132def cmd_infra_start(ctx, *args, **kwargs):133    ctx.invoke(cmd_start, *args, **kwargs)134def print_docker_status():135    from rich.table import Table136    from localstack import config137    from localstack.utils import docker138    from localstack.utils.bootstrap import (139        get_docker_image_details,140        get_main_container_ip,141        get_main_container_name,142        get_server_version,143    )144    grid = Table(show_header=False)145    grid.add_column()146    grid.add_column()147    # version148    grid.add_row("Runtime version", "[bold]%s[/bold]" % get_server_version())149    # image150    img = get_docker_image_details()151    grid.add_row(152        "Docker image", "tag: %s, id: %s, :calendar: %s" % (img["tag"], img["id"], img["created"])153    )154    # container155    cont_name = config.MAIN_CONTAINER_NAME156    running = docker.DOCKER_CLIENT.is_container_running(cont_name)157    cont_status = "[bold][red]:heavy_multiplication_x: stopped"158    if running:159        cont_status = '[bold][green]:heavy_check_mark: running[/green][/bold] (name: "[italic]%s[/italic]", IP: %s)' % (160            get_main_container_name(),161            get_main_container_ip(),162        )163    grid.add_row("Runtime status", cont_status)164    console.print(grid)165def print_service_table(services: Dict[str, str]):166    from rich.table import Table167    status_display = {168        "running": "[green]:heavy_check_mark:[/green] running",169        "starting": ":hourglass_flowing_sand: starting",170        "available": "[grey]:heavy_check_mark:[/grey] available",171        "error": "[red]:heavy_multiplication_x:[/red] error",172    }173    table = Table()174    table.add_column("Service")175    table.add_column("Status")176    services = [(k, v) for k, v in services.items()]177    services.sort(key=lambda item: item[0])178    for service, status in services:179        if status in status_display:...enumerate_service_table.py
Source:enumerate_service_table.py  
...59            continue60        function_address = function_offset + offset_base61        yield syscall_id, function_address62        63def print_service_table():64    for syscall_id, function_address in enumerate_service_table():65        function_name = Name(function_address)66        print '%04x - %s' % (syscall_id, function_name)...gen_service_table.py
Source:gen_service_table.py  
...26        ("getid", "exception_getid"),27        ("raise", "exception_raise"),28    ])29]30def print_service_table(ksupport_elf_filename):31    with open(ksupport_elf_filename, "rb") as f:32        elf = ELFFile(f)33        symtab = elf.get_section_by_name(b".symtab")34        symbols = {symbol.name: symbol.entry.st_value35                   for symbol in symtab.iter_symbols()}36    for name, contents in services:37        print("static const struct symbol {}[] = {{".format(name))38        for name, value in contents:39            print("    {{\"{}\", (void *)0x{:08x}}},"40                  .format(name, symbols[bytes(value, "ascii")]))41        print("    {NULL, NULL}")42        print("};")43def main():44    if len(sys.argv) == 2:45        print_service_table(sys.argv[1])46    else:47        print("Incorrect number of command line arguments")48        sys.exit(1)49if __name__ == "__main__":...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!!
