Пример #1
0
def create_rpm_installer(target, config, python_spec='python'):
    rpm_prefix = config['rpm']['prefix']
    index = conda.api.get_index()
    matches = Resolve(index).get_pkgs(MatchSpec(python_spec))
    if not matches:
        raise RuntimeError('No python found in the channels.')
    # Pick the latest Python match.
    pkg_info = sorted(matches)[-1].info
    dist_name = '{}-{}-{}'.format(pkg_info['name'], pkg_info['version'],
                                  pkg_info['build'])
    pkg_cache = os.path.join(target, 'SOURCES') 
    if not conda_install.is_fetched(pkg_cache, dist_name):
        print('Fetching {}'.format(dist_name))
        conda.fetch.fetch_pkg(pkg_info, pkg_cache)

    installer_source = os.path.join(os.path.dirname(__file__), 'install.py')
    installer_target = os.path.join(pkg_cache, 'install.py')

    shutil.copyfile(installer_source, installer_target)

    spec_dir = os.path.join(target, 'SPECS')
    if not os.path.exists(spec_dir):
        os.makedirs(spec_dir)

    specfile = os.path.join(spec_dir, '{}-installer.spec'.format(rpm_prefix))
    with open(specfile, 'w') as fh:
        fh.write(generate.render_installer(pkg_info, config))
Пример #2
0
def create_rpmbuild_for_env(pkgs, target, config):
    rpm_prefix = config['rpm']['prefix']
    pkg_cache = os.path.join(target, 'SOURCES')
    pkg_names = set(pkg for _, pkg in pkgs)

    if os.path.exists(target):
        # The environment we want to deploy already exists. We should
        # just double check that there aren't already packages in there which
        # we need to remove before we install anything new.
        linked = conda_install.linked(target)
        for pkg in linked:
            if pkg not in pkg_names:
                conda_install.unlink(target, pkg)
    else:
        linked = []

    if set(linked) == pkg_names:
        # We don't need to re-link everything - it is already as expected.
        # The downside is that we are not verifying that each package is
        # installed correctly.
        return

    spec_dir = os.path.join(target, 'SPECS')
    if not os.path.exists(spec_dir):
        os.makedirs(spec_dir)

    for source, pkg in pkgs:
        index = conda.fetch.fetch_index([source], use_cache=False)
        pkg_index = {pkg_info['fn']: pkg_info for pkg_info in index.values()}
        tar_name = pkg + '.tar.bz2'
        pkg_info = pkg_index.get(tar_name, None)
        if pkg_info is None:
            raise ValueError('Distribution {} is no longer available '
                             'in the channel {}.'.format(tar_name, source))
        if not conda_install.is_fetched(pkg_cache, pkg):
            print('Fetching {}'.format(pkg))
            conda.fetch.fetch_pkg(pkg_info, pkg_cache)
        spec_path = os.path.join(spec_dir,
                                 '{}-pkg-{}.spec'.format(rpm_prefix, pkg))
        if not os.path.exists(spec_path):
            spec = generate.render_dist_spec(os.path.join(pkg_cache, tar_name),
                                             config)
            with open(spec_path, 'w') as fh:
                fh.write(spec)
Пример #3
0
def create_rpmbuild_for_env(pkgs, target, config):
    rpm_prefix = config['rpm']['prefix']
    pkg_cache = os.path.join(target, 'SOURCES')
    pkg_names = set(pkg for _, pkg in pkgs)
    if os.path.exists(target):
        # The environment we want to deploy already exists. We should
        # just double check that there aren't already packages in there which
        # we need to remove before we install anything new.
        linked = conda_install.linked(target)
        for pkg in linked:
            if pkg not in pkg_names:
                conda_install.unlink(target, pkg)
    else:
        linked = []

    if set(linked) == pkg_names:
        # We don't need to re-link everything - it is already as expected.
        # The downside is that we are not verifying that each package is
        # installed correctly.
        return

    spec_dir = os.path.join(target, 'SPECS')
    if not os.path.exists(spec_dir):
        os.makedirs(spec_dir)
    for source, pkg in pkgs:
        index = conda.fetch.fetch_index([source], use_cache=False)
        pkg_index = {pkg_info['fn']: pkg_info for pkg_info in index.values()}
        tar_name = pkg + '.tar.bz2'
        pkg_info = pkg_index.get(tar_name, None)
        if pkg_info is None:
            raise ValueError('Distribution {} is no longer available '
                             'in the channel {}.'.format(tar_name, source))
        dist_name = pkg 
        if not conda_install.is_fetched(pkg_cache, dist_name):
            print('Fetching {}'.format(dist_name))
            conda.fetch.fetch_pkg(pkg_info, pkg_cache)
        spec_path = os.path.join(spec_dir, '{}-pkg-{}.spec'.format(rpm_prefix,
                                                                   pkg))
        if not os.path.exists(spec_path):
            spec = generate.render_dist_spec(os.path.join(pkg_cache,
                                                          tar_name), config)
            with open(spec_path, 'w') as fh:
                fh.write(spec)