Best Python code snippet using lisa_python
snippet.py
Source:snippet.py
...8 '192.168.1.11', 9 '192.168.1.12', 10 '192.168.1.13', 11]12def _get_package_list():13 """14 Get the list of currently installed packages and versions via pip freeze15 """16 with settings(17 hide('warnings', 'running', 'stdout', 'stderr'),18 warn_only=True19 ):20 return run("%sbin/pip freeze -l" % venv)21def _process_packages(packages):22 """23 Convert the packages datastructure into the multiple versions and missing24 servers lists and output the result25 """26 multi_versions = {}27 missing_servers = []28 for package, versions in packages.items():29 if len(versions.keys()) > 1:30 # There is more than one version installed on the servers31 multi_versions[package] = versions32 elif len(versions[versions.keys()[0]]) != len(env.hosts):33 # The package is not installed on all the servers34 missing_hosts = set(env.hosts) - set(versions[versions.keys()[0]])35 missing_servers.append(36 "%s: %s" % (package, ", ".join(missing_hosts))37 )38 if missing_servers or multi_versions:39 print ""40 print "Packages out-of-sync:"41 if multi_versions:42 print ""43 print "Multiple versions found of these packages:"44 for package, versions in multi_versions.items():45 print package46 for ver, servers in versions.items():47 print " %s: %s" % (ver, ", ".join(servers))48 if missing_servers:49 print ""50 print "These packages are missing on these servers:"51 for item in missing_servers:52 print item53@runs_once54def check_package_versions():55 """56 Check the versions of all the packages on all the servers and print out57 the out of sync packages58 """59 packages = {}60 for host in env.hosts:61 with settings(host_string=host):62 print "Getting packages on %s" % host63 result = _get_package_list()64 pkg_list = result.splitlines()65 for package in pkg_list:66 if package.startswith("-e"):67 version, pkg = package.split("#egg=")68 else:69 pkg, version = package.split("==")70 if pkg not in packages:71 packages[pkg] = {}72 if version not in packages[pkg]:73 packages[pkg][version] = []74 packages[pkg][version].append(host)...
DirectorySearch.py
Source:DirectorySearch.py
...3import glob4class DirectorySearch:5 def __init__(self, root_path):6 target_directory = pathlib.Path(root_path).resolve()7 self.pkg_list = self._get_package_list(target_directory)8 self.component_list = []9 for p in self.pkg_list:10 for c in self._get_component_list(p):11 self.component_list.append([p,c])12 def getComponentPathPairList(self):13 return self.component_list14 def getPackagePathList(self):15 return self.pkg_list16 def _get_package_list(self, target_directory):17 return glob.glob(str(target_directory) + '/*/package.xml', recursive = True)18 def _get_component_list(self, pkg_path):19 pkg_dir = pathlib.Path(pkg_path+"/..").resolve()20 return glob.glob(str(pkg_dir) + '/*/*.roborecipe', recursive = True)21if __name__ == '__main__':22 ds = DirectorySearch('../sample')...
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!!