Пример #1
0
def doInstallerReindex():
    sh.cd('%s/installer/redhat/' % (BASE_DIR))
    sh.createrepo('.')
    sh.cd('%s/installer/ubuntu' % (BASE_DIR))
    run = sh.Command('./update-archive.sh')
    run('.')
    return True
Пример #2
0
def build_repodata():
    #repodir = '/var/cache/gravity/repos/rpm'
    repodir = os.path.join(VARDIR, 'repos', 'rpm')
    repodata_dir = os.path.join(repodir, 'repodata')
    if os.path.exists(repodata_dir):
        shutil.rmtree(repodata_dir)
    logger.info('creating repo')
    createrepo('.', _cwd=repodir)
Пример #3
0
def doReindex():
    options = setup()
    ecoList = options.dest.split(',')

    for eco in ecoList:
        destEco = eco[0]
        destOS = eco[1:]

        for os in destOS:
            # Recreate the index for the repository
            if os is 'r':
                print 'Recreating index for Redhat: %s' % REINDEX_CMD_LIST['r']
                sh.cd('%s/redhat' % ECO_DIR_DICT[destEco])
                sh.createrepo('.', _out=logfile)
            elif os is 'u':
                print 'Recreating index for Ubuntu: %s' % REINDEX_CMD_LIST['u']
                sh.cd('%s/ubuntu' % ECO_DIR_DICT[destEco])
                sh.pwd(_out=logfile)
                run = sh.Command('./update-archive.sh')
                run(_out=logfile, _tty_out=logfile)
            else:
                print 'This is an invalid OS'
Пример #4
0
def build(cp, package_info, commit, env_vars, dev_mode, use_public):

    # Set the build timestamp to now
    commit.dt_build = int(time())

    datadir = os.path.realpath(cp.get("DEFAULT", "datadir"))
    scriptsdir = os.path.realpath(cp.get("DEFAULT", "scriptsdir"))
    target = cp.get("DEFAULT", "target")
    yumrepodir = os.path.join("repos", commit.getshardedcommitdir())
    yumrepodir_abs = os.path.join(datadir, yumrepodir)

    commit_hash = commit.commit_hash
    project_name = commit.project_name
    repo_dir = commit.repo_dir

    # If yum repo already exists remove it and assume we're starting fresh
    if os.path.exists(yumrepodir_abs):
        shutil.rmtree(yumrepodir_abs)
    os.makedirs(yumrepodir_abs)

    sh.git("--git-dir", "%s/.git" % repo_dir,
           "--work-tree=%s" % repo_dir, "reset", "--hard", commit_hash)

    docker_run_cmd = []
    # expand the env name=value pairs into docker arguments
    if env_vars:
        for env_var in env_vars:
            docker_run_cmd.append('--env')
            docker_run_cmd.append(env_var)
    if (dev_mode or use_public):
            docker_run_cmd.append('--env')
            docker_run_cmd.append("DELOREAN_DEV=1")

    docker_run_cmd.extend(["-t", "--volume=%s:/data" % datadir,
                           "--volume=%s:/scripts" % scriptsdir,
                           "--name", "builder-%s" % target,
                           "delorean/%s" % target,
                           "/scripts/build_rpm_wrapper.sh", project_name,
                           "/data/%s" % yumrepodir, str(os.getuid()),
                           str(os.getgid())])
    try:
        sh.docker("run", docker_run_cmd)
    except Exception as e:
        logger.error('Docker cmd failed. See logs at: %s/%s/' % (datadir,
                                                                 yumrepodir))
        raise e
    finally:
        # Kill builder-"target" if running and remove if present
        try:
            sh.docker("kill", "builder-%s" % target)
            sh.docker("wait", "builder-%s" % target)
        except Exception:
            pass
        try:
            sh.docker("rm", "builder-%s" % target)
        except Exception:
            pass

    built_rpms = []
    for rpm in os.listdir(yumrepodir_abs):
        if rpm.endswith(".rpm"):
            built_rpms.append(os.path.join(yumrepodir, rpm))
    if not built_rpms:
        raise Exception("No rpms built for %s" % project_name)

    notes = "OK"
    if not os.path.isfile(os.path.join(yumrepodir_abs, "installed")):
        logger.error('Build failed. See logs at: %s/%s/' % (datadir,
                                                            yumrepodir))
        raise Exception("Error installing %s" % project_name)

    packages = [package["name"] for package in package_info["packages"]]
    for otherproject in packages:
        if otherproject == project_name:
            continue
        last_success = session.query(Commit).\
            filter(Commit.project_name == otherproject).\
            filter(Commit.status == "SUCCESS").\
            order_by(desc(Commit.id)).first()
        if not last_success:
            continue
        rpms = last_success.rpms.split(",")
        for rpm in rpms:
            rpm_link_src = os.path.join(yumrepodir_abs, os.path.split(rpm)[1])
            os.symlink(os.path.relpath(os.path.join(datadir, rpm),
                       yumrepodir_abs), rpm_link_src)

    sh.createrepo(yumrepodir_abs)

    fp = open(os.path.join(yumrepodir_abs,
                           "%s.repo" % cp.get("DEFAULT", "reponame")), "w")
    fp.write("[%s]\nname=%s-%s-%s\nbaseurl=%s/%s\nenabled=1\n"
             "gpgcheck=0\npriority=1" % (cp.get("DEFAULT", "reponame"),
                                         cp.get("DEFAULT", "reponame"),
                                         project_name, commit_hash,
                                         cp.get("DEFAULT", "baseurl"),
                                         commit.getshardedcommitdir()))
    fp.close()

    current_repo_dir = os.path.join(datadir, "repos", "current")
    os.symlink(os.path.relpath(yumrepodir_abs, os.path.join(datadir, "repos")),
               current_repo_dir + "_")
    os.rename(current_repo_dir + "_", current_repo_dir)
    return built_rpms, notes
