mirror of
https://github.com/Telecominfraproject/OpenNetworkLinux.git
synced 2025-12-27 02:04:43 +00:00
Helper script to pull out kernel/initrd/vendor
This commit is contained in:
82
tools/onlplatform.py
Normal file
82
tools/onlplatform.py
Normal file
@@ -0,0 +1,82 @@
|
||||
#!/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
|
||||
|
||||
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()
|
||||
|
||||
platform = sys.argv[1]
|
||||
arch = sys.argv[2]
|
||||
key = sys.argv[3]
|
||||
|
||||
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 key in ('kernel', 'initrd',):
|
||||
print extractKey(platform, arch, key)
|
||||
sys.exit(0)
|
||||
|
||||
if key == 'vendor':
|
||||
print extractVendor(platform, arch)
|
||||
sys.exit(0)
|
||||
|
||||
raise SystemExit("invalid key %s" % key)
|
||||
Reference in New Issue
Block a user