forked from opencomputeproject/OpenNetworkLinux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathonlplatform.py
executable file
·85 lines (68 loc) · 2.63 KB
/
onlplatform.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
78
79
80
81
82
83
84
85
#!/usr/bin/python
"""onlplatform.py
Extract install file requirements from the platform YAML file and/or
the platform package metadata.
"""
import sys, os
import itertools
import argparse
toolsdir = os.path.dirname(os.path.abspath(__file__))
sys.path.append(toolsdir)
onldir = os.path.dirname(toolsdir)
onlpydir = os.path.join(onldir, "packages/base/all/vendor-config-onl/src/python")
sys.path.append(onlpydir)
import onl.YamlUtils
from onlpm import *
# glob import is required here so pickle load load properly
pm = defaultPm()
ap = argparse.ArgumentParser("ONL Platform Data Extractor.")
ap.add_argument("platform", help="Platform name")
ap.add_argument("arch", help="Architecture")
ap.add_argument("key", help="Lookup key.")
ops = ap.parse_args()
def extractKey(platform, arch, key):
pkg = "onl-platform-config-%s:%s" % (platform, arch,)
basename = "%s.yml" % platform
pm.require(pkg, force=False, build_missing=False)
platformConfigPath = pm.opr.get_file(pkg, basename)
if arch in ('amd64',):
pkg = "onl-vendor-config-onl:all"
basename = "platform-config-defaults-x86-64.yml"
subkey = 'grub'
else:
pkg = "onl-vendor-config-onl:all"
basename = "platform-config-defaults-uboot.yml"
subkey = 'flat_image_tree'
pm.require(pkg, force=False, build_missing=False)
defaultConfigPath = pm.opr.get_file(pkg, basename)
platformConf = onl.YamlUtils.merge(defaultConfigPath, platformConfigPath)
resource = platformConf[platform][subkey][key]
if type(resource) == dict:
pkg = resource['package']
basename = resource['=']
else:
pkg, sep, basename = resource.partition(',')
if not sep:
raise ValueError("resource missing package declaration: %s" % resource)
pkg = pkg.strip()
basename = basename.strip()
pm.require(pkg, force=False, build_missing=False)
resourcePath = pm.opr.get_file(pkg, basename)
return resourcePath
def extractVendor(platform, arch):
pkg = "onl-platform-config-%s:%s" % (platform, arch,)
l = pm.opr.lookup_all(pkg)
if not l:
raise SystemExit("cannot find package %s:%s"
% (platform, arch,))
l = [x for x in pm.package_groups if pkg in x]
l = list(itertools.chain(*[x.prerequisite_packages() for x in l]))
l = [x for x in l if x.startswith('onl-vendor-config-')]
return "\n".join(l)
if ops.key in ('kernel', 'initrd', 'dtb', 'itb',):
print extractKey(ops.platform, ops.arch, ops.key)
sys.exit(0)
if ops.key == 'vendor':
print extractVendor(ops.platform, ops.arch)
sys.exit(0)
raise SystemExit("invalid key %s" % ops.key)