def load(self, pkg):
        if not os.path.exists(pkg):
            raise OnlPackageError("Package file '%s' does not exist." % pkg)

        pkg_data = onlyaml.loadf(pkg, OnlPackage.DEFAULTS)

        pkglist = []

        # Package declarations are dicts.
        if type(pkg_data) is not dict:
            raise OnlPackageError("The package file '%s' is empty or malformed." % pkg)

        if "packages" not in pkg_data:
            raise OnlPackageError("The package file '%s' does not contain a packages declaration." % pkg)

        if type(pkg_data["packages"]) is not list:
            raise OnlPackageError("The packages declaration is not a list.")

        self.packages = []
        for p in pkg_data["packages"]:
            self.packages.append(OnlPackage(p, os.path.dirname(pkg), pkg_data.get("common", None), None))

        # This is used for the pkg_info dump
        self._pkg_info = pkg_data.copy()
        self._pkgs = pkg_data
        self._pkgs["__source"] = os.path.abspath(pkg)
        self._pkgs["__directory"] = os.path.dirname(self._pkgs["__source"])
        self._pkgs["__mtime"] = os.path.getmtime(pkg)
Example #2
 def __load(self, config):
     if not os.path.exists(config):
         raise OnlRfsError("Configuration file '%s' does not exist." % config)
     self.config = onlyaml.loadf(config, self.kwargs)
# of platforms.
import onlyaml
import argparse
import onlu
import os

ap = argparse.ArgumentParser(description='ONL Platform Package Lister')
ap.add_argument('platforms', metavar='PLATFORM-LIST|YAML-FILE', help='YAML file containing the list of platforms.')
ap.add_argument("--no-builtins", action='store_true', help='Skip builtin ONL packages.')
ap.add_argument("--add-patterns", help="Additional package patterns.", nargs='+', default=[])

ops = ap.parse_args()

if os.path.exists(ops.platforms):
    platforms = onlyaml.loadf(ops.platforms)
    platforms = ops.platforms.split(',')

# The following ONL packages are needed for each platform:
# The platform-config package
# The ONLP package
ONL_PATTERNS = [ "onlp-%(platform)s", "onl-platform-config-%(platform)s" ]

PATTERNS = list(onlu.sflatten(ops.add_patterns))

if not ops.no_builtins: