-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathlineage-minimal-regen.py
executable file
·77 lines (60 loc) · 2.05 KB
/
lineage-minimal-regen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env python3
import os
import re
import sys
import xml.etree.ElementTree as ET
try:
import git
except ImportError:
sys.exit("Please install the GitPython package via pip3")
# Clone (or update) the repository
if os.path.isdir("lineage_manifest"):
print("Updating lineage_manifest repository...")
lineage_manifest = git.Repo("lineage_manifest")
lineage_manifest.remote("origin").fetch()
else:
print("Downloading lineage_manifest repository...")
lineage_manifest = git.Repo.clone_from(
"https://github.com/LineageOS/android", "lineage_manifest"
)
# Get all the refs
refs = [
re.search(r"remotes/(\S+)", tag).group(1)
for tag in lineage_manifest.git.branch(a=True).splitlines()
if "remotes/" in tag
]
repos = set()
# Look for repo names in each ref
for index, ref in enumerate(refs, 1):
print("[{}/{}] Parsing `{}`...".format(index, len(refs), ref))
xml_todo = ["default.xml"]
# Load the XML
while len(xml_todo) != 0:
xml_name = xml_todo.pop(0)
print(" - {}".format(xml_name))
xml = ET.fromstring(lineage_manifest.git.show("{}:{}".format(ref, xml_name)))
for child in xml:
if child.tag == "include":
xml_todo.append(child.attrib["name"])
continue
# Skip all non-project tags
if child.tag != "project":
continue
# Ignore non-Lineage projects
if not child.attrib["name"].startswith("LineageOS/"):
continue
repos.add(child.attrib["name"].rstrip("/"))
file = open("lineage-minimal.xml", "w")
file.write('<?xml version="1.0" encoding="UTF-8"?>\n')
file.write("<manifest>\n")
file.write("\n")
file.write(' <remote name="github"\n')
file.write(' fetch=".." />\n')
file.write(' <default revision="main"\n')
file.write(' remote="github"\n')
file.write(' sync-j="4" />\n')
file.write("\n")
for repo in sorted(repos):
file.write(' <project name="' + repo + '" />\n')
file.write("</manifest>\n")
file.close()