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

Function run

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

Source from the content-addressed store, hash-verified

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

Callers 2

binary_pathsMethod · 0.85
mainFunction · 0.85

Calls 7

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

Tested by

no test coverage detected