How to use traverse_file_tree method in localstack

Best Python code snippet using localstack_python

PyiCloud_uploader.py

Source:PyiCloud_uploader.py Github

copy

Full Screen

...6import os7import pprint8from Classes import File_Tree_Node, build_file_tree9from utils import authenticate_session, get_environment_variables, render_target_directory, render_tree, rename_file10def traverse_file_tree(File_Tree_Node_object):11 current_folder, formatted = build_file_tree(File_Tree_Node_object)12 available_folders = [i for i in current_folder.children if i.get('type') == 'folder']13 available_names = [list(i.keys())[-1] for i in available_folders]14 # check that the selected child folder is valid15 # for this we iterate over the metadata attributes exposed for this purpose in File_Tree_Node.children16 # if valid, use metadata key to get index of specific object in list of children, start a new search in that child17 # since python3 dicts are ordered, we trust that indices match between the 2 iterables18 dir = render_tree(formatted)19 if dir.split(' ')[0] == 'ls':20 dir = ' '.join(dir.split(' ')[1:])21 current_folder = available_folders[available_names.index(dir)].get('child')22 return traverse_file_tree(current_folder)23 if dir.lower() == 'here':24 return current_folder25 if dir.lower() == 'root':26 return traverse_file_tree(iCloud_client.drive.root)27 else:28 if dir in available_names:29 current_folder = File_Tree_Node(available_folders[available_names.index(dir)].get('child'))30 return current_folder31 else:32 print(f'\nFolder {dir} not present!\n')33 return traverse_file_tree(current_folder)34def integrity_check(local_path, DriveNode_object, is_root_node=False, overwrite_intended=False, to_delete_file=None):35 checker_session = pyicloud.PyiCloudService(user,password)36 checker_session_node = checker_session.drive.get_node_data(node_id=DriveNode_object.data.get("docwsid"))37 actually_existing_items = [f'{i.get("name")}.{i.get("extension")}' for i in checker_session_node.get("items")]38 if local_path.name in actually_existing_items:39 if overwrite_intended == True:40 deleted_node = checker_session.drive.move_items_to_trash(41 to_delete_file.get('drivewsid'),42 to_delete_file.get('etag'),43 )44 return local_path.name, deleted_node45 else:46 return local_path.name, {}47def upload_archive(local_path, DriveNode_object, is_root_node=False, existing_item=None, overwrite_intended=False, to_delete_file=None):48 if overwrite_intended == True and existing_item:49 try:50 renamed_name=f"{'.'.join(existing_item.name.split('.')[:-1])}_deleteme.{existing_item.name.split('.')[-1]}"51 to_delete_file = existing_item.rename(renamed_name)['items'][0]52 except Exception as e:53 raise e54 os.chdir(local_path.parents[0])55 with open(local_path.name, 'rb') as archive:56 try:57 DriveNode_object.upload(archive)58 except Exception as e:59 raise e60 # iCloud API does not return on success, so verify (before deleting, if applicable)61 return integrity_check(62 local_path,63 DriveNode_object,64 is_root_node,65 overwrite_intended,66 to_delete_file67 )68def generate_upload_params(DriveNode_object, local_file, selection_final=False):69 starting_dir = traverse_file_tree(DriveNode_object)70 if starting_dir.parent is None:71 is_root_node = True72 else:73 is_root_node = False74 to_upload_path = local_file75 existing_item = None76 overwrite_intended = False77 # File_Tree_Node wrapper class methods and attributes are only needed to traverse the filesystem78 # we now de-encapsulate the DriveNode class to access methods to upload, rename, or delete files79 starting_dir = starting_dir.drive_node80 try:81 items = starting_dir.dir()82 if local_file.name not in items:83 selection_final = True...

Full Screen

Full Screen

diagnose.py

Source:diagnose.py Github

copy

Full Screen

...115def get_service_stats() -> Dict[str, str]:116 from localstack.services.plugins import SERVICE_PLUGINS117 return {service: state.value for service, state in SERVICE_PLUGINS.get_states().items()}118def get_file_tree() -> Dict[str, List[str]]:119 return {d: traverse_file_tree(d) for d in INSPECT_DIRECTORIES}120def traverse_file_tree(root: str) -> List[str]:121 try:122 result = []123 if config.in_docker():124 for root, _, _ in os.walk(root):125 result.append(root)126 return result127 except Exception as e:128 return ["traversing files failed %s" % e]129def get_docker_image_details() -> Dict[str, str]:130 return bootstrap.get_docker_image_details()131def get_host_kernel_version() -> str:...

Full Screen

Full Screen

main.py

Source:main.py Github

copy

Full Screen

1import argparse2import os3from settings import DEFAULT_FILE_NAME, HTML_HEAD, BODY_HEAD, BODY_CLOSE_TAG, QUERY_SCRIPT, IMAGE_FILE_FORMATS4def traverse_file_tree(source_path, target_path):5 for item in os.listdir(source_path):6 if os.path.isdir(os.path.join(source_path, item)):7 traverse_file_tree(os.path.join(source_path, item), target_path)8 else:9 print(os.path.join(source_path, item))10 file = os.path.splitext(item)11 if len(file) > 1 and file[1] in IMAGE_FILE_FORMATS:12 html = "<tr>\n" + \13 "<td>" + source_path + "</td>\n" + \14 "<td>" + item + "</td>\n" + \15 "</tr>\n"16 f = open(os.path.join(target_path, DEFAULT_FILE_NAME), "a")17 f.write(html)18 f.close()19def generate_html(source_path, target_path):20 """21 HTML code has been adapted from:22 https://www.w3schools.com/bootstrap/tryit.asp?filename=trybs_filters_table&stacked=h23 :param source_path:24 :param target_path:25 :return:26 """27 # Loop through Folders and Create index details28 f = open(os.path.join(target_path, DEFAULT_FILE_NAME), "w")29 f.write(HTML_HEAD +30 BODY_HEAD)31 f.close()32 print("Browse directory ...")33 traverse_file_tree(source_path, target_path)34 # Write HTML code to file35 print("Finish file ...")36 f = open(os.path.join(target_path, DEFAULT_FILE_NAME), "a")37 f.write(BODY_CLOSE_TAG +38 QUERY_SCRIPT)39 f.close()40def generate_file_list(read_from, output_path):41 if not os.path.exists(output_path):42 os.makedirs(output_path, mode=777)43 # Creates HTML file image_index.html44 generate_html(read_from, output_path)45def parse_and_store_arguments():46 # Initiate the parser47 parser = argparse.ArgumentParser()...

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