Best Python code snippet using robotframework-appiumlibrary_python
pull.py
Source:pull.py
1from stimela import logger, LOG_FILE, BASE, utils2from stimela.backends import docker, singularity, podman3def make_parser(subparsers):4 parser = subparsers.add_parser('pull', help='Pull docker stimela base images')5 add = parser.add_argument6 add("-im", "--image", nargs="+", metavar="IMAGE[:TAG]",7 help="Pull base image along with its tag (or version). Can be called multiple times")8 add("-f", "--force", action="store_true",9 help="force pull if image already exists")10 add("-s", "--singularity", action="store_true",11 help="Pull base images using singularity."12 "Images will be pulled into the directory specified by the enviroment varaible, STIMELA_PULLFOLDER. $PWD by default")13 add("-d", "--docker", action="store_true",14 help="Pull base images using docker.")15 add("-p", "--podman", action="store_true",16 help="Pull base images using podman.")17 add("-cb", "--cab-base", nargs="+",18 help="Pull base image for specified cab")19 add("-pf", "--pull-folder",20 help="Images will be placed in this folder. Else, if the environmnental variable 'STIMELA_PULLFOLDER' is set, then images will be placed there. "21 "Else, images will be placed in the current directory")22 parser.set_defaults(func=pull)23def pull(args, conf):24 if args.pull_folder:25 pull_folder = args.pull_folder26 else:27 try:28 pull_folder = os.environ["STIMELA_PULLFOLDER"]29 except KeyError:30 pull_folder = "."31 if args.podman:32 jtype = "podman"33 elif args.singularity:34 jtype = "singularity"35 elif args.docker:36 jtype = "docker"37 else:38 jtype = "docker"39 log = logger.StimelaLogger(LOG_FILE, jtype=jtype)40 images = log.read()['images']41 images_ = []42 for cab in args.cab_base or []:43 if cab in CAB:44 filename = "/".join([stimela.CAB_PATH, cab, "parameters.json"])45 param = utils.readJson(filename)46 tags = param["tag"]47 if not isinstance(tags, list):48 tags = [tags]49 for tag in tags:50 images_.append(":".join([param["base"], tag]))51 args.image = images_ or args.image52 if args.image:53 for image in args.image:54 simage = image.replace("/", "_")55 simage = simage.replace(":", "_") + singularity.suffix56 if args.singularity:57 singularity.pull(58 image, simage, directory=pull_folder, force=args.force)59 elif args.docker:60 docker.pull(image)61 log.log_image(image, 'pulled')62 elif args.podman:63 podman.pull(image)64 log.log_image(image, 'pulled')65 else:66 docker.pull(image)67 log.log_image(image, 'pulled')68 else:69 base = []70 for cab_ in CAB:71 cabdir = "{:s}/{:s}".format(stimela.CAB_PATH, cab_)72 _cab = info(cabdir, display=False)73 tags = _cab.tag74 if not isinstance(tags, list):75 tags = [tags]76 for tag in tags:77 base.append(f"{_cab.base}:{tag}")78 base = set(base)79 for image in base:80 if args.singularity:81 simage = image.replace("/", "_")82 simage = simage.replace(":", "_") + singularity.suffix83 singularity.pull(84 image, simage, directory=pull_folder, force=args.force)85 elif args.docker:86 docker.pull(image, force=args.force)87 log.log_image(image, 'pulled')88 elif args.podman:89 podman.pull(image, force=args.force)90 log.log_image(image, 'pulled')91 else:92 docker.pull(image, force=args.force)93 log.log_image(image, 'pulled')...
record.py
Source:record.py
1import click2import os3import vk.config as config4import vk.utils as utils5class RecordSession:6 def __init__(self, app_name):7 self.app_name = app_name8 def __enter__(self):9 self.old_global_layers = utils.get_debug_vulkan_layers()10 self.old_app_name = utils.get_gpu_debug_app()11 self.old_app_layers = utils.get_gpu_debug_layers()12 self.old_enable_app_layers = utils.get_enable_gpu_debug_layers()13 utils.enable_gpu_debug_layers(True)14 utils.set_debug_vulkan_layers(None)15 utils.set_gpu_debug_app(self.app_name)16 utils.set_gpu_debug_layers(['VK_LAYER_LUNARG_gfxreconstruct'])17 def __exit__(self, exc_type, exc_value, exc_tb):18 utils.set_debug_vulkan_layers(self.old_global_layers)19 utils.enable_gpu_debug_layers(self.old_enable_app_layers)20 utils.set_gpu_debug_app(self.old_app_name)21 utils.set_gpu_debug_layers(self.old_app_layers)22@click.command()23@click.argument('app_name', type=str, default='?')24@click.option('-f', '--filename', default='capture.gfxr', metavar='<trace_name>', help='Set trace name.')25@click.option('--pull', 'pull_folder', type=click.Path(), metavar='<local_folder>',26 help='Pull output files from device to <local_folder>.')27@click.option('--log', 'enable_log', is_flag=True, default=False, help='Write log messages.')28def record(app_name, filename, enable_log, pull_folder):29 """Record API trace of APP_NAME.30 When APP_NAME is ?, its value could be selected later.31 \b32 >> Example 1: Launch com.foo.bar and then record a trace as test.gfxr.33 $ vk record -f test.gfxr com.foo.bar34 \b35 >> Example 2: Launch app from selection, and then record a trace as test.gfxr.36 $ vk record -f test.gfxr ?37 """38 app_name = utils.get_valid_app_name(app_name)39 settings = config.GfxrConfigSettings(app_name)40 utils.stop_app(app_name)41 # utils.adb_cmd(f'shell am kill {app_name}')42 if not filename.endswith('gfxr'):43 filename = f'{filename}.gfxr'44 with RecordSession(app_name) as rec:45 settings.set_capture_options(filename, enable_log=enable_log)46 click.echo(f'Start recording {app_name}...')47 utils.create_folder_if_not_exists(settings.get_trace_folder_on_device())48 utils.start_app(app_name)49 utils.wait_until_app_launch(app_name)50 utils.wait_until_app_exit(app_name)51 click.echo('Finish recording {}'.format(settings.trace_path))52 if pull_folder:53 if not os.path.exists(pull_folder):54 os.makedirs(pull_folder)55 utils.adb_pull(settings.trace_path, pull_folder)56 if enable_log:57 utils.adb_pull(settings.log_path, pull_folder)...
bulk image resizer.py
Source:bulk image resizer.py
2from tkinter import *3from PIL import Image4import os5 6def get_pull_folder():7 pull_folder = filedialog.askdirectory()8 p_folder = Label(root, text = f'Pull Folder: {pull_folder}')9 p_folder.pack()10 return pull_folder11def get_save_folder():12 save_folder = filedialog.askdirectory()13 s_folder = Label(root, text = f'Save folder: {save_folder}')14 s_folder.pack()15 return save_folder16def resize_img():17 message = Label(root, text = 'Resizing has started')18 message.pack()19 for filename in os.listdir(folder_name):20 if filename.endswith('.png'):21 img = Image.open(folder_name + "/" + filename)22 new_img = img.resize((115,115))23 new_img.save(save_folder + "/" + filename)24 print(f' {filename} resized!')25 else: pass26root = Tk()27root.title("Bulk Image Resizer") 28 29folder_name = get_pull_folder()30save_folder = get_save_folder()31resize_button = Button(32 text = "Resize folder Images",33 command = resize_img34 )35resize_button.pack()...
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!!