How to use inventory_directory method in molecule

Best Python code snippet using molecule_python

inventory.py

Source:inventory.py Github

copy

Full Screen

1#!/usr/bin/env python2""" Inventory written by David James Estrin for Dr. Conor Liston lab 3 ================================================================4 This code is generally used to inventory data on a server. Some path 5 variables are manually set based on folder structure. 6 7 Example folder structure:8 __brain1/*9 __lightsheet__|__brain2/*10 _rsync_data_| |__brain3/*11 *|__root__| |__brain4/*12 |_inventory__13 |__lightsheet__14 | |__brain1.txt15 | |__brain2.txt16 | |__brain3.txt17 | |__brain4.txt18 |19 |__lightsheet.txt20"""21import os, glob22class Inventory():23 def __init__(self, root, purpose, status):24 # Create inventory in root directory where purpose is a string25 self.root = root26 self.purpose = purpose27 self.inventory_directory = self.root + "inventory\\" + self.purpose + "\\"28 self.data_directory = self.root + "rsync_data\\" + self.purpose + "\\"29 print(self.inventory_directory)30 print(self.data_directory)31 # Walk through internal functions 32 self.create()33 self.search_inventory(status)34 35 def create(self):36 # Grab all folders in data directory, create an inventory file if not created yet.37 folders = glob.glob((self.data_directory + "*"))38 current_inventory_files = glob.glob((self.inventory_directory + "\\*"))39 40 for file in folders:41 if (str(file)+".txt") in current_inventory_files:42 pass43 else:44 head, tail = os.path.split(file)45 filename=(self.inventory_directory + tail + ".txt")46 with open(filename, 'w') as f:47 f.write('raw')48 f.close()49 return 50 51 def search_inventory(self, status):52 # Read every text file in inventory and search for a certain status53 # Example, search for all new files by searching for "raw"54 brains = glob.glob((self.inventory_directory + "\\*"))55 56 found_brains = []57 for brain in brains:58 with open(brain, 'r') as f:59 last_line = f.readlines()[-1]60 61 if last_line == status:62 found_brains.append(brain)63 64 if os.path.exists((self.root+"\inventory\\"+self.purpose+".txt")):65 os.remove((self.root+"\inventory\\" + self.purpose + ".txt"))66 67 with open((self.root+"\inventory\\"+self.purpose+".txt"), 'w') as output:68 for item in found_brains:69 output.write("%s\n" % item)70 output.close()71 72 return 73 74 def update_status(self, brain_oh, new_status):75 # Update a specific brain's new status when it is finished a step76 brains = glob.glob((self.inventory_directory + "*"))77 78 for brain in brains:79 if brain==brain_oh:80 with open(brain, 'w') as f:81 f.write(new_status)82 f.close()83 return84 85if __name__ == "__main__":86 # Root directory87 root="C:\\Users\\David\\Desktop\\dje4001\\"88 print(root)89 # Create Inventory...

Full Screen

Full Screen

inventory-check.py

Source:inventory-check.py Github

copy

Full Screen

1import argparse2import boto33from botocore.exceptions import ClientError4from urllib.parse import unquote5import time6from smart_open import open7import os8import sys9s3 = boto3.resource('s3')10parser = argparse.ArgumentParser(11 description="Analyze Inventory Files")12parser.add_argument('--inventory_file', '-i',13 help='The file that has a csv formatted list of inventory to check. The first column of the CSV is the bucket, the second column is the key. This can be an S3 object or local file. It can also be gzipped.')14parser.add_argument('--inventory_directory',15 help='A directory with a set of inventories. this will recursively iterate across all folders/files.')16parser.add_argument(17 '--env', action='store_true', help="use the AWS environment variables for aws_access_key_id and aws_secret_access_key values")18parser.add_argument(19 "--profile", help='Use a specific AWS Profile'20)21args = parser.parse_args()22start_time = time.localtime()23inventory_file = args.inventory_file24inventory_directory = args.inventory_directory25env = args.env26profile = args.profile27object_list = []28response_list = []29object_count = 030total_records = 031if (not inventory_file) and (not inventory_directory):32 print("--inventory_file or --inventory_directory is required")33 exit()34# I'm sure there is a way to do this more elegantly...35# First priority: If --env is specified, use the environment variables36# Second priority: if --profile is specified, use the profile name37# Last priority: if nothing is specified, use the current user38if env:39 try:40 s3_client = boto3.client(41 's3',42 aws_access_key_id=os.environ['AWS_ACCESS_KEY_ID'],43 aws_secret_access_key=os.environ['AWS_SECRET_ACCESS_KEY']44 )45 print(os.environ)46 except Exception as err:47 print(err)48 exit()49elif profile:50 boto3.setup_default_session(profile_name=profile)51 s3_client = boto3.client('s3')52else:53 s3_client = boto3.client('s3')54if inventory_file:55 print(f"Analyzing inventory file...")56 total_records = len(open(inventory_file).readlines())57 print("Number of records in the " + inventory_file +58 " inventory file: " + str(total_records))59if inventory_directory:60 print("Walking directory " + os.path.abspath(inventory_directory))61 for dirpath, dirs, files in os.walk(inventory_directory):62 for f in files:63 inv_file = dirpath + "/" + f64 # print("Inv File: " + inv_file)65 records_files = len(open(inv_file).readlines())66 # print("Num records in " + inv_file)...

Full Screen

Full Screen

getservers.py

Source:getservers.py Github

copy

Full Screen

1#/usr/bin/python234import json5import requests6import os7import shutil89inventory_directory = "/apps/scripts/ssh_key_rotation/inventory"1011if not os.path.exists(inventory_directory):12 os.makedirs(inventory_directory)131415requests.packages.urllib3.disable_warnings()1617projects = '{"projects": [{"name": "partnerPortal","landscape": ["dev03", "dev04"],"apptype": ["author", "publish", "webserver"]},{"name": "acom","landscape": ["dev04", "qa04"],"apptype": ["author", "publish"]}]}'1819projects = json.loads(projects)2021for project in projects['projects']:22 shutil.rmtree(inventory_directory+"/"+project['name'])23 for landscape in project['landscape']:24 for apptype in project['apptype']:25 url = "https://wcms-hostdb.com/cgi-bin/appservers.py?project="+project['name']+"&landscape="+landscape+"&apptype="+apptype26 resp = requests.get(url, verify=False)27 json_resp = resp.json()28 if len(json_resp) > 0:29 dir = inventory_directory+"/"+project['name']+"/"+landscape30 if not os.path.exists(dir):31 os.makedirs(dir)32 open(dir+"/"+apptype, 'w').close()33 f=open(dir+"/"+apptype, "a+")34 for host in json_resp:35 host = json.dumps(host).strip('["').strip('"]')36 f.write("%s\n" % host) ...

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 molecule 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