Пример #5
0
def build(cp, package_info, commit, env_vars, dev_mode, use_public):

    # Set the build timestamp to now
    commit.dt_build = int(time())

    datadir = os.path.realpath(cp.get("DEFAULT", "datadir"))
    scriptsdir = os.path.realpath(cp.get("DEFAULT", "scriptsdir"))
    target = cp.get("DEFAULT", "target")
    yumrepodir = os.path.join("repos", commit.getshardedcommitdir())
    yumrepodir_abs = os.path.join(datadir, yumrepodir)

    commit_hash = commit.commit_hash
    project_name = commit.project_name
    repo_dir = commit.repo_dir

    # If yum repo already exists remove it and assume we're starting fresh
    if os.path.exists(yumrepodir_abs):
        shutil.rmtree(yumrepodir_abs)
    os.makedirs(yumrepodir_abs)

    sh.git("--git-dir", "%s/.git" % repo_dir, "--work-tree=%s" % repo_dir,
           "reset", "--hard", commit_hash)

    docker_run_cmd = []
    # expand the env name=value pairs into docker arguments
    if env_vars:
        for env_var in env_vars:
            docker_run_cmd.append('--env')
            docker_run_cmd.append(env_var)
    if (dev_mode or use_public):
        docker_run_cmd.append('--env')
        docker_run_cmd.append("DELOREAN_DEV=1")

    docker_run_cmd.extend([
        "-t",
        "--volume=%s:/data" % datadir,
        "--volume=%s:/scripts" % scriptsdir, "--name",
        "builder-%s" % target,
        "delorean/%s" % target, "/scripts/build_rpm_wrapper.sh", project_name,
        "/data/%s" % yumrepodir,
        str(os.getuid()),
        str(os.getgid())
    ])
    try:
        sh.docker("run", docker_run_cmd)
    except Exception as e:
        logger.error('Docker cmd failed. See logs at: %s/%s/' %
                     (datadir, yumrepodir))
        raise e
    finally:
        # Kill builder-"target" if running and remove if present
        try:
            sh.docker("kill", "builder-%s" % target)
            sh.docker("wait", "builder-%s" % target)
        except Exception:
            pass
        try:
            sh.docker("rm", "builder-%s" % target)
        except Exception:
            pass

    built_rpms = []
    for rpm in os.listdir(yumrepodir_abs):
        if rpm.endswith(".rpm"):
            built_rpms.append(os.path.join(yumrepodir, rpm))
    if not built_rpms:
        raise Exception("No rpms built for %s" % project_name)

    notes = "OK"
    if not os.path.isfile(os.path.join(yumrepodir_abs, "installed")):
        logger.error('Build failed. See logs at: %s/%s/' %
                     (datadir, yumrepodir))
        raise Exception("Error installing %s" % project_name)

    packages = [package["name"] for package in package_info["packages"]]
    for otherproject in packages:
        if otherproject == project_name:
            continue
        last_success = session.query(Commit).\
            filter(Commit.project_name == otherproject).\
            filter(Commit.status == "SUCCESS").\
            order_by(desc(Commit.id)).first()
        if not last_success:
            continue
        rpms = last_success.rpms.split(",")
        for rpm in rpms:
            rpm_link_src = os.path.join(yumrepodir_abs, os.path.split(rpm)[1])
            os.symlink(
                os.path.relpath(os.path.join(datadir, rpm), yumrepodir_abs),
                rpm_link_src)

    sh.createrepo(yumrepodir_abs)

    fp = open(
        os.path.join(yumrepodir_abs,
                     "%s.repo" % cp.get("DEFAULT", "reponame")), "w")
    fp.write("[%s]\nname=%s-%s-%s\nbaseurl=%s/%s\nenabled=1\n"
             "gpgcheck=0\npriority=1" %
             (cp.get("DEFAULT", "reponame"), cp.get(
                 "DEFAULT", "reponame"), project_name, commit_hash,
              cp.get("DEFAULT", "baseurl"), commit.getshardedcommitdir()))
    fp.close()

    current_repo_dir = os.path.join(datadir, "repos", "current")
    os.symlink(os.path.relpath(yumrepodir_abs, os.path.join(datadir, "repos")),
               current_repo_dir + "_")
    os.rename(current_repo_dir + "_", current_repo_dir)
    return built_rpms, notes
