How to use the koji.ensuredir function in koji

To help you get started, we’ve selected a few koji examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github koji-project / koji / tests / test_hub / test_get_build_logs.py View on Github external
def make_tree(self, data):
        for filepath in data:
            path = "%s/%s" % (self.tempdir, filepath)
            if path.endswith('/'):
                # just make a directory
                dirpath = path
                path = None
            else:
                dirpath = os.path.dirname(path)
            koji.ensuredir(dirpath)
            if path:
                with open(path, 'w') as fo:
                    fo.write('TEST LOG FILE CONTENTS\n')
github koji-project / koji / plugins / builder / runroot.py View on Github external
opts = []
            else:
                opts = opts.split(',')
            if 'bind' in opts:
                #make sure dir exists
                if not os.path.isdir(dev):
                    error = koji.GenericError("No such directory or mount: %s" % dev)
                    break
                type = 'none'
            if 'bg' in opts:
                error = koji.GenericError("bad config: background mount not allowed")
                break
            opts = ','.join(opts)
            cmd = ['mount', '-t', type, '-o', opts, dev, mpoint]
            self.logger.info("Mount command: %r" % cmd)
            koji.ensuredir(mpoint)
            if compat_mode:
                status = log_output(cmd[0], cmd, logfile, uploadpath, logerror=True, append=True)
            else:
                status = log_output(self.session, cmd[0], cmd, logfile, uploadpath, logerror=True, append=True)
            if not _isSuccess(status):
                error = koji.GenericError("Unable to mount %s: %s" \
                        % (mpoint, _parseStatus(status, cmd)))
                break
            fslog.write("%s\n" % mpoint)
            fslog.flush()
        fslog.close()
        if error is not None:
            self.undo_mounts(rootdir, fatal=False)
            raise error
github koji-project / koji / plugins / builder / runroot.py View on Github external
opts = []
                else:
                    opts = opts.split(',')
                if 'bind' in opts:
                    #make sure dir exists
                    if not os.path.isdir(dev):
                        error = koji.GenericError("No such directory or mount: %s" % dev)
                        break
                    type = 'none'
                if 'bg' in opts:
                    error = koji.GenericError("bad config: background mount not allowed")
                    break
                opts = ','.join(opts)
                cmd = ['mount', '-t', type, '-o', opts, dev, mpoint]
                self.logger.info("Mount command: %r" % cmd)
                koji.ensuredir(mpoint)
                status = log_output(self.session, cmd[0], cmd, logfile, uploadpath, logerror=True, append=True)
                if not isSuccess(status):
                    error = koji.GenericError("Unable to mount %s: %s" \
                            % (mpoint, parseStatus(status, cmd)))
                    break
                fslog.write("%s\n" % mpoint)
                fslog.flush()
        if error is not None:
            self.undo_mounts(rootdir, fatal=False)
            raise error
github koji-project / koji / plugins / hub / rpm2maven.py View on Github external
if not config:
        config = ConfigParser.SafeConfigParser()
        config.read(CONFIG_FILE)
    name_patterns = config.get('patterns', 'rpm_names').split()
    for pattern in name_patterns:
        if fnmatch.fnmatch(rpminfo['name'], pattern):
            break
    else:
        return

    tmpdir = os.path.join(koji.pathinfo.work(), 'rpm2maven', koji.buildLabel(buildinfo))
    try:
        if os.path.exists(tmpdir):
            rmtree(tmpdir)
        koji.ensuredir(tmpdir)
        expand_rpm(filepath, tmpdir)
        scan_and_import(buildinfo, rpminfo, tmpdir)
    finally:
        if os.path.exists(tmpdir):
            rmtree(tmpdir)
