On Thursday 24 Mar 2011 17:37:39 Baptiste AGASSE wrote:
> Before using spacewalk, i used cobbler to manage and mirror locally
> repositories like CentOS 5.x, EPEL... and i was abble to define what
> package i want to mirror (for example, EPEL repo have a lot of packages
> but i use only a few of them) and their dependencies.
> 
> I saw that spacewalk use cobbler for distros, but not for channel repo
> management.
> 
> So, my question is: Is it possible to filter which package to download
> from remote repository (with an "download only" or "exclude" condition) ?
> And, if not:
> Anybody have the same problem ?
> It will be included in future spacewalk version ?

Yes, I had the same problem.  In the meantime I hacked a plugin to spacewalk-
repo-sync to read includes from a config file, but it would be way better if 
support for reading and setting yum config options for spacewalk-repo-sync 
existed in Spacewalk natively.

I'm attaching the file in case you're interested, but I didn't have time to 
really think the design through, so it's a "quick & dirty" version (it's based 
on yum_src.py from Spacewalk).  Basically you have to put the file in 
/usr/lib/python2.4/site-packages/spacewalk/satellite_tools/repo_plugins/ and 
put a config file (like subset of yum config with just includepkgs options in 
each repo section) in /etc/rhn/spacewalk-repo-sync-yum.conf and then you can 
run e.g.:

  spacewalk-repo-sync --channel=epel-5-i386 --type=yumsubset

(assuming you have epel-5-i386 channel with repository URL and GPG keys 
defined).

You also have to hunt down all dependencies and include them in includepkgs 
manually.  I started working on something to make this easier but so far lack 
the time to get anywhere with it.

Let me know if that works for you (I'm away next week but will respond as soon 
as I'm back).


-- 
Michael Gliwinski
Henderson Group Information Services
9-11 Hightown Avenue, Newtownabby, BT36 4RT
Phone: 028 9034 3319

**********************************************************************************************
The information in this email is confidential and may be legally privileged.  
It is intended solely for the addressee and access to the email by anyone else 
is unauthorised.
If you are not the intended recipient, any disclosure, copying, distribution or 
any action taken or omitted to be taken in reliance on it, is prohibited and 
may be unlawful.
When addressed to our clients, any opinions or advice contained in this e-mail 
are subject to the terms and conditions expressed  in the governing client 
engagement leter or contract.
If you have received this email in error please notify 
[email protected]

John Henderson (Holdings) Ltd
Registered office: 9 Hightown Avenue, Mallusk, County Antrim, Northern Ireland, 
BT36 4RT.
Registered in Northern Ireland
Registration Number NI010588
Vat No.: 814 6399 12
*********************************************************************************

#
# Copyright (c) 2008--2010 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public License,
# version 2 (GPLv2). There is NO WARRANTY for this software, express or
# implied, including the implied warranties of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
# along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
# 
# Red Hat trademarks are not licensed under GPLv2. No permission is
# granted to use or replicate Red Hat trademarks that are incorporated
# in this software or its documentation. 
#
# Based on yum_src.py
#
import yum
import shutil
import sys

from ConfigParser import ConfigParser

from yum import config
from yum.packages import parsePackages
from spacewalk.satellite_tools.reposync import ContentPackage

class YumWarnings:
    def write(self, s):
        pass
    def disable(self):
        self.saved_stdout = sys.stdout
        sys.stdout = self
    def restore(self):
        sys.stdout = self.saved_stdout

class ContentSource(object):
    url = None
    name = None
    cache_dir = '/var/cache/rhn/reposync/'
    conf_fn = '/etc/rhn/spacewalk-repo-sync-yum.conf'
    def __init__(self, url, name):
        self.url = url
        self.name = name
        self._repo = None
        self._clean_cache(self.cache_dir + name)
        self._parser = ConfigParser()
        self._parser.read(self.conf_fn)

    def list_packages(self):
        """ list packages"""
        list = self.repo.sack.returnPackages()
        to_return = []
        for pack in list:
            new_pack = ContentPackage()
            new_pack.setNVREA(pack.name, pack.version, pack.release, 
                              pack.epoch, pack.arch)
            new_pack.unique_id = pack
            for cs in pack.checksums:
                new_pack.checksums[cs[0]] = cs[1]
            to_return.append(new_pack)
        return to_return

    def get_package(self, package):
        """ get package """
        check = (self.verify_pkg, (package.unique_id ,1), {})
        return self.repo.getPackage(package.unique_id, checkfunc=check)

    def verify_pkg(self, fo, pkg, fail):
        return pkg.verifyLocalPkg()

    def _clean_cache(self, directory):
        shutil.rmtree(directory, True)

    def _filter_pkgs(self, repo):
        """Filter repository packages according to repo options.

        Options are: includepkgs

        This is based on YumBase.includePackages

        @todo: why oh why isn't this done by repository itself?
        """
        includelist = repo.getIncludePkgList()
        if not includelist: return

        pkglist = repo.sack.returnPackages()

        exactmatch, matched, unmatched = \
            parsePackages(pkglist, includelist, casematch=1)
        keeplist = set(exactmatch + matched)

        for pkg in pkglist:
            if pkg not in keeplist:
                repo.sack.delPackage(pkg)

    @property
    def repo(self):
        """Return a configured YumRepository object for this source."""
        if self._repo is not None: return self._repo

        repo = yum.yumRepo.YumRepository(self.name)
        repo.populate(self._parser, self.name)
        repo.cache = 0
        repo.metadata_expire = 0
        repo.mirrorlist = self.url
        repo.baseurl = [self.url]
        repo.basecachedir = self.cache_dir

        warnings = YumWarnings()
        warnings.disable()
        repo.baseurlSetup()
        warnings.restore()

        repo.setup(False)
        repo.sack.populate(repo, 'metadata', None, 0)
        self._filter_pkgs(repo)

        self._repo = repo
        return repo

if __name__ == '__main__':
    src = ContentSource('http://mirrors.fedoraproject.org/mirrorlist?repo=epel-5&arch=i386', 'epel')
    from pprint import pprint
    for pack in src.list_packages():
        pprint(pack)
_______________________________________________
Spacewalk-list mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/spacewalk-list

Reply via email to