Пример #6
0
def build(cp, dt, project, spec_subdir, commit):
    datadir = os.path.realpath(cp.get("DEFAULT", "datadir"))
    # TODO : only working by convention need to improve
    scriptsdir = datadir.replace("data", "scripts")
    yumrepodir = os.path.join("repos", commit[:2], commit[2:4], commit)
    yumrepodir_abs = os.path.join(datadir, yumrepodir)

    # If yum repo already exists remove it and assume we're starting fresh
    if os.path.exists(yumrepodir_abs):
        shutil.rmtree(yumrepodir_abs)
    os.makedirs(yumrepodir_abs)

    # We need to make sure if any patches exist in the master-patches branch
    # they they can still be applied to upstream master, if they can we stop
    testpatches(project, commit, datadir)

    sh.git("--git-dir", "data/%s/.git" % project,
           "--work-tree=data/%s" % project, "reset", "--hard", commit)
    try:
        sh.docker("kill", "builder")
    except:
        pass

    # looks like we need to give the container time to die
    time.sleep(20)
    try:
        sh.docker("rm", "builder")
    except:
        pass

    try:
        sh.docker("run", "-t", "--volume=%s:/data" % datadir,
                  "--volume=%s:/scripts" % scriptsdir, "--name", "builder",
                  "delorean/fedora", "/scripts/build_rpm_wrapper.sh", project,
                  spec_subdir, "/data/%s" % yumrepodir)
    except:
        raise Exception("Error while building packages")

    built_rpms = []
    for rpm in os.listdir(yumrepodir_abs):
        if rpm.endswith(".rpm"):
            built_rpms.append(os.path.join(yumrepodir, rpm))
    if not built_rpms:
        raise Exception("No rpms built for %s" % project)

    notes = "OK"
    if not os.path.isfile(os.path.join(yumrepodir_abs, "installed")):
        notes = "Error installing"

    for otherproject in cp.sections():
        if otherproject == project:
            continue
        last_success = session.query(Commit).\
            filter(Commit.project_name == otherproject).\
            filter(Commit.status == "SUCCESS").\
            order_by(desc(Commit.dt_commit)).first()
        if not last_success:
            continue
        rpms = last_success.rpms.split(",")
        for rpm in rpms:
            rpm_link_src = os.path.join(yumrepodir_abs, os.path.split(rpm)[1])
            os.symlink(
                os.path.relpath(os.path.join(datadir, rpm), yumrepodir_abs),
                rpm_link_src)

    sh.createrepo(yumrepodir_abs)

    fp = open(os.path.join(yumrepodir_abs, "delorean.repo"), "w")
    fp.write("[delorean]\nname=delorean-%s-%s\nbaseurl=%s/%s\nenabled=1\n"
             "gpgcheck=0" %
             (project, commit, cp.get("DEFAULT", "baseurl"), yumrepodir))
    fp.close()

    current_repo_dir = os.path.join(datadir, "repos", "current")
    os.symlink(os.path.relpath(yumrepodir_abs, os.path.join(datadir, "repos")),
               current_repo_dir + "_")
    os.rename(current_repo_dir + "_", current_repo_dir)
    return built_rpms, notes