github containerbuildsystem / koji-containerbuild / koji_containerbuild / plugins / builder_containerbuild.py View on Github external
def fetchDockerfile(self, src, build_tag):
        """
        Gets Dockerfile. Roughly corresponds to getSRPM method of build task
        """
        scm = SCM(src)
        scm.assert_allowed(self.options.allowed_scms)
        scmdir = os.path.join(self.workdir, 'sources')

        koji.ensuredir(scmdir)

        logfile = os.path.join(self.workdir, 'checkout-for-labels.log')
        uploadpath = self.getUploadDir()

        koji.ensuredir(uploadpath)

        self.run_callbacks('preSCMCheckout', scminfo=scm.get_info(), build_tag=build_tag,
                           scratch=self.opts.get('scratch', False))

        # Check out sources from the SCM
        sourcedir = scm.checkout(scmdir, self.session, uploadpath, logfile)

        self.run_callbacks("postSCMCheckout", scminfo=scm.get_info(), build_tag=build_tag,
                           scratch=self.opts.get('scratch', False), srcdir=sourcedir)

        fn = os.path.join(sourcedir, 'Dockerfile')
        if not os.path.exists(fn):
            raise koji.BuildError("Dockerfile file missing: %s" % fn)
        return fn
github containerbuildsystem / koji-containerbuild / koji_containerbuild / plugins / builder_containerbuild.py View on Github external
def fetchDockerfile(self, src, build_tag):
        """
        Gets Dockerfile. Roughly corresponds to getSRPM method of build task
        """
        scm = SCM(src)
        scm.assert_allowed(self.options.allowed_scms)
        scmdir = os.path.join(self.workdir, 'sources')

        koji.ensuredir(scmdir)

        logfile = os.path.join(self.workdir, 'checkout-for-labels.log')
        uploadpath = self.getUploadDir()

        koji.ensuredir(uploadpath)

        self.run_callbacks('preSCMCheckout', scminfo=scm.get_info(), build_tag=build_tag,
                           scratch=self.opts.get('scratch', False))

        # Check out sources from the SCM
        sourcedir = scm.checkout(scmdir, self.session, uploadpath, logfile)

        self.run_callbacks("postSCMCheckout", scminfo=scm.get_info(), build_tag=build_tag,
                           scratch=self.opts.get('scratch', False), srcdir=sourcedir)

        fn = os.path.join(sourcedir, 'Dockerfile')
github henrysher / fedora-infra-ansible / roles / koji_builder / files / runroot.py View on Github external
if 'bind' in opts:
                #make sure dir exists
                if not os.path.isdir(dev):
                    error = koji.GenericError("No such directory or mount: %s" % dev)
                    break
                type = 'none'
                if path is None:
                    #shorthand for "same path"
                    path = dev
            if 'bg' in opts:
                error = koji.GenericError("bad config: background mount not allowed")
                break
            opts = ','.join(opts)
            cmd = ['mount', '-t', type, '-o', opts, dev, mpoint]
            self.logger.info("Mount command: %r" % cmd)
            koji.ensuredir(mpoint)
            if compat_mode:
                status = log_output(cmd[0], cmd, logfile, uploadpath, logerror=True, append=True)
            else:
                status = log_output(self.session, cmd[0], cmd, logfile, uploadpath, logerror=True, append=True)
            if not _isSuccess(status):
                error = koji.GenericError("Unable to mount %s: %s" \
                        % (mpoint, _parseStatus(status, cmd)))
                break
            fslog.write("%s\n" % mpoint)
            fslog.flush()
        fslog.close()
        if error is not None:
            self.undo_mounts(rootdir, fatal=False)
            raise error
github containerbuildsystem / koji-containerbuild / koji_containerbuild / plugins / builder_containerbuild.py View on Github external
create_method, orchestrator_create_build_args)
            build_response = create_method(**orchestrator_create_build_args)
        except (AttributeError, OsbsOrchestratorNotEnabled):
            # Older osbs-client, or else orchestration not enabled
            create_build_args['architecture'] = arch = arches[0]
            create_build_args.pop('skip_build', None)
            create_method = self.osbs().create_build
            self.logger.debug("Starting %s with params: '%s'",
                              create_method, create_build_args)
            build_response = create_method(**create_build_args)

        if build_response is None:
            self.logger.debug("Build was skipped")

            osbs_logs_dir = self.resultdir()
            koji.ensuredir(osbs_logs_dir)
            try:
                self._incremental_upload_logs()
            except koji.ActionNotAllowed:
                pass

            return

        return self.handle_build_response(build_response, arch=arch)