def __init__(self, builds_dir, build="latest", workdir=None, arch=BASEARCH): """ init loads the builds.json which lists the builds, loads the relevant meta-data from JSON and finally, locates the build artifacts. :param builds_dir: name of directory to find the builds :type builds_dir: str :param build: build id or "latest" to parse :type build: str :param workdir: Temporary directory to ensure exists and is clean :type workdir: None or str :raises: BuildError If the build meta-data fails to parse, then a generic exception is raised. If workdir is None then no temporary work directory is created. """ builds = Builds(os.path.dirname(builds_dir)) if build != "latest": if not builds.has(build): raise BuildError("Build was not found in builds.json") else: build = builds.get_latest() log.info("Targeting build: %s", build) self._build_dir = builds.get_build_dir(build, basearch=arch) self._build_json = { "commit": None, "config": None, "image": None, "meta": None } self._found_files = {} self._workdir = workdir self._create_work_dir() # Check to make sure that the build and it's meta-data can be parsed. emsg = "was not read in properly or is not defined" if self.commit is None: raise BuildError("%s %s" % self.__file("commit"), emsg) if self.config is None: raise BuildError("%s %s" % self.__file("config"), emsg) if self.image is None: raise BuildError("%s %s" % self.__file("image"), emsg) if self.meta is None: raise BuildError("%s %s" % self.__file("meta"), emsg) log.info("Proccessed build for: %s (%s-%s) %s", self.summary, self.build_name.upper(), self.basearch, self.build_id)
def __init__(self, workdir=None, build='latest'): builds = Builds(workdir) if build != "latest": if not builds.has(build): raise Exception('Build was not found in builds.json') else: build = builds.get_latest() self._meta_path = os.path.join(builds.get_build_dir(build), 'meta.json') self.read()
def __init__(self, workdir=None, build='latest', schema=SCHEMA_PATH): builds = Builds(workdir) if build != "latest": if not builds.has(build): raise Exception('Build was not found in builds.json') else: build = builds.get_latest() self._build_dir = builds.get_build_dir(build) path = os.path.join(self._build_dir, 'meta.json') super().__init__(schema=schema, path=path)
def __init__(self, workdir=None, build='latest', schema=SCHEMA_PATH): builds = Builds(workdir) if build != "latest": if not builds.has(build): raise Exception('Build was not found in builds.json') else: build = builds.get_latest() # Load the schema self._validator = None if schema and schema.lower() not in ("false", "none"): with open(schema, 'r') as data: self._validator = jsonschema.Draft7Validator( json.loads(data.read())) self._meta_path = os.path.join(builds.get_build_dir(build), 'meta.json') self.read()
def __init__(self, *args, **kwargs): """ init loads the builds.json which lists the builds, loads the relevant meta-data from JSON and finally, locates the build artifacts. :param args: All non-keyword arguments :type args: list :param kwargs: All keyword arguments :type kwargs: dict :raises: BuildError Keyword args: arch: the base architecture, defaults to the current arch. build: the name of the build or latest require_cosa: require the CoreOS Assembler data, such as coreos-assembler-config-git.json and the cosa tarball. require_commit: require the commitmeta.json output. workdir: the work directory, defaults current working dirvY If the build meta-data fails to parse, then a generic exception is raised. If workdir is None then no temporary work directory is created. """ build = kwargs.get("build", "latest") builds = Builds(os.path.dirname(build)) if build != "latest": if not builds.has(build): raise BuildError("Build was not found in builds.json") else: build = builds.get_latest() log.info("Targeting build: %s", build) self._build_dir = builds.get_build_dir(build, basearch=kwargs.get( "arch", BASEARCH)) self._found_files = {} self._workdir = kwargs.pop("workdir", os.getcwd()) tmpdir = os.path.join(self._workdir, "tmp") os.environ['TMPDIR'] = tmpdir # we need to make sure we allocate in tmp/ so we're on the same # filesystem as builds/ and we can just `rename()` it there self._tmpdir = tempfile.mkdtemp(dir=tmpdir) self._image_name = None schema = kwargs.pop("schema", SCHEMA_PATH) # Setup the instance properties. self._build_json = { "commit": None, "config": None, "image": None, "meta": Meta(self.workdir, build, schema=schema) } os.environ['workdir'] = self._workdir # Setup what is required for this Class. # require_cosa means that the COSA information is need # require_commit is usually only needed at build time require_cosa = kwargs.get("require_cosa", False) require_commit = kwargs.get("require_commit", False) self._exceptions = { "commit": CommitMetaRequired if require_commit else None, "image": COSAMetaRequired if require_cosa else None, "config": COSAMetaRequired if require_cosa else None, } # Check the required meta-data by calling the properties. (_, _, _, _) = (self.commit, self.meta, self.config, self.image) log.info("Processed build for: %s (%s-%s) %s", self.summary, self.build_name.upper(), self.basearch, self.build_id)