Пример #7
0
def build(cp, package_info, dt, project, repo_dir, commit):
    datadir = os.path.realpath(cp.get("DEFAULT", "datadir"))
    # TODO : only working by convention need to improve
    scriptsdir = datadir.replace("data", "scripts")
    yumrepodir = os.path.join("repos", commit[:2], commit[2:4], commit)
    yumrepodir_abs = os.path.join(datadir, yumrepodir)

    # If yum repo already exists remove it and assume we're starting fresh
    if os.path.exists(yumrepodir_abs):
        shutil.rmtree(yumrepodir_abs)
    os.makedirs(yumrepodir_abs)

    # We need to make sure if any patches exist in the master-patches branch
    # they they can still be applied to upstream master, if they can we stop
    testpatches(project, commit, datadir)

    sh.git("--git-dir", "%s/.git" % repo_dir,
           "--work-tree=%s" % repo_dir, "reset", "--hard", commit)
    try:
        sh.docker("kill", "builder")
    except:
        pass

    # looks like we need to give the container time to die
    time.sleep(20)
    try:
        sh.docker("rm", "builder")
    except:
        pass

    try:
        sh.docker("run", "-t", "--volume=%s:/data" % datadir,
                  "--volume=%s:/scripts" % scriptsdir,
                  "--name", "builder", "delorean/fedora",
                  "/scripts/build_rpm_wrapper.sh", project,
                  "/data/%s" % yumrepodir)
    except:
        raise Exception("Error while building packages")

    built_rpms = []
    for rpm in os.listdir(yumrepodir_abs):
        if rpm.endswith(".rpm"):
            built_rpms.append(os.path.join(yumrepodir, rpm))
    if not built_rpms:
        raise Exception("No rpms built for %s" % project)

    notes = "OK"
    if not os.path.isfile(os.path.join(yumrepodir_abs, "installed")):
        notes = "Error installing"

    packages = [package["name"] for package in package_info["packages"]]
    for otherproject in packages:
        if otherproject == project:
            continue
        last_success = session.query(Commit).\
            filter(Commit.project_name == otherproject).\
            filter(Commit.status == "SUCCESS").\
            order_by(desc(Commit.dt_commit)).first()
        if not last_success:
            continue
        rpms = last_success.rpms.split(",")
        for rpm in rpms:
            rpm_link_src = os.path.join(yumrepodir_abs, os.path.split(rpm)[1])
            os.symlink(os.path.relpath(os.path.join(datadir, rpm),
                       yumrepodir_abs), rpm_link_src)

    sh.createrepo(yumrepodir_abs)

    fp = open(os.path.join(yumrepodir_abs, "delorean.repo"), "w")
    fp.write("[delorean]\nname=delorean-%s-%s\nbaseurl=%s/%s\nenabled=1\n"
             "gpgcheck=0" % (project, commit, cp.get("DEFAULT", "baseurl"),
                             yumrepodir))
    fp.close()

    current_repo_dir = os.path.join(datadir, "repos", "current")
    os.symlink(os.path.relpath(yumrepodir_abs, os.path.join(datadir, "repos")),
               current_repo_dir+"_")
    os.rename(current_repo_dir+"_", current_repo_dir)
    return built_rpms, notes
Пример #8
0
def build(cp, packages, commit, env_vars, dev_mode, use_public, bootstrap):

    # Set the build timestamp to now
    commit.dt_build = int(time())

    scriptsdir = os.path.realpath(cp.get("DEFAULT", "scriptsdir"))
    run(os.path.join(scriptsdir, "build_rpm_wrapper.sh"), cp, commit, env_vars,
        dev_mode, use_public, bootstrap)

    datadir = os.path.realpath(cp.get("DEFAULT", "datadir"))
    yumrepodir = os.path.join("repos", commit.getshardedcommitdir())
    yumrepodir_abs = os.path.join(datadir, yumrepodir)
    commit_hash = commit.commit_hash
    project_name = commit.project_name

    built_rpms = []
    for rpm in os.listdir(yumrepodir_abs):
        if rpm.endswith(".rpm"):
            built_rpms.append(os.path.join(yumrepodir, rpm))
    if not built_rpms:
        raise Exception("No rpms built for %s" % project_name)

    notes = "OK"
    if not os.path.isfile(os.path.join(yumrepodir_abs, "installed")):
        logger.error('Build failed. See logs at: %s/%s/' % (datadir,
                                                            yumrepodir))
        raise Exception("Error installing %s" % project_name)

    shafile = open(os.path.join(yumrepodir_abs, "versions.csv"), "w")
    shafile.write("Project,Source Repo,Source Sha,Dist Repo,Dist Sha,"
                  "Status,Last Success Timestamp\n")
    failures = 0

    for otherproject in packages:
        otherprojectname = otherproject["name"]
        if otherprojectname == project_name:
            # Output sha's this project
            dumpshas2file(shafile, commit, otherproject["upstream"],
                          otherproject["master-distgit"], "SUCCESS",
                          commit.dt_build)
            continue
        # Output sha's of all other projects represented in this repo
        last_success = getCommits(session, project=otherprojectname,
                                  with_status="SUCCESS").first()
        last_processed = getLastProcessedCommit(session, otherprojectname,
                                                'INVALID STATE')
        if last_success:
            for rpm in last_success.rpms.split(","):
                rpm_link_src = os.path.join(yumrepodir_abs,
                                            os.path.split(rpm)[1])
                os.symlink(os.path.relpath(os.path.join(datadir, rpm),
                                           yumrepodir_abs), rpm_link_src)
            last = last_success
        else:
            last = last_processed
        if last:
            dumpshas2file(shafile, last, otherproject["upstream"],
                          otherproject["master-distgit"],
                          last_processed.status, last.dt_build)
            if last_processed.status != 'SUCCESS':
                failures += 1
        else:
            failures += 1
    shafile.close()

    sh.createrepo(yumrepodir_abs)

    with open(os.path.join(
            yumrepodir_abs, "%s.repo" % cp.get("DEFAULT", "reponame")),
            "w") as fp:
        fp.write("[%s]\nname=%s-%s-%s\nbaseurl=%s/%s\nenabled=1\n"
                 "gpgcheck=0\npriority=1" % (cp.get("DEFAULT", "reponame"),
                                             cp.get("DEFAULT", "reponame"),
                                             project_name, commit_hash,
                                             cp.get("DEFAULT", "baseurl"),
                                             commit.getshardedcommitdir()))

    dirnames = ['current']
    if failures == 0:
        dirnames.append('consistent')
    else:
        logger.info('%d packages not built correctly: not updating the '
                    'consistent symlink' % failures)
    for dirname in dirnames:
        target_repo_dir = os.path.join(datadir, "repos", dirname)
        os.symlink(os.path.relpath(yumrepodir_abs,
                                   os.path.join(datadir, "repos")),
                   target_repo_dir + "_")
        os.rename(target_repo_dir + "_", target_repo_dir)
    return built_rpms, notes
