This repository was archived by the owner on Aug 7, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathunbundle.py
More file actions
executable file
·82 lines (71 loc) · 2.71 KB
/
unbundle.py
File metadata and controls
executable file
·82 lines (71 loc) · 2.71 KB
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
78
79
80
81
82
import argparse
import os
import sys
def resolve_includes(bundle_name, bundle_path,
content, bundles=False, seen=None, search=''):
"""
resolve_incudes returns a full package list of include-resolved packages in
the bundle definition file or pundle declaration under bundle_path. Sources
for included bundles are other bundle definition files at
bundle_path/bundles/* and bundle_path/packages.
"""
if not seen:
seen = set()
if bundle_name in seen:
return True
seen.add(bundle_name)
bundle_def = os.path.join(bundle_path, "bundles", bundle_name)
try:
with open(bundle_def, "r", encoding="latin-1") as bundlef:
lines = bundlef.readlines()
except FileNotFoundError:
print(f"ERROR: could not find {bundle_name} bundle")
return False
if bundles:
content.add(bundle_name)
for line in lines:
line = line.split("#", 1)[0].strip()
if not line:
continue
if line.startswith("also-add("):
continue
if line.startswith("include("):
inc_bundle = line[line.find("(")+1:line.find(")")]
success = resolve_includes(inc_bundle, bundle_path,
content, bundles, seen, search)
if not success:
return False
if search == inc_bundle:
print(f"{bundle_name} includes {search}")
if bundles:
content.add(inc_bundle)
continue
if not bundles:
content.add(line)
return True
def main():
parser = argparse.ArgumentParser(description='Process bundle packages following includes')
parser.add_argument('bundle_name', help='name of bundle to process')
parser.add_argument('bundle_path', help='path to clr-bundles directory')
parser.add_argument('--bundles', default=False, action='store_true',
help='Report only included bundle names')
parser.add_argument('--search', default='',
help='Display bundles processed that include this bundle')
args = parser.parse_args()
success = True
content = set()
if args.bundles:
os_core_set = set(["os-core"])
else:
os_core_set = set()
success = resolve_includes("os-core", args.bundle_path, os_core_set, search=args.search)
if not success:
sys.exit(1)
success = resolve_includes(args.bundle_name, args.bundle_path, content,
bundles=args.bundles, search=args.search)
if not success:
sys.exit(1)
if not args.search:
print('\n'.join(sorted(os_core_set.union(content))))
if __name__ == "__main__":
main()