Skip to content

Commit ddfead4

Browse files
SirRGBcornaimjyotiradityatieu1991
committed
1 parent d38f02c commit ddfead4

File tree

3 files changed

+115
-24
lines changed

3 files changed

+115
-24
lines changed

TODO.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
## ToDo
2-
- multi-line remotes/repos in local manifests do not work for more than one manifest
32
- automatic repo pulling for officially supported lineage devices
4-
- move xml handling to python

py-utils/xml_manifest_gen.py

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#!/usr/bin/python3
2+
3+
from xml.etree import ElementTree
4+
import sys
5+
from urllib.request import urlopen, Request
6+
7+
8+
def is_in_manifest(manifest: str, project_path: str = "", project_remote: str = "") -> bool:
9+
for manifest_project in manifest.findall("project"):
10+
if project_path == manifest_project.get("path"):
11+
return True
12+
13+
for manifest_project in manifest.findall("remote"):
14+
if project_remote == manifest_project.get("name"):
15+
return True
16+
17+
return False
18+
19+
20+
def add_project_to_manifest(manifest: str, project_name: str, project_path: str, project_remote: str = "",
21+
project_revision: str = "") -> str:
22+
if is_in_manifest(manifest=manifest, project_path=project_path):
23+
return manifest
24+
25+
element = ElementTree.Element(
26+
"project",
27+
attrib={
28+
"name": project_name,
29+
"path": project_path,
30+
},
31+
)
32+
33+
if project_remote:
34+
element.attrib["remote"] = project_remote
35+
36+
if project_revision:
37+
element.attrib["revision"] = project_revision
38+
39+
manifest.append(element)
40+
return manifest
41+
42+
43+
def add_remote_to_manifest(manifest: str, remote_name: str, remote_fetch: str, remote_revision: str = "") -> str:
44+
if is_in_manifest(manifest=manifest, project_remote=remote_name):
45+
return manifest
46+
47+
element = ElementTree.Element(
48+
"remote",
49+
attrib={
50+
"name": remote_name,
51+
"fetch": remote_fetch,
52+
},
53+
)
54+
55+
if remote_revision:
56+
element.attrib["revision"] = remote_revision
57+
58+
manifest.append(element)
59+
return manifest
60+
61+
def generate_manifest(local_manifest: str, remote_manifest: str) -> str:
62+
for projects in remote_manifest.findall("remote"):
63+
if projects.get("revision") == "":
64+
revision = ""
65+
else:
66+
revision = projects.get("revision")
67+
68+
local_manifest = add_remote_to_manifest(
69+
manifest=local_manifest,
70+
remote_name=projects.get("name"),
71+
remote_fetch=projects.get("fetch"),
72+
remote_revision=revision
73+
)
74+
75+
for projects in remote_manifest.findall("project"):
76+
if projects.get("remote") == "":
77+
remote = ""
78+
else:
79+
remote = projects.get("remote")
80+
81+
if projects.get("revision") == "":
82+
revision = ""
83+
else:
84+
revision = projects.get("revision")
85+
86+
local_manifest = add_project_to_manifest(
87+
manifest=local_manifest,
88+
project_name=projects.get("name"),
89+
project_path=projects.get("path"),
90+
project_remote=remote,
91+
project_revision=revision
92+
)
93+
94+
ElementTree.indent(local_manifest)
95+
return local_manifest
96+
97+
def main() -> None:
98+
local_manifest = ElementTree.Element("manifest")
99+
100+
for urls in sys.argv[1].split(","):
101+
request = Request(urls, headers={"User-Agent": "Mozilla/5.0"})
102+
source_manifest = urlopen(request).read()
103+
remote_manifest = ElementTree.fromstring(source_manifest)
104+
105+
local_manifest = generate_manifest(local_manifest, remote_manifest)
106+
107+
print('<?xml version="1.0" encoding="UTF-8"?>')
108+
print(ElementTree.tostring(local_manifest).decode())
109+
110+
111+
112+
if __name__ == '__main__':
113+
main()

scripts/sync.sh

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,8 @@ _sync() {
1616
cd "${ROM_DIR}" || exit
1717
# Remove local manifests
1818
find "${ROM_DIR}"/.repo/local_manifests/ -type f -exec rm {} \;
19-
if [[ -n "${LOCAL_MANIFEST}" ]]; then
20-
if grep -q ',' <<< "${LOCAL_MANIFEST}"; then
21-
_merge_local_manifests
22-
else
23-
curl_cmd "${LOCAL_MANIFEST}" --output "${ROM_DIR}"/.repo/local_manifests/manifest.xml
24-
fi
25-
fi
19+
# Merge local manifests into one to avoid conflicts with duplicate dependencies
20+
xml_manifest_gen.py "${LOCAL_MANIFEST}" > "${ROM_DIR}"/.repo/local_manifests/manifest.xml
2621
local threads
2722
threads=$(nproc)
2823
repo forall -c "rm .git/*.lock" || true
@@ -34,21 +29,6 @@ _sync() {
3429
unset ROM_MANIFEST LOCAL_MANIFEST CLONE_REPOS
3530
}
3631

37-
# Merge local manifests into one
38-
# to avoid conflicts with duplicate dependencies
39-
_merge_local_manifests() {
40-
echo -e '<?xml version="1.0" encoding="UTF-8"?>\n<manifest>' > "${ROM_DIR}"/.repo/local_manifests/manifest.xml
41-
IFS=',' read -r -a "LOCAL_MANIFEST" <<< "${LOCAL_MANIFEST}"
42-
for url in "${LOCAL_MANIFEST[@]}"; do
43-
# Remove heading and end
44-
curl_cmd "${url}" | sed '/<?xml version="1.0" encoding="UTF-8"?>/d; /<manifest>/d; /<\/manifest>/d; /<!--/d; /-->/d; /^$/d' >> "${ROM_DIR}"/.repo/local_manifests/.merge.txt
45-
done
46-
# Remove duplicated entries
47-
sort < "${ROM_DIR}"/.repo/local_manifests/.merge.txt | uniq >> "${ROM_DIR}"/.repo/local_manifests/manifest.xml
48-
find "${ROM_DIR}"/.repo/local_manifests/ -type f ! -name "*.xml" -exec rm -r {} \; || true
49-
echo '</manifest>' >> "${ROM_DIR}"/.repo/local_manifests/manifest.xml
50-
}
51-
5232
# Clone a repo
5333
_clone() {
5434
full_repo_name="${1}"

0 commit comments

Comments
 (0)