summaryrefslogtreecommitdiffstats
path: root/src/lib/Server/Plugins/Pkgmgr.py
diff options
context:
space:
mode:
authorNarayan Desai <desai@mcs.anl.gov>2006-01-23 22:35:40 +0000
committerNarayan Desai <desai@mcs.anl.gov>2006-01-23 22:35:40 +0000
commitedca0b698637c3fd0a70af7e4752a46afca938d3 (patch)
tree658fad717833200ccb4e3725c811ccce7c10fc8d /src/lib/Server/Plugins/Pkgmgr.py
parent8ca8a153dfc6bd81ede9f5cff1ee3f111ae053ee (diff)
downloadbcfg2-edca0b698637c3fd0a70af7e4752a46afca938d3.tar.gz
bcfg2-edca0b698637c3fd0a70af7e4752a46afca938d3.tar.bz2
bcfg2-edca0b698637c3fd0a70af7e4752a46afca938d3.zip
last step of repo switches
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@1716 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib/Server/Plugins/Pkgmgr.py')
-rw-r--r--src/lib/Server/Plugins/Pkgmgr.py128
1 files changed, 41 insertions, 87 deletions
diff --git a/src/lib/Server/Plugins/Pkgmgr.py b/src/lib/Server/Plugins/Pkgmgr.py
index 8521994e0..e77dd99e5 100644
--- a/src/lib/Server/Plugins/Pkgmgr.py
+++ b/src/lib/Server/Plugins/Pkgmgr.py
@@ -1,100 +1,54 @@
'''This module implements a package management scheme for all images'''
__revision__ = '$Revision$'
-from copy import deepcopy
-from re import compile as regcompile
+import re
from syslog import syslog, LOG_ERR
+import Bcfg2.Server.Plugin
-from Bcfg2.Server.Plugin import Plugin, PluginInitError, PluginExecutionError, DirectoryBacked, XMLFileBacked
-
-class PackageEntry(XMLFileBacked):
- '''PackageEntry is a set of packages and locations for a single image'''
- __identifier__ = 'image'
- splitters = {'rpm':regcompile('^(?P<name>[\w\+\d\.]+(-[\w\+\d\.]+)*)-' + \
+class PNode(Bcfg2.Server.Plugin.LNode):
+ '''PNode has a list of packages available at a particular group intersection'''
+ splitters = {'rpm':re.compile('^(?P<name>[\w\+\d\.]+(-[\w\+\d\.]+)*)-' + \
'(?P<version>[\w\d\.]+-([\w\d\.]+))\.(?P<arch>\w+)\.rpm$'),
- 'encap':regcompile('^(?P<name>\w+)-(?P<version>[\w\d\.-]+).encap.*$')}
-
- def __init__(self, filename):
- XMLFileBacked.__init__(self, filename)
- self.packages = {}
-
- def Index(self):
- '''Build internal data structures'''
- XMLFileBacked.Index(self)
- self.packages = {}
- for location in self.entries:
- for pkg in location.getchildren():
- if location.attrib.has_key('type'):
- pkg.set('type', location.get('type'))
- if pkg.attrib.has_key("simplefile"):
- self.packages[pkg.get('name')] = {}
- for key in pkg.attrib:
- self.packages[pkg.get('name')][key] = pkg.attrib[key]
- # most attribs will be set from pkg
- self.packages[pkg.get('name')]['url'] = "%s/%s" % (location.get('uri'), pkg.get('simplefile'))
- elif pkg.attrib.has_key("file"):
- if self.splitters.has_key(pkg.get('type')):
- mdata = self.splitters[pkg.get('type')].match(pkg.get('file'))
- if not mdata:
- syslog(LOG_ERR, "Failed to match pkg %s" % pkg.get('file'))
- continue
- pkgname = mdata.group('name')
- self.packages[pkgname] = mdata.groupdict()
- self.packages[pkgname]['url'] = location.get('uri') + '/' + pkg.get('file')
- self.packages[pkgname]['type'] = pkg.get('type')
- else:
- derived = [(ptype, self.splitters[ptype].match(pkg.get('file')).groupdict())
- for ptype in self.splitters if self.splitters[ptype].match(pkg.get('file'))]
- if not derived:
- syslog("Failed to match pkg %s" % pkg.get('file'))
- else:
- (ptype, mdata) = derived[0]
- pkgname = mdata['name']
- self.packages[pkgname] = mdata
- self.packages[pkgname]['url'] = location.get('uri') + '/' + pkg.get('file')
- self.packages[pkgname]['type'] = ptype
+ 'encap':re.compile('^(?P<name>\w+)-(?P<version>[\w\d\.-]+).encap.*$')}
+
+ def __init__(self, data, plist, parent=None):
+ # copy local attributes to all child nodes if no local attribute exists
+ for child in data.getchildren():
+ for attr in [key for key in data.attrib.keys() if key != 'name' and not child.attrib.has_key(key)]:
+ child.set(attr, data.get(attr))
+ Bcfg2.Server.Plugin.LNode.__init__(self, data, plist, parent)
+ for pkg in data.findall('./Package'):
+ if pkg.attrib.has_key('name') and pkg.get('name') not in plist:
+ plist.append(pkg.get('name'))
+ if pkg.attrib.has_key('simplefile'):
+ pkg.set('url', "%s/%s" % (pkg.get('uri'), pkg.get('simplefile')))
+ self.contents[pkg.get('name')] = pkg.attrib
+ else:
+ if pkg.attrib.has_key('file'):
+ pkg.set('url', '%s/%s' % (pkg.get('uri'), pkg.get('file')))
+ if self.splitters.has_key(pkg.get('type')):
+ mdata = self.splitters[pkg.get('type')].match(pkg.get('file'))
+ if not mdata:
+ syslog(LOG_ERR, "Pkgmgr: Failed to match pkg %s" % pkg.get('file'))
+ continue
+ pkgname = mdata.group('name')
+ self.contents[pkgname] = mdata.groupdict()
+ if pkg.attrib.get('file'):
+ self.contents[pkgname]['url'] = pkg.get('url')
+ self.contents[pkgname]['type'] = pkg.get('type')
+ if pkgname not in plist:
+ plist.append(pkgname)
else:
- self.packages[pkg.get('name')] = pkg.attrib
+ self.contents[pkg.get('name')] = pkg.attrib
-class PackageDir(DirectoryBacked):
- '''A directory of package files'''
- __child__ = PackageEntry
+class PkgSrc(Bcfg2.Server.Plugin.XMLSrc):
+ '''PkgSrc files contain a PNode hierarchy that returns matching package entries'''
+ __node__ = PNode
-class Pkgmgr(Plugin):
+class Pkgmgr(Bcfg2.Server.Plugin.XMLPrioDir):
'''This is a generator that handles package assignments'''
__name__ = 'Pkgmgr'
__version__ = '$Id$'
__author__ = 'bcfg-dev@mcs.anl.gov'
-
- def __init__(self, core, datastore):
- Plugin.__init__(self, core, datastore)
- try:
- self.pkgdir = PackageDir(self.data, self.core.fam)
- except OSError:
- self.LogError("Pkgmgr: Failed to load package indices")
- raise PluginInitError
-
- def FindHandler(self, entry):
- '''Non static mechanism of determining entry provisioning'''
- if entry.tag != 'Package':
- raise PluginExecutionError, (entry.tag, entry.get('name'))
- return self.LocatePackage
-
- def LocatePackage(self, entry, metadata):
- '''Locates a package entry for particular metadata'''
- pkgname = entry.get('name')
- if self.pkgdir.entries.has_key("%s.xml" % metadata.hostname):
- pkglist = self.pkgdir["%s.xml" % metadata.hostname]
- if pkglist.packages.has_key(pkgname):
- pkginfo = pkglist.packages[pkgname]
- [entry.attrib.__setitem__(field, pkginfo[field]) for field in pkginfo]
- return
- elif not self.pkgdir.entries.has_key("%s.xml" % metadata.image):
- self.LogError("Pkgmgr: no package index for image %s" % metadata.image)
- raise PluginExecutionError, ("Image", metadata.image)
- pkglist = self.pkgdir["%s.xml" % (metadata.image)]
- if pkglist.packages.has_key(pkgname):
- pkginfo = pkglist.packages[pkgname]
- [entry.attrib.__setitem__(x, pkginfo[x]) for x in pkginfo]
- else:
- raise PluginExecutionError, ("Package", pkgname)
+ __child__ = PkgSrc
+ __element__ = 'Package'