Пример #9
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--noclean', action='store_true')
    args = parser.parse_args()

    #src_repo = 'https://github.com/jctanner/ansible'
    #src_branch = 'MAZER_DEMO_BRANCH'
    src_repo = 'https://github.com/nitzmahone/ansible.git'
    src_branch = 'collection_content_load'

    src_dir = '/tmp/ansible.mazer.checkout'
    dst_dir = '/tmp/ansible.mazer.build'

    if not os.path.exists(src_dir):
        logger.info('cloning source repo')
        git.clone('--branch=%s' % src_branch, src_repo, src_dir)

    logger.info('copying source checkout to build checkout')
    if os.path.exists(dst_dir):
        shutil.rmtree(dst_dir)
    shutil.copytree(src_dir, dst_dir)

    logger.info('cleaning out fragments')
    #mdfd = os.path.join(dst_dir, 'lib', 'ansible', 'utils', 'module_docs_fragments')
    mdfd = os.path.join(dst_dir, 'lib', 'ansible', 'plugins', 'doc_fragments')
    fragments = find(mdfd)
    fragments = [x.strip() for x in fragments if x.strip()]
    for ff in fragments:
        if not os.path.exists(ff):
            continue
        if ff == mdfd:
            continue
        found = False
        for wl in FRAGMENT_WHITELIST:
            if wl in ff:
                found = True
                break
        if not found:
            if os.path.isdir(ff):
                shutil.rmtree(ff)
            else:
                os.remove(ff)

    logger.info('cleaning out modules')
    module_files = find(os.path.join(dst_dir, 'lib', 'ansible', 'modules'))
    module_files = [x.strip() for x in module_files]
    for mf in module_files:
        if mf.endswith('/modules'):
            continue
        if not os.path.exists(mf):
            continue
        found = False
        for wl in MODULE_WHITELIST:
            if wl in mf:
                found = True
                break
        if not found:
            if os.path.isdir(mf):
                shutil.rmtree(mf)
            else:
                os.remove(mf)

    logger.info('cleaning out module utils')
    module_util_files = find(
        os.path.join(dst_dir, 'lib', 'ansible', 'module_utils'))
    module_util_files = [x.strip() for x in module_util_files]
    for muf in module_util_files:
        if muf.endswith('/module_utils'):
            continue
        if not os.path.exists(muf):
            continue
        found = False
        for wl in MODULE_UTIL_WHITELIST:
            if wl in muf:
                found = True
                break
        if not found:
            if os.path.isdir(muf):
                shutil.rmtree(muf)
            else:
                os.remove(muf)

    logger.info('running "make rpm"')
    try:
        make.clean(_cwd=dst_dir)
        make('rpm', _cwd=dst_dir)
    except Exception as e:
        print(e.stdout)
        print(e.stderr)
        sys.exit(1)

    logger.info('cleaning out old repo metadata')
    #repodir = '/var/cache/gravity/repos/rpm'
    repodir = 'cache/repos/rpm'
    repodata_dir = os.path.join(repodir, 'repodata')
    if os.path.exists(repodata_dir):
        shutil.rmtree(repodata_dir)

    logger.info('removing old ansible rpms from repo path')
    rpms = find(repodir, '-maxdepth', '1', '-name', '*MAZERDEMO*.rpm')
    for rpm in rpms:
        os.remove(rpm.strip())

    logger.info('copying ansible rpms to new repo path')
    rpms = find(os.path.join(dst_dir, 'rpm-build'), '-maxdepth', '1', '-name',
                '*.rpm')
    for rpm in rpms:
        shutil.copy(rpm.strip(), repodir)

    logger.info('creating repo')
    createrepo('.', _cwd=repodir)
Пример #10
0
def post_build_rpm(status, packages, session, build_repo=True):
    config_options = getConfigOptions()
    commit = status[0]
    built_rpms = status[1]
    project_name = commit.project_name
    commit_hash = commit.commit_hash
    datadir = os.path.realpath(config_options.datadir)
    yumrepodir = os.path.join("repos", commit.getshardedcommitdir())
    yumrepodir_abs = os.path.join(datadir, yumrepodir)

    shafile = open(os.path.join(yumrepodir_abs, "versions.csv"), "w")
    shafile.write("Project,Source Repo,Source Sha,Dist Repo,Dist Sha,"
                  "Status,Last Success Timestamp,Pkg NVR\n")
    failures = 0

    for otherproject in packages:
        otherprojectname = otherproject["name"]
        if otherprojectname == project_name:
            # Output sha's this project
            dumpshas2file(shafile, commit, otherproject["upstream"],
                          otherproject["master-distgit"], "SUCCESS",
                          commit.dt_build, built_rpms)
            continue
        # Output sha's of all other projects represented in this repo
        last_success = getCommits(session, project=otherprojectname,
                                  with_status="SUCCESS",
                                  type=commit.type).first()
        last_processed = getCommits(session, project=otherprojectname,
                                    type=commit.type).first()

        if last_success:
            if build_repo:
                for rpm in last_success.artifacts.split(","):
                    rpm_link_src = os.path.join(yumrepodir_abs,
                                                os.path.split(rpm)[1])
                    os.symlink(os.path.relpath(os.path.join(datadir, rpm),
                                               yumrepodir_abs), rpm_link_src)
            last = last_success
        else:
            last = last_processed
        if last:
            if last.artifacts:
                rpmlist = last.artifacts.split(",")
            else:
                rpmlist = []
            upstream = otherproject.get('upstream', '')
            dumpshas2file(shafile, last, upstream,
                          otherproject["master-distgit"],
                          last_processed.status, last.dt_build,
                          rpmlist)
            if last_processed.status != 'SUCCESS':
                failures += 1
        else:
            failures += 1
    shafile.close()

    if build_repo:
        # Use createrepo_c when available
        try:
            from sh import createrepo_c
            sh.createrepo = createrepo_c
        except ImportError:
            pass

        if config_options.include_srpm_in_repo:
            sh.createrepo(yumrepodir_abs)
        else:
            sh.createrepo('-x', '*.src.rpm', yumrepodir_abs)

        with open(os.path.join(
                yumrepodir_abs, "%s.repo" % config_options.reponame),
                "w") as fp:
            fp.write("[%s]\nname=%s-%s-%s\nbaseurl=%s/%s\nenabled=1\n"
                     "gpgcheck=0\npriority=1\n" % (
                         config_options.reponame,
                         config_options.reponame,
                         project_name, commit_hash,
                         config_options.baseurl,
                         commit.getshardedcommitdir()))

    return failures
