MCPcopy Index your code
hub / github.com/SeleniumHQ/selenium / run

Function run

scripts/update_multitool_binaries.py:26–69  ·  view source on GitHub ↗
(lockfile_path)

Source from the content-addressed store, hash-verified

24
25
26def run(lockfile_path):
27 with open(lockfile_path) as f:
28 data = json.load(f)
29
30 for tool in [tool for tool in data if tool != "$schema"]:
31 match = re.search(f"download/(.*?)/{tool}", data[tool]["binaries"][0]["url"])
32 if match:
33 version = match[1]
34 else:
35 continue
36 match = re.search("github.com/(.*?)/releases", data[tool]["binaries"][0]["url"])
37 if match:
38 releases_url = f"https://api.github.com/repos/{match[1]}/releases/latest"
39 else:
40 continue
41 try:
42 with urllib.request.urlopen(releases_url) as response:
43 json_resp = json.loads(response.read())
44 new_version = json_resp["tag_name"]
45 assets = json_resp["assets"]
46 except Exception:
47 continue
48 if new_version != version:
49 print(f"found new version of '{tool}': {new_version}")
50 urls = [asset.get("browser_download_url") for asset in assets]
51 hashes = [asset.get("digest").split(":")[1] for asset in assets]
52 bare_version = version.lstrip("v")
53 bare_new = new_version.lstrip("v")
54 for binary in data[tool]["binaries"]:
55 new_url = binary["url"].replace(version, new_version)
56 new_file = binary["file"].replace(version, new_version)
57 if bare_version != version:
58 new_url = new_url.replace(bare_version, bare_new)
59 new_file = new_file.replace(bare_version, bare_new)
60 new_hash = hashes[urls.index(new_url)]
61 binary["url"] = new_url
62 binary["file"] = new_file
63 binary["sha256"] = new_hash
64
65 with open(lockfile_path, "w") as f:
66 json.dump(data, f, indent=2)
67 f.write("\n")
68
69 print(f"\ngenerated new '{lockfile_path}' with updated urls and hashes")
70
71
72def main():

Callers 1

mainFunction · 0.70

Calls 6

splitMethod · 0.80
readMethod · 0.65
getMethod · 0.65
loadMethod · 0.45
searchMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected