Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os, sys, re
- import os.path
- try:
- from hashlib import md5
- except ImportError:
- from md5 import md5
- import ConfigParser
- import rpm
- from yum.plugins import PluginYumExit, TYPE_CORE
- from yum.repos import Repository
- from yum.yumRepo import YumRepository # , YumPackageSack
- from yum.packageSack import PackageSack
- from yum.packages import YumLocalPackage, YumHeaderPackage, YumAvailablePackage
- from yum.repoMDObject import RepoMD
- import rpmUtils, yum.Errors
- requires_api_version = '2.3'
- plugin_type = (TYPE_CORE,)
- cpacman_on=True
- # really weird location for libraries. Oh well...
- sys.path.append('/usr/share/yum-cli')
- from yumcommands import YumCommand
- # class CPacManPackage(YumHeaderPackage):
- class CPacManPackage(YumLocalPackage):
- def __init__(self,repo,hdr,localpath):
- self.localpath=localpath
- YumHeaderPackage.__init__(self,repo,hdr)
- self.pkgid = self.hdr[rpm.RPMTAG_SHA1HEADER]
- if not self.pkgid:
- self.pkgid = "%s.%s" %(self.hdr['name'], self.hdr['buildtime'])
- self.id=self.pkgid
- self.pkgKey = self.__hash__()
- def __getattr__(self, thing):
- #FIXME - if an error - return AttributeError, not KeyError
- # ONLY FIX THIS AFTER THE API BREAK
- if thing.startswith('__') and thing.endswith('__'):
- # If these existed, then we wouldn't get here ...
- # So these are missing.
- raise AttributeError, "%s has no attribute %s" % (self, thing)
- try:
- return self.hdr[thing]
- except KeyError:
- # Note above, API break to fix this ... this at least is a nicer
- # msg. so we know what we accessed that is bad.
- # print "%s has no attribute %s" % (self, thing)
- # return None
- raise KeyError, "%s (%s) has no attribute %s" % (self, self.repoid, thing)
- except ValueError:
- # Note above, API break to fix this ... this at least is a nicer
- # msg. so we know what we accessed that is bad.
- raise ValueError, "%s (%s) has no attribute %s" % (self, self.repoid, thing)
- def returnChecksums(self):
- return YumAvailablePackage.returnChecksums(self)
- class CPacManSack(PackageSack):
- def __init__(self):
- PackageSack.__init__(self)
- # looks like this is required property in some cases...
- self._pkgtup2pkgs=[]
- self.added={}
- def populate(self, repo, mdtype='metadata', callback=None, cacheonly=0):
- # print "In CPacMan Populate"
- self.added[repo]=[]
- return
- def get_added(self):
- return {}
- # added=property(get_added)
- def searchPrimaryFieldsMultipleStrings(self,fields,searchstrings):
- ##FIXME
- print "-=search=--=search=-"
- return []
- class CPacManYumRepo(YumRepository):
- """CPacMan repo that translates from collects all of the available packages into
- a neat Yum-like Repo object"""
- def __init__(self,server_name,repo_path,repoid):
- # global server_db, server
- YumRepository.__init__(self,repoid)
- self.cpacman_sack=CPacManSack()
- # we need private copies of ServerDB and Server here as we're going
- # to manipulate them
- self.repo_path=repo_path
- self.pkgdir=repo_path
- self.cost=1500
- self.__init_sack()
- ##FIXME Hacking around EL5 deficiencies
- try:
- self.repoXML=RepoMD(self.id)
- except TypeError:
- # looks like older version of Yum... we should be OK
- pass
- def __init_sack(self):
- # simplifying original call:
- # pl=self.server.listAvailablePackages(all_versions=0, ignore_policy=0, filter_path=self.repo_filter)
- # to a bare dictionary:
- pl={'a-1.1-1.i386':{'path':self.repo_path, 'package_name':'a-1.1-1.i386.rpm'}}
- ts=rpm.TransactionSet()
- # hack to disable DIGEST and SIGNATURE checks
- ts.setVSFlags((rpm._RPMVSF_NOSIGNATURES|rpm._RPMVSF_NODIGESTS))
- for pk in pl.keys():
- pkg=pl[pk]
- localpath=os.path.join(pkg['path'],pkg['package_name'])
- try:
- hdr = rpmUtils.miscutils.hdrFromPackage(ts, localpath)
- except rpmUtils.RpmUtilsError:
- raise yum.Errors.MiscError, \
- 'Could not open local rpm file: %s' % localpath
- ypkg=CPacManPackage(self, hdr, localpath)
- ypkg._populatePrco()
- ypkg.basepath='file://'+pkg['path']
- ypkg.relativepath=pkg['package_name']
- self.cpacman_sack.addPackage(ypkg)
- def getPackageSack(self):
- return self.cpacman_sack
- CPacManRepo=CPacManYumRepo
- def prereposetup_hook(conduit):
- ## Most of action happens here since this is the first stage where command-line arguments are being
- ## processed. Everything prior to this hook has no access to CLI args which we need to identify
- ## the server we're working on, or whether we need to kick-in at all...
- global cpacman_on
- # simplifying process here... we actually get
- # sc_path_str via different means...
- sc_path_str="/foo/bar:/baz/moo"
- # ... we have set cpacman_on based on previous conditions by now...
- if cpacman_on:
- repos=conduit.getRepos()
- ## filter out the paths of repos that are already enabled
- ## to avoid double-repo added via cpacman...
- path_filter=[]
- for r in repos.listEnabled():
- try:
- path_filter.append(r.pkgdir)
- conduit.info(2, "Adding repo.pkgdir: "+r.pkgdir)
- except AttributeError:
- # repo doesn't have pkgrid attribute
- # which is fine (?)...
- pass
- sc_path=sc_path_str.split(':')
- for p in sc_path:
- if not (p in path_filter):
- conduit.info(2, "Adding path: "+p)
- repoid=p.replace('/','_')
- cpm_repo=CPacManRepo(server_name=conf.servername,repo_path=p,repoid=repoid)
- cpacman_repos.append(repoid)
- try:
- repos.add(cpm_repo)
- except yum.Errors.DuplicateRepoError:
- pass
- repos.enableRepo(repoid)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement