From 2be7d4cc7e7fb44f801591dfe73ade84e02e7a65 Mon Sep 17 00:00:00 2001
From: Luke Macken <lmacken@redhat.com>
Date: Tue, 23 Jun 2009 12:07:25 -0400
Subject: [PATCH] Lots of refactoring to try and support other releases, such as Fedora EPEL.

- No database schema changes
- Add a few new @properties to the Release model to get the appropriate
stable/candidate/testing tags for various releases
- Change the mail.get_template API a little bit to accept a string for
use_template instead of the template itself.
- Make our tag checking code a bit more generic

diff --git a/bodhi/controllers.py b/bodhi/controllers.py
index 10a68bb..00f4b37 100644
--- a/bodhi/controllers.py
+++ b/bodhi/controllers.py
@@ -601,20 +601,21 @@ class Root(controllers.RootController):
 
             # Determine which release this build is a candidate for
             for tag in tags:
-                dist = tag.split('-updates-candidate')
-                if len(dist) == 2: # candidate tag
-                    rel = Release.selectBy(dist_tag=dist[0])
-                    if rel.count():
-                        rel = rel[0]
-                        log.debug("Adding %s for %s" % (rel.name, build))
-                        if not releases.has_key(rel):
-                            releases[rel] = []
-                        if build not in releases[rel]:
-                            releases[rel].append(build)
-                        buildinfo[build]['releases'].add(rel)
-                        valid = True
-                    else:
-                        log.error("Cannot find release for %s" % dist[0])
+                rel = None
+                for r in Release.select():
+                    if tag == r.candidate_tag:
+                        rel = r
+                        break
+                if rel:
+                    log.debug("Adding %s for %s" % (rel.name, build))
+                    if not releases.has_key(rel):
+                        releases[rel] = []
+                    if build not in releases[rel]:
+                        releases[rel].append(build)
+                    buildinfo[build]['releases'].add(rel)
+                    valid = True
+                else:
+                    log.debug("%s not a candidate tag" % tag)
 
             # if we're using build inheritance, iterate over each release
             # looking to see if the latest build in its candidate tag 
@@ -622,7 +623,7 @@ class Root(controllers.RootController):
             if inheritance:
                 log.info("Following build inheritance")
                 for rel in Release.select():
-                    b = koji.listTagged(rel.dist_tag + '-updates-candidate',
+                    b = koji.listTagged(rel.candidate_tag,
                                         inherit=True, latest=True,
                                         package=buildinfo[build]['nvr'][0])[0]
                     if b['nvr'] == build:
@@ -647,8 +648,7 @@ class Root(controllers.RootController):
             # Check for broken update paths
             log.info("Checking for broken update paths")
             for release in buildinfo[build]['releases']:
-                tags = ['dist-rawhide', release.dist_tag,
-                        release.dist_tag + '-updates']
+                tags = ['dist-rawhide', release.dist_tag, release.stable_tag]
                 for tag in tags:
                     pkg = buildinfo[build]['nvr'][0]
                     for oldBuild in koji.listTagged(tag, package=pkg,
@@ -1118,8 +1118,7 @@ class Root(controllers.RootController):
         builds = {}
         koji = buildsys.get_session()
         for release in Release.select():
-            for tag in ('updates-candidate', 'updates-testing', 'updates'):
-                tag = '%s-%s' % (release.dist_tag, tag)
+            for tag in (release.candidate_tag, release.testing_tag, release.stable_tag):
                 for build in koji.getLatestBuilds(tag, package=package):
                     builds[tag] = build['nvr']
         return builds
diff --git a/bodhi/mail.py b/bodhi/mail.py
index ae05c7a..cbe7ea8 100644
--- a/bodhi/mail.py
+++ b/bodhi/mail.py
@@ -258,7 +258,7 @@ http://fedoraproject.org/keys
 --------------------------------------------------------------------------------
 """
 
-fedora-epel_errata_template = u"""\
+fedora_epel_errata_template = u"""\
 --------------------------------------------------------------------------------
 Fedora EPEL%(testing)s Update Notification
 %(updateid)s
@@ -296,11 +296,12 @@ maillist_template = u"""\
 """
 
 
-def get_template(update, use_template=fedora_errata_template):
+def get_template(update, use_template='fedora_errata_template'):
     """
     Build the update notice for a given update.
     @param use_template: the template to generate this notice with
     """
+    use_template = globals()[use_template]
     line = unicode('-' * 80) + '\n'
     templates = []
 
diff --git a/bodhi/masher.py b/bodhi/masher.py
index 10c7033..9b1eb0a 100644
--- a/bodhi/masher.py
+++ b/bodhi/masher.py
@@ -285,14 +285,11 @@ class MashTask(Thread):
         for update in self.updates:
             if not pending_nvrs.has_key(update.release.name):
                 pending_nvrs[update.release.name] = [build['nvr'] for build in
-                        self.koji.listTagged('%s-updates-candidate' %
-                                             update.release.dist_tag)]
+                        self.koji.listTagged(update.release.candidate_tag)]
                 testing_nvrs[update.release.name] = [build['nvr'] for build in
-                        self.koji.listTagged('%s-updates-testing' %
-                                             update.release.dist_tag)]
+                        self.koji.listTagged(update.release.testing_tag)]
                 stable_nvrs[update.release.name] = [build['nvr'] for build in
-                        self.koji.listTagged('%s-updates' %
-                                             update.release.dist_tag)]
+                        self.koji.listTagged(update.release.stable_tag)]
 
         for update in self.updates:
             for build in update.builds:
@@ -339,21 +336,21 @@ class MashTask(Thread):
         mash during this push
         """
         for update in self.updates:
-            release = update.release.name.lower()
+            release = update.release
             if self.resume:
-                self.repos.add('%s-updates' % release)
-                self.repos.add('%s-updates-testing' % release)
+                self.repos.add(release.stable_tag)
+                self.repos.add(release.testing_tag)
             elif update.request == 'stable':
-                self.repos.add('%s-updates' % release)
+                self.repos.add(release.stable_tag)
                 if update.status == 'testing':
-                    self.repos.add('%s-updates-testing' % release)
+                    self.repos.add(release.testing_tag)
             elif update.request == 'testing':
-                self.repos.add('%s-updates-testing' % release)
+                self.repos.add(release.testing_tag)
             elif update.request == 'obsolete':
                 if update.status == 'testing':
-                    self.repos.add('%s-updates-testing' % release)
+                    self.repos.add(release.testing_tag)
                 elif update.status == 'stable':
-                    self.repos.add('%s-updates' % release)
+                    self.repos.add(release.stable_tag)
 
     def move_builds(self):
         """
@@ -368,11 +365,11 @@ class MashTask(Thread):
         self.koji.multicall = True
         for update in self.updates:
             if update.request == 'stable':
-                self.tag = update.release.dist_tag + '-updates'
+                self.tag = update.release.stable_tag
             elif update.request == 'testing':
-                self.tag = update.release.dist_tag + '-updates-testing'
+                self.tag = update.release.testing_tag
             elif update.request == 'obsolete':
-                self.tag = update.release.dist_tag + '-updates-candidate'
+                self.tag = update.release.candidate_tag
             current_tag = update.get_build_tag()
             for build in update.builds:
                 if build.inherited:
@@ -659,7 +656,7 @@ class MashTask(Thread):
         prefix = update.release.long_name
         if not self.testing_digest.has_key(prefix):
             self.testing_digest[prefix] = {}
-        for i, subbody in enumerate(mail.get_template(update,use_template=mail.maillist_template)):
+        for i, subbody in enumerate(mail.get_template(update,use_template='maillist_template')):
             self.testing_digest[prefix][update.builds[i].nvr] = subbody[1]
 
     def send_digest_mail(self):
@@ -700,7 +697,7 @@ class MashTask(Thread):
         release = update.release
         self.updates.add(update)
         mashdir = config.get('mashed_dir')
-        repo = "%s-updates" % release.name.lower()
+        repo = release.stable_tag
         master_repomd = config.get('master_repomd')
         repomd = join(mashdir, repo, 'i386', 'repodata', 'repomd.xml')
         if not exists(repomd):
diff --git a/bodhi/model.py b/bodhi/model.py
index 82e3718..701699f 100644
--- a/bodhi/model.py
+++ b/bodhi/model.py
@@ -57,6 +57,26 @@ class Release(SQLObject):
         regex = re.compile('\D+(\d+)$')
         return int(regex.match(self.name).groups()[0])
 
+    @property
+    def candidate_tag(self):
+        if self.name.startswith('EL'):
+            return '%s-testing-candidate' % self.dist_tag
+        else:
+            return '%s-updates-candidate' % self.dist_tag
+
+    @property
+
+    @property
+    def testing_tag(self):
+        return '%s-testing' % self.dist_tag
+
+    @property
+    def stable_tag(self):
+        if self.name.startswith('EL'):
+            return self.dist_tag
+        else:
+            return '%s-updates' % self.dist_tag
+
     def __json__(self):
         return dict(name=self.name, long_name=self.long_name,
                     id_prefix=self.id_prefix, dist_tag=self.dist_tag,
@@ -163,8 +183,8 @@ class PackageBuild(SQLObject):
         # there could potentially be packages that never make their way over
         # -updates, so we don't want to generate ChangeLogs against those.
         nvr = get_nvr(self.nvr)
-        for tag in ['%s-updates', '%s']:
-            tag %= self.updates[0].release.dist_tag
+        release = self.updates[0].release
+        for tag in [release.stable_tag, release.dist_tag]:
             builds = koji_session.getLatestBuilds(tag, None, self.package.name)
             latest = None
 
-- 
1.6.0.6