Пример #11
0
def post_build_rpm(status, packages, session, build_repo=True):
    config_options = getConfigOptions()
    commit = status[0]
    built_rpms = status[1]
    project_name = commit.project_name
    commit_hash = commit.commit_hash
    datadir = os.path.realpath(config_options.datadir)
    yumrepodir = os.path.join("repos", commit.getshardedcommitdir())
    yumrepodir_abs = os.path.join(datadir, yumrepodir)

    shafile = open(os.path.join(yumrepodir_abs, "versions.csv"), "w")
    shafile.write("Project,Source Repo,Source Sha,Dist Repo,Dist Sha,"
                  "Status,Last Success Timestamp,Component,Extended Sha,"
                  "Pkg NVR\n")
    failures = 0

    for otherproject in packages:
        if (config_options.use_components and 'component' in otherproject
                and otherproject['component'] != commit.component):
            # Only dump information and create symlinks for the same component
            continue

        otherprojectname = otherproject["name"]
        if otherprojectname == project_name:
            # Output sha's this project
            dumpshas2file(shafile, commit, otherproject["upstream"],
                          otherproject["master-distgit"], "SUCCESS",
                          commit.dt_build, commit.component, built_rpms)
            continue
        # Output sha's of all other projects represented in this repo
        last_success = getCommits(session,
                                  project=otherprojectname,
                                  with_status="SUCCESS",
                                  type=commit.type).first()
        last_processed = getCommits(session,
                                    project=otherprojectname,
                                    type=commit.type).first()

        if last_success:
            if build_repo:
                for rpm in last_success.artifacts.split(","):
                    rpm_link_src = os.path.join(yumrepodir_abs,
                                                os.path.split(rpm)[1])
                    os.symlink(
                        os.path.relpath(os.path.join(datadir, rpm),
                                        yumrepodir_abs), rpm_link_src)
            last = last_success
        else:
            last = last_processed
        if last:
            if last.artifacts:
                rpmlist = last.artifacts.split(",")
            else:
                rpmlist = []
            upstream = otherproject.get('upstream', '')
            dumpshas2file(shafile, last, upstream,
                          otherproject["master-distgit"],
                          last_processed.status, last.dt_build,
                          commit.component, rpmlist)
            if last_processed.status != 'SUCCESS':
                failures += 1
        else:
            failures += 1
    shafile.close()

    if build_repo:
        # Use createrepo_c when available
        try:
            from sh import createrepo_c
            sh.createrepo = createrepo_c
        except ImportError:
            pass

        if config_options.include_srpm_in_repo:
            sh.createrepo(yumrepodir_abs)
        else:
            sh.createrepo('-x', '*.src.rpm', yumrepodir_abs)

        with open(
                os.path.join(yumrepodir_abs,
                             "%s.repo" % config_options.reponame), "w") as fp:
            if config_options.use_components:
                repo_id = "%s-component-%s" % (config_options.reponame,
                                               commit.component)
            else:
                repo_id = config_options.reponame
            fp.write(
                "[%s]\nname=%s-%s-%s\nbaseurl=%s/%s\nenabled=1\n"
                "gpgcheck=0\npriority=1\n" %
                (repo_id, config_options.reponame, project_name, commit_hash,
                 config_options.baseurl, commit.getshardedcommitdir()))

    return failures