MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / run

Function run

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

Source from the content-addressed store, hash-verified

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

Callers 2

binary_pathsMethod · 0.85
mainFunction · 0.85

Calls 6

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

Tested by

no test coverage detected