Best Python code snippet using behave
make_localpi.py
Source:make_localpi.py
...95 for pattern in cls.PATTERNS:96 if fnmatch(filename, pattern):97 return True98 return False99def make_index_for(package, index_dir, verbose=True):100 """101 Create an 'index.html' for one package.102 :param package: Package object to use.103 :param index_dir: Where 'index.html' should be created.104 """105 index_template = """\106<html>107<head><title>{title}</title></head>108<body>109<h1>{title}</h1>110<ul>111{packages}112</ul>113</body>114</html>115"""116 item_template = '<li><a href="{1}">{0}</a></li>'117 index_filename = os.path.join(index_dir, "index.html")118 if not os.path.isdir(index_dir):119 os.makedirs(index_dir)120 parts = []121 for pkg_filename in package.files:122 pkg_name = os.path.basename(pkg_filename)123 if pkg_name == "index.html":124 # -- ROOT-INDEX:125 pkg_name = os.path.basename(os.path.dirname(pkg_filename))126 else:127 pkg_name = package.splitext(pkg_name)128 pkg_relpath_to = os.path.relpath(pkg_filename, index_dir)129 parts.append(item_template.format(pkg_name, pkg_relpath_to))130 if not parts:131 print("OOPS: Package %s has no files" % package.name)132 return133 if verbose:134 root_index = not Package.isa(package.files[0])135 if root_index:136 info = "with %d package(s)" % len(package.files)137 else:138 package_versions = sorted(set(package.versions))139 info = ", ".join(reversed(package_versions))140 message = "%-30s %s" % (package.name, info)141 print(message)142 with open(index_filename, "w") as f:143 packages = "\n".join(parts)144 text = index_template.format(title=package.name, packages=packages)145 f.write(text.strip())146 f.close()147def make_package_index(download_dir):148 """149 Create a pypi server like file structure below download directory.150 :param download_dir: Download directory with packages.151 EXAMPLE BEFORE:152 +-- downloads/153 +-- alice-1.0.zip154 +-- alice-1.0.tar.gz155 +-- bob-1.3.0.tar.gz156 +-- bob-1.4.2.tar.gz157 +-- charly-1.0.tar.bz2158 EXAMPLE AFTERWARDS:159 +-- downloads/160 +-- simple/161 | +-- alice/index.html --> ../../alice-*.*162 | +-- bob/index.html --> ../../bob-*.*163 | +-- charly/index.html --> ../../charly-*.*164 | +-- index.html --> alice/index.html, bob/index.html, ...165 +-- alice-1.0.zip166 +-- alice-1.0.tar.gz167 +-- bob-1.3.0.tar.gz168 +-- bob-1.4.2.tar.gz169 +-- charly-1.0.tar.bz2170 """171 if not os.path.isdir(download_dir):172 raise ValueError("No such directory: %r" % download_dir)173 pkg_rootdir = os.path.join(download_dir, "simple")174 if os.path.isdir(pkg_rootdir):175 shutil.rmtree(pkg_rootdir, ignore_errors=True)176 os.mkdir(pkg_rootdir)177 # -- STEP: Collect all packages.178 package_map = {}179 packages = []180 for filename in sorted(os.listdir(download_dir)):181 if not Package.isa(filename):182 continue183 pkg_filepath = os.path.join(download_dir, filename)184 package_name = Package.get_pkgname(pkg_filepath)185 package = package_map.get(package_name, None)186 if not package:187 # -- NEW PACKAGE DETECTED: Store/register package.188 package = Package(pkg_filepath)189 package_map[package.name] = package190 packages.append(package)191 else:192 # -- SAME PACKAGE: Collect other variant/version.193 package.files.append(pkg_filepath)194 # -- STEP: Make local PYTHON PACKAGE INDEX.195 root_package = Package(None, "Python Package Index")196 root_package.files = [ os.path.join(pkg_rootdir, pkg.name, "index.html")197 for pkg in packages ]198 make_index_for(root_package, pkg_rootdir)199 for package in packages:200 index_dir = os.path.join(pkg_rootdir, package.name)201 make_index_for(package, index_dir)202# -----------------------------------------------------------------------------203# MAIN:204# -----------------------------------------------------------------------------205if __name__ == "__main__":206 if (len(sys.argv) != 2) or "-h" in sys.argv[1:] or "--help" in sys.argv[1:]:207 print("USAGE: %s DOWNLOAD_DIR" % os.path.basename(sys.argv[0]))208 print(__doc__)209 sys.exit(1)...
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!!