|
| 1 | +#!/usr/bin/python3 |
| 2 | + |
| 3 | +import xml |
| 4 | +import xml_manifest_gen |
| 5 | +from xml.etree import ElementTree |
| 6 | +import sys |
| 7 | +from urllib.request import urlopen, Request |
| 8 | + |
| 9 | + |
| 10 | +def fetch_device_vendor(local_manifest, remote_manifest, device: str) -> xml: |
| 11 | + for projects in remote_manifest.findall("project"): |
| 12 | + if projects.get("groups").__contains__(device): |
| 13 | + if projects.get("remote") == "": |
| 14 | + remote = "" |
| 15 | + else: |
| 16 | + remote = projects.get("remote") |
| 17 | + |
| 18 | + if projects.get("revision") == "": |
| 19 | + revision = "" |
| 20 | + else: |
| 21 | + revision = projects.get("revision") |
| 22 | + |
| 23 | + local_manifest = xml_manifest_gen.add_project_to_manifest( |
| 24 | + manifest=local_manifest, |
| 25 | + project_name=projects.get("name"), |
| 26 | + project_path=projects.get("path"), |
| 27 | + project_remote=remote, |
| 28 | + project_revision=revision |
| 29 | + ) |
| 30 | + |
| 31 | + ElementTree.indent(local_manifest) |
| 32 | + return local_manifest |
| 33 | + |
| 34 | + |
| 35 | +def main() -> None: |
| 36 | + devices = f"muppets_{sys.argv[1]}".split(",") |
| 37 | + branch = sys.argv[2] |
| 38 | + |
| 39 | + url = f"https://github.com/TheMuppets/manifests/raw/refs/heads/{branch}/muppets.xml" |
| 40 | + request = Request(url, headers={"User-Agent": "Mozilla/5.0"}) |
| 41 | + source_manifest = urlopen(request).read() |
| 42 | + remote_manifest = ElementTree.fromstring(source_manifest) |
| 43 | + |
| 44 | + local_manifest = ElementTree.Element("manifest") |
| 45 | + for device in devices: |
| 46 | + local_manifest = fetch_device_vendor(local_manifest, remote_manifest, device) |
| 47 | + |
| 48 | + print('<?xml version="1.0" encoding="UTF-8"?>') |
| 49 | + print(ElementTree.tostring(local_manifest).decode()) |
| 50 | + |
| 51 | + |
| 52 | +if __name__ == '__main__': |
| 53 | + main() |
0 commit comments