summaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2012-01-25 16:06:00 -0500
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2012-01-25 16:06:11 -0500
commit48ee74f4af26baf165a7d43ec5923d716fa4522a (patch)
tree05ba4a4d55df76c82c3e925d590cb8671bb96ac8 /src/lib
parent60301459da33e4fdad4c5bc4c836c8990238dd61 (diff)
downloadbcfg2-48ee74f4af26baf165a7d43ec5923d716fa4522a.tar.gz
bcfg2-48ee74f4af26baf165a7d43ec5923d716fa4522a.tar.bz2
bcfg2-48ee74f4af26baf165a7d43ec5923d716fa4522a.zip
made automatic repository naming not suck horribly
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/Server/Plugins/Packages/Source.py24
-rw-r--r--src/lib/Server/Plugins/Packages/Yum.py18
2 files changed, 32 insertions, 10 deletions
diff --git a/src/lib/Server/Plugins/Packages/Source.py b/src/lib/Server/Plugins/Packages/Source.py
index de7dedbc9..910a90cac 100644
--- a/src/lib/Server/Plugins/Packages/Source.py
+++ b/src/lib/Server/Plugins/Packages/Source.py
@@ -31,7 +31,9 @@ class SourceInitError(Exception):
class Source(Bcfg2.Server.Plugin.Debuggable):
- reponame_re = re.compile(r'.*/(?:RPMS\.)?([^/]+)')
+ mrepo_re = re.compile(r'/RPMS\.([^/]+)')
+ pulprepo_re = re.compile(r'pulp/repos/([^/]+)')
+ genericrepo_re = re.compile(r'https?://[^/]+/(.+?)/?$')
basegroups = []
def __init__(self, basepath, xsource, config):
@@ -133,16 +135,22 @@ class Source(Bcfg2.Server.Plugin.Debuggable):
def get_repo_name(self, url_map):
# try to find a sensible name for a repo
- match = self.reponame_re.search(url_map['url'])
if url_map['component']:
return url_map['component']
- elif match:
- return match.group(1)
else:
- # couldn't figure out the name from the URL or URL map
- # (which probably means its a screwy URL), so we just
- # generate a random one
- name = base64.b64encode(os.urandom(16))[:-2]
+ name = None
+ for repo_re in (self.mrepo_re,
+ self.pulprepo_re,
+ self.genericrepo_re):
+ match = repo_re.search(url_map['url'])
+ if match:
+ name = match.group(1).replace('/', '-')
+ break
+ if name is None:
+ # couldn't figure out the name from the URL or URL map
+ # (which probably means its a screwy URL), so we just
+ # generate a random one
+ name = base64.b64encode(os.urandom(16))[:-2]
return "%s-%s" % (self.groups[0], name)
def __str__(self):
diff --git a/src/lib/Server/Plugins/Packages/Yum.py b/src/lib/Server/Plugins/Packages/Yum.py
index 13a553031..a5fe706cd 100644
--- a/src/lib/Server/Plugins/Packages/Yum.py
+++ b/src/lib/Server/Plugins/Packages/Yum.py
@@ -144,8 +144,22 @@ class YumCollection(Collection):
source.get_urls()
for url_map in source.url_map:
if url_map['arch'] in self.metadata.groups:
- reponame = source.get_repo_name(url_map)
- config.add_section(reponame)
+ 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.match("-(\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")