Best Python code snippet using prospector_python
list
Source: list
...11from optparse import OptionParser12__version__ = "1.0.0"13__minimum_durian_version__ = "1.0.0"14__description__ = "print list of available definitions/seeds/mirrors"15def find_from_path(paths, suffixes = ["", ".cfg"], names = [], \16 syntax_checker = None):17 """\18 Returns a dictionary of all available names on path. The19 dictionary key is the name (filname without suffix) and the value20 is its filename (full path). If @names is given, the result will21 only include the given names.22 """23 def get_name(filename):24 return os.path.splitext(os.path.split(filename)[1])[0]25 result = {}26 for name in names:27 if os.path.isabs(name) and os.path.isfile(name) and \28 (not syntax_checker or syntax_checker(name)):29 result[get_name(name)] = name30 if names and len(result) == len(names):31 return result32 for path in paths:33 try:34 for filename in os.listdir(path):35 name = get_name(filename)36 if name in result or \37 names and name not in names: continue38 filepath = os.path.join(path, filename)39 if filename.startswith(".") or filename.endswith("~") or \40 not os.path.isfile(filepath) or \41 os.path.splitext(filename)[1] not in suffixes:42 continue43 if not syntax_checker or syntax_checker(filepath):44 result[name] = filepath45 except Exception:46 pass47 return result48def check_seed_syntax(seed_file):49 global OPTIONS50 if seed_file.endswith(".superseed"):51 return superseed_check(seed_file)52 retcode = 053 try:54 kwargs = {"stdout": subprocess.PIPE, "stderr": subprocess.PIPE} \55 if OPTIONS.quiet else {}56 retcode = subprocess.call(["debconf-set-selections", "-c", \57 seed_file], **kwargs)58 except Exception as e:59 if not OPTIONS.quiet:60 sys.stderr.write("Could not verify '{0}' syntax with " \61 "debconf-set-selections. {1}" \62 .format(seed_file, e))63 return retcode == 064def superseed_check(seed_file):65 return os.access(seed_file, os.X_OK)66if __name__ == "__main__":67 parser = OptionParser()68 parser.add_option("-c", "--syntax-check", dest = "syntax_check", \69 action = "store_true", default = False, \70 help = "Enable seed file syntax checking")71 parser.add_option("-q", "--quiet", dest = "quiet", \72 action = "store_true", default = False, \73 help = "Do not print errors")74 parser.add_option("-s", "--superseeds", dest = "superseeds", \75 action = "store_true", default = False, \76 help = "print superseeds in seeds listing")77 parser.add_option("-v", "--version", dest = "version", \78 action = "store_true", default = False, \79 help = "Print plugin version and exit")80 parser.set_description(__doc__)81 parser.set_usage("list [-v|--version] [-h|--help] [-c|--syntax-check]" \82 "[-q|--quiet] <definitions|seeds|superseeds|mirrors> " \83 "<args>")84 OPTIONS, ARGS = parser.parse_args()85 if OPTIONS.version:86 sys.stdout.write("desctiption: {0}\n".format(__description__))87 sys.stdout.write("version: {0}\n".format(__version__))88 sys.stdout.write("minimum durian version: {0}\n" \89 .format(__minimum_durian_version__))90 exit(0)91 ARGS = ARGS or ["definitions"]92 if ARGS[0] in ["def", "defs", "definition", "definitions"]:93 defs = find_from_path(os.environ.get("DEFINITIONS_PATH", "") \94 .split(":"), \95 suffixes = ["", ".cfg", ".def"], \96 names = ARGS[1:])97 if defs:98 format_string = "{{0:<{0}}} {{1}}" \99 .format(max(len(i) for i in defs.keys()) + 1)100 sys.stdout.write("\n".join(format_string.format(k, v) \101 for k, v in defs.items()))102 sys.stdout.write("\n")103 elif ARGS[0] in ["seed", "seeds"]:104 seeds = find_from_path(os.environ.get("SEEDS_PATH", "").split(":"), \105 suffixes = ["", ".cfg", ".seed", ".preseed"] + \106 ([".superseed"] \107 if OPTIONS.superseeds else []), \108 names = ARGS[1:], \109 syntax_checker = check_seed_syntax if \110 OPTIONS.syntax_check else None)111 if seeds:112 format_string = "{{0:<{0}}} {{1}}" \113 .format(max(len(i) for i in seeds.keys()) + 1)114 sys.stdout.write("\n".join(format_string.format(k, v) \115 for k, v in seeds.items()))116 sys.stdout.write("\n")117 elif ARGS[0] in ["superseed", "superseeds"]:118 seeds = find_from_path(os.environ.get("SEEDS_PATH", "").split(":"), \119 suffixes = [".superseed"], \120 names = ARGS[1:], \121 syntax_checker = superseed_check)122 if seeds:123 format_string = "{{0:<{0}}} {{1}}" \124 .format(max(len(i) for i in seeds.keys()) + 1)125 sys.stdout.write("\n".join(format_string.format(k, v) \126 for k, v in seeds.items()))127 sys.stdout.write("\n")128 elif ARGS[0] in ["mirror", "mirrors"]:129 mirrors = find_from_path(os.environ.get("MIRRORS_PATH", "") \130 .split(":"), suffixes = ["", ".cfg", \131 ".mirror", ".debmirror"])132 if len(ARGS) == 1:133 if mirrors:134 format_string = "{{0:<{0}}} {{1}}" \135 .format(max(len(i) for i in mirrors.keys()) + 1)136 sys.stdout.write("\n".join(format_string.format(k, v) \137 for k, v in mirrors.items()))138 sys.stdout.write("\n")139 else:140 sys.stderr.write("Invalid number of arguments for mirror.\n")141 exit(1)142 else:143 sys.stdout.write("Invalid list name.\n")...
autodetect.py
Source: autodetect.py
...28 for import_name in import_names:29 if import_name in POSSIBLE_LIBRARIES:30 names.add(import_name)31 return names32def find_from_path(path):33 names = set()34 max_possible = len(POSSIBLE_LIBRARIES)35 for item in os.listdir(path):36 item_path = os.path.abspath(os.path.join(path, item))37 if os.path.isdir(item_path):38 if is_virtualenv(item_path):39 continue40 names |= find_from_path(item_path)41 elif not os.path.islink(item_path) and item_path.endswith(".py"):42 try:43 contents = encoding.read_py_file(item_path)44 names |= find_from_imports(contents)45 except encoding.CouldNotHandleEncoding as err:46 # TODO: this output will break output formats such as JSON47 warnings.warn("{0}: {1}".format(err.path, err.cause), ImportWarning)48 if len(names) == max_possible:49 # don't continue on recursing, there's no point!50 break51 return names52def find_from_requirements(path):53 reqs = find_requirements(path)54 names = []55 for requirement in reqs:56 if requirement.name is not None and requirement.name.lower() in POSSIBLE_LIBRARIES:57 names.append(requirement.name.lower())58 return names59def autodetect_libraries(path):60 if os.path.isfile(path):61 path = os.path.dirname(path)62 if path == "":63 path = "."64 libraries = []65 try:66 libraries = find_from_requirements(path)67 # pylint: disable=pointless-except68 except RequirementsNotFound:69 pass70 if len(libraries) < len(POSSIBLE_LIBRARIES):71 libraries = find_from_path(path)...
Check out the latest blogs from LambdaTest on this topic:
“Test frequently and early.” If you’ve been following my testing agenda, you’re probably sick of hearing me repeat that. However, it is making sense that if your tests detect an issue soon after it occurs, it will be easier to resolve. This is one of the guiding concepts that makes continuous integration such an effective method. I’ve encountered several teams who have a lot of automated tests but don’t use them as part of a continuous integration approach. There are frequently various reasons why the team believes these tests cannot be used with continuous integration. Perhaps the tests take too long to run, or they are not dependable enough to provide correct results on their own, necessitating human interpretation.
As a developer, checking the cross browser compatibility of your CSS properties is of utmost importance when building your website. I have often found myself excited to use a CSS feature only to discover that it’s still not supported on all browsers. Even if it is supported, the feature might be experimental and not work consistently across all browsers. Ask any front-end developer about using a CSS feature whose support is still in the experimental phase in most prominent web browsers. ????
Have you ever visited a website that only has plain text and images? Most probably, no. It’s because such websites do not exist now. But there was a time when websites only had plain text and images with almost no styling. For the longest time, websites did not focus on user experience. For instance, this is how eBay’s homepage looked in 1999.
Recently, I was going through some of the design patterns in Java by reading the book Head First Design Patterns by Eric Freeman, Elisabeth Robson, Bert Bates, and Kathy Sierra.
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!!