Ejemplo n.º 1
0
def main(argv):
    """
    Main function.  Parse spec file and iterate over its sources, downloading
    them as appropriate.
    """
    intercepted_args, passthrough_args = parse_args_or_exit(argv)
    config = os.path.join(intercepted_args.configdir, intercepted_args.root + ".cfg")

    loglevel = logging.INFO
    if intercepted_args.debug:
        loglevel = logging.DEBUG
    logging.basicConfig(format="%(message)s", level=loglevel)

    yum_config = util.load_mock_config(config)
    yumbase = util.get_yumbase(yum_config)
    setup_yumbase(yumbase)
    srpm = load_srpm_from_file(passthrough_args[-1])
    with open(config) as cfg:
        mock_config = cfg.read()
    pkg_hash = get_srpm_hash(srpm, yumbase, mock_config)

    cachedirs = [os.path.expanduser(x) for x in intercepted_args.cachedirs.split(":")]

    # Rebuild if not available in the cache
    if not in_cache(cachedirs, pkg_hash):
        logging.debug("Cache miss - rebuilding")
        build_output = build_package(intercepted_args.configdir, intercepted_args.root, passthrough_args)
        add_to_cache(cachedirs, pkg_hash, build_output)

    # Expand default resultdir as done in mock.backend.Root
    resultdir = intercepted_args.resultdir or yum_config["resultdir"] % yum_config
    get_from_cache(cachedirs, pkg_hash, resultdir)
Ejemplo n.º 2
0
def main(argv):
    """
    Main function.  Parse spec file and iterate over its sources, downloading
    them as appropriate.
    """
    util.setup_sigint_handler()
    intercepted_args, passthrough_args = parse_args_or_exit(argv)
    config = os.path.join(intercepted_args.configdir,
                          intercepted_args.root + ".cfg")

    # Initialize yum before setting up logging, because yum uses
    # logging with a different default loglevel.   This avoids
    # having yum print lots of irrelevant messages during startup.
    yum_config = util.load_mock_config(config)
    yumbase = util.get_yumbase(yum_config)
    setup_yumbase(yumbase)

    util.setup_logging(intercepted_args)

    srpm = load_srpm_from_file(passthrough_args[-1])
    with open(config) as cfg:
        mock_config = cfg.read()
    pkg_hash = get_srpm_hash(srpm, yumbase, mock_config)

    cachedirs = [os.path.expanduser(x) for x
                 in intercepted_args.cachedirs.split(':')]

    # Expand default resultdir as done in mock.backend.Root
    resultdir = intercepted_args.resultdir or \
        yum_config['resultdir'] % yum_config

    if not os.path.isdir(resultdir):
        os.makedirs(resultdir)

    # Rebuild if not available in the cache
    if not in_cache(cachedirs, pkg_hash):
        logging.debug("Cache miss - rebuilding")
        build_output = build_package(intercepted_args.configdir,
                                     intercepted_args.root, passthrough_args)
        try:
            add_to_cache(cachedirs, pkg_hash, build_output)
        except OSError:
            # If we can't cache the result, that's not a fatal error
            pass

        for cached_file in os.listdir(build_output):
            dest = os.path.join(resultdir, cached_file)

            if os.path.exists(dest):
                os.unlink(dest)
            shutil.move(os.path.join(build_output, cached_file), resultdir)
    else:
        get_from_cache(cachedirs, pkg_hash, resultdir)
Ejemplo n.º 3
0
def main(argv):
    """
    Main function.  Parse spec file and iterate over its sources, downloading
    them as appropriate.
    """
    util.setup_sigint_handler()
    intercepted_args, passthrough_args = parse_args_or_exit(argv)
    config = os.path.join(intercepted_args.configdir,
                          intercepted_args.root + ".cfg")

    # Initialize yum before setting up logging, because yum uses
    # logging with a different default loglevel.   This avoids
    # having yum print lots of irrelevant messages during startup.
    yum_config = util.load_mock_config(config)
    yumbase = util.get_yumbase(yum_config)
    setup_yumbase(yumbase)

    util.setup_logging(intercepted_args)

    srpm = load_srpm_from_file(passthrough_args[-1])
    pkg_hash = get_srpm_hash(srpm, yumbase)

    cachedirs = [os.path.expanduser(x) for x
                 in intercepted_args.cachedirs.split(':')]

    # Expand default resultdir as done in mock.backend.Root
    resultdir = intercepted_args.resultdir or \
        yum_config['resultdir'] % yum_config

    if not os.path.isdir(resultdir):
        os.makedirs(resultdir)

    # Rebuild if not available in the cache
    if not in_cache(cachedirs, pkg_hash):
        logging.debug("Cache miss - rebuilding")
        build_output = build_package(intercepted_args.configdir,
                                     intercepted_args.root, passthrough_args)
        try:
            add_to_cache(cachedirs, pkg_hash, build_output)
        except OSError:
            # If we can't cache the result, that's not a fatal error
            pass

        for cached_file in os.listdir(build_output):
            dest = os.path.join(resultdir, cached_file)

            if os.path.exists(dest):
                os.unlink(dest)
            shutil.move(os.path.join(build_output, cached_file), resultdir)
    else:
        get_from_cache(cachedirs, pkg_hash, resultdir)
Ejemplo n.º 4
0
def sort_mockconfig(config):
    config_dir = config.config_dir
    if not os.path.exists(MOCK_DIR):
        print_col(bcolours.OKGREEN,
                  "Creating mock configuration for current working directory")

        yum_config = load_mock_config(os.path.join(config_dir,
                                                   'mock', 'default.cfg'))
        yumbase = get_yumbase(yum_config)
        if yumbase.repos.findRepos(PLANEX_REPO_NAME) == []:
            print_col(bcolours.FAIL, "Planex repository not found")
            print """
Please add a repository stanza similar to:

[%s]
name=Mock output
baseurl = file://@PLANEX_BUILD_ROOT@/RPMS
gpgcheck=0
priority=1
enabled=1
metadata_expire=0
""" % PLANEX_REPO_NAME
            sys.exit(1)

        os.makedirs(MOCK_DIR)

        # Copy in all the files from config_dir
        mock_files = glob.glob(os.path.join(config_dir, 'mock', '*'))

        for mock_file in mock_files:
            basename = mock_file.split('/')[-1]
            dest_fname = os.path.join(MOCK_DIR, basename)
            print "  copying file '%s' to '%s'" % (mock_file, dest_fname)
            shutil.copyfile(mock_file, dest_fname)
            planex_build_root = os.path.join(os.getcwd(), BUILD_ROOT_DIR)
            with open(dest_fname, 'w') as dst:
                with open(mock_file) as src:
                    for line in src:
                        dst.write(re.sub(r"@PLANEX_BUILD_ROOT@",
                                         planex_build_root, line))