summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2012-08-27 10:40:44 -0400
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2012-08-29 08:37:20 -0400
commit15a9f8e6c4994288b382ea2fa685a9e471850ff4 (patch)
treee24748df7341a1afe579b1477e9b73a2c989f188
parent18746a094e0ebfe3f16cc34c765e69e707e4c1ad (diff)
downloadbcfg2-15a9f8e6c4994288b382ea2fa685a9e471850ff4.tar.gz
bcfg2-15a9f8e6c4994288b382ea2fa685a9e471850ff4.tar.bz2
bcfg2-15a9f8e6c4994288b382ea2fa685a9e471850ff4.zip
Packages: made url_map consistent across all source types
Conflicts: src/lib/Server/Plugins/Packages/Collection.py src/lib/Server/Plugins/Packages/Yum.py
-rw-r--r--src/lib/Server/Plugins/Packages/Apt.py4
-rw-r--r--src/lib/Server/Plugins/Packages/Pac.py4
-rw-r--r--src/lib/Server/Plugins/Packages/Source.py24
-rw-r--r--src/lib/Server/Plugins/Packages/Yum.py105
4 files changed, 63 insertions, 74 deletions
diff --git a/src/lib/Server/Plugins/Packages/Apt.py b/src/lib/Server/Plugins/Packages/Apt.py
index f76bf7fa1..c1fae94d1 100644
--- a/src/lib/Server/Plugins/Packages/Apt.py
+++ b/src/lib/Server/Plugins/Packages/Apt.py
@@ -17,10 +17,6 @@ class AptSource(Source):
Source.__init__(self, basepath, xsource, config)
self.pkgnames = set()
- self.url_map = [{'rawurl': self.rawurl, 'url': self.url,
- 'version': self.version,
- 'components': self.components, 'arches': self.arches}]
-
def save_state(self):
cache = file(self.cachefile, 'wb')
cPickle.dump((self.pkgnames, self.deps, self.provides),
diff --git a/src/lib/Server/Plugins/Packages/Pac.py b/src/lib/Server/Plugins/Packages/Pac.py
index 9db6b0535..467af80a9 100644
--- a/src/lib/Server/Plugins/Packages/Pac.py
+++ b/src/lib/Server/Plugins/Packages/Pac.py
@@ -17,10 +17,6 @@ class PacSource(Source):
Source.__init__(self, basepath, xsource, config)
self.pkgnames = set()
- self.url_map = [{'rawurl': self.rawurl, 'url': self.url,
- 'version': self.version,
- 'components': self.components, 'arches': self.arches}]
-
def save_state(self):
cache = file(self.cachefile, 'wb')
cPickle.dump((self.pkgnames, self.deps, self.provides),
diff --git a/src/lib/Server/Plugins/Packages/Source.py b/src/lib/Server/Plugins/Packages/Source.py
index bd5a2b1a8..66a0afae7 100644
--- a/src/lib/Server/Plugins/Packages/Source.py
+++ b/src/lib/Server/Plugins/Packages/Source.py
@@ -44,7 +44,7 @@ class Source(Bcfg2.Server.Plugin.Debuggable):
try:
self.version = xsource.find('Version').text
except AttributeError:
- pass
+ self.version = None
for key, tag in [('components', 'Component'), ('arches', 'Arch'),
('blacklist', 'Blacklist'),
@@ -100,7 +100,27 @@ class Source(Bcfg2.Server.Plugin.Debuggable):
self.cachefile = os.path.join(self.basepath,
"cache-%s" % self.cachekey)
+ if not self.rawurl:
+ self.baseurl = self.url + "%(version)s/%(component)s/%(arch)s/"
+ else:
+ self.baseurl = self.rawurl
self.url_map = []
+ for arch in self.arches:
+ if self.url:
+ usettings = [dict(version=self.version, component=comp,
+ arch=arch)
+ for comp in self.components]
+ else: # rawurl given
+ usettings = [dict(version=self.version, component=None,
+ arch=arch)]
+
+ for setting in usettings:
+ if not self.rawurl:
+ setting['baseurl'] = self.url
+ else:
+ setting['baseurl'] = self.rawurl
+ setting['url'] = self.baseurl % setting
+ self.url_map.extend(usettings)
@property
def cachekey(self):
@@ -145,7 +165,7 @@ class Source(Bcfg2.Server.Plugin.Debuggable):
def get_repo_name(self, url_map):
# try to find a sensible name for a repo
- if 'component' in url_map and url_map['component']:
+ if url_map['component']:
rname = url_map['component']
else:
name = None
diff --git a/src/lib/Server/Plugins/Packages/Yum.py b/src/lib/Server/Plugins/Packages/Yum.py
index b603b4aae..3f0028aed 100644
--- a/src/lib/Server/Plugins/Packages/Yum.py
+++ b/src/lib/Server/Plugins/Packages/Yum.py
@@ -168,49 +168,48 @@ class YumCollection(Collection):
def get_config(self, raw=False):
config = ConfigParser.SafeConfigParser()
for source in self.sources:
- # get_urls() loads url_map as a side-effect
- source.get_urls()
for url_map in source.url_map:
- if url_map['arch'] in self.metadata.groups:
- basereponame = source.get_repo_name(url_map)
- reponame = basereponame
-
- added = False
- while not added:
- try:
- config.add_section(reponame)
- added = True
- except ConfigParser.DuplicateSectionError:
- match = re.search("-(\d+)", reponame)
- if match:
- rid = int(match.group(1)) + 1
- else:
- rid = 1
- reponame = "%s-%d" % (basereponame, rid)
-
- config.set(reponame, "name", reponame)
- config.set(reponame, "baseurl", url_map['url'])
- config.set(reponame, "enabled", "1")
- if len(source.gpgkeys):
- config.set(reponame, "gpgcheck", "1")
- config.set(reponame, "gpgkey",
- " ".join(source.gpgkeys))
- else:
- config.set(reponame, "gpgcheck", "0")
+ if url_map['arch'] not in self.metadata.groups:
+ continue
+ basereponame = source.get_repo_name(url_map)
+ reponame = basereponame
- if len(source.blacklist):
- config.set(reponame, "exclude",
- " ".join(source.blacklist))
- if len(source.whitelist):
- config.set(reponame, "includepkgs",
- " ".join(source.whitelist))
+ added = False
+ while not added:
+ try:
+ config.add_section(reponame)
+ added = True
+ except ConfigParser.DuplicateSectionError:
+ match = re.search("-(\d+)", reponame)
+ if match:
+ rid = int(match.group(1)) + 1
+ else:
+ rid = 1
+ reponame = "%s-%d" % (basereponame, rid)
+
+ config.set(reponame, "name", reponame)
+ config.set(reponame, "baseurl", url_map['url'])
+ config.set(reponame, "enabled", "1")
+ if len(source.gpgkeys):
+ config.set(reponame, "gpgcheck", "1")
+ config.set(reponame, "gpgkey",
+ " ".join(source.gpgkeys))
+ else:
+ config.set(reponame, "gpgcheck", "0")
- if raw:
- opts = source.server_options
- else:
- opts = source.client_options
- for opt, val in opts.items():
- config.set(reponame, opt, val)
+ if len(source.blacklist):
+ config.set(reponame, "exclude",
+ " ".join(source.blacklist))
+ if len(source.whitelist):
+ config.set(reponame, "includepkgs",
+ " ".join(source.whitelist))
+
+ if raw:
+ opts = source.server_options
+ else:
+ opts = source.client_options
+ for opt, val in opts.items():
+ config.set(reponame, opt, val)
if raw:
return config
@@ -506,10 +505,6 @@ class YumSource(Source):
self.repo['relative_path'])
self.arches = [self.repo['arch']]
- if not self.rawurl:
- self.baseurl = self.url + "%(version)s/%(component)s/%(arch)s/"
- else:
- self.baseurl = self.rawurl
self.packages = dict()
self.deps = dict([('global', dict())])
self.provides = dict([('global', dict())])
@@ -538,26 +533,8 @@ class YumSource(Source):
self.filemap, self.url_map) = cPickle.load(data)
def get_urls(self):
- surls = list()
- self.url_map = []
- for arch in self.arches:
- if self.url:
- usettings = [{'version':self.version, 'component':comp,
- 'arch':arch}
- for comp in self.components]
- else: # rawurl given
- usettings = [{'version':self.version, 'component':None,
- 'arch':arch}]
-
- for setting in usettings:
- setting['url'] = self.baseurl % setting
- self.url_map.append(copy.deepcopy(setting))
- surls.append((arch, [setting['url'] for setting in usettings]))
- urls = []
- for (sarch, surl_list) in surls:
- for surl in surl_list:
- urls.extend(self._get_urls_from_repodata(surl, sarch))
- return urls
+ return [self._get_urls_from_repodata(m['url'], m['arch'])
+ for m in self.url_map]
urls = property(get_urls)
def _get_urls_from_repodata(self, url, arch):