From e721c83e7b8744dae54878ab50ca495b2ff1f251 Mon Sep 17 00:00:00 2001 From: Tim Flink Date: May 25 2016 06:18:58 +0000 Subject: make lookup of previous build more generic --- diff --git a/libtaskotron/directives/koji_directive.py b/libtaskotron/directives/koji_directive.py index be8d1b7..ea0f1f7 100644 --- a/libtaskotron/directives/koji_directive.py +++ b/libtaskotron/directives/koji_directive.py @@ -207,15 +207,17 @@ class KojiDirective(BaseDirective): "The koji directive requires 'koji_build' for the 'download_latest_stable' " "action. Detected arguments: %s" % detected_args) - name = rpm_utils.rpmformat(params['koji_build'], 'n') - disttag = rpm_utils.get_dist_tag(params['koji_build']) - # we need to do 'fc22' -> 'f22' conversion - tag = disttag.replace('c', '') - - # first we need to check updates tag and if that fails, the latest - # stable nvr is in the base repo - tags = ['%s-updates' % tag, tag] - latest_stable_nvr = self.koji.latest_by_tag(tags, name) + #name = rpm_utils.rpmformat(params['koji_build'], 'n') + #disttag = rpm_utils.get_dist_tag(params['koji_build']) + ## we need to do 'fc22' -> 'f22' conversion + #tag = disttag.replace('c', '') + + ## first we need to check updates tag and if that fails, the latest + ## stable nvr is in the base repo + #tags = ['%s-updates' % tag, tag] + #latest_stable_nvr = self.koji.latest_by_tag(tags, name) + + latest_stable_nvr = self.koji.get_previous_build(params['koji_build']) output_data['downloaded_rpms'] = self.koji.get_nvr_rpms( latest_stable_nvr, self.target_dir, arch_exclude=self.arch_exclude, diff --git a/libtaskotron/ext/fedora/koji_utils.py b/libtaskotron/ext/fedora/koji_utils.py index 3f7c54e..2bd447c 100644 --- a/libtaskotron/ext/fedora/koji_utils.py +++ b/libtaskotron/ext/fedora/koji_utils.py @@ -268,6 +268,43 @@ class KojiClient(object): return rpms + def get_previous_build(self, nvr): + '''The idea here is to find the previous build using a few assumptions + which I hope are valid. + + 1. there is a parent tag + 2. the latest build in that parent tag is "the last build" + + so we find the tag of input build, look for the parent tag of that build + and get the latest build in that tag for the same package. + + This appears to work but has not been reviewed or hevily tested''' + + + build_info = self.session.getBuild(nvr) + build_tags = self.session.listTags(nvr) + # assuming that if there are multiple tags, they have the same parent + + tagname = build_tags[0]['name'] + buildnvr = None + while buildnvr is None: + parent_tags = self.session.getInheritanceData(tagname) + + if len(parent_tags) == 0: + raise Exception("there were no parent tags!") + + parent_tag = parent_tags[0]['name'] + + history = self.session.queryHistory(None, package=build_info['name'], tag=parent_tag) + + # assuming these are sorted in reverse chronological order + if len(history['tag_listing']) > 0: + buildnvr = history['tag_listing'][0] + continue + tagname = parent_tag + + return "{}-{}-{}".format(buildnvr['name'], buildnvr['version'], buildnvr['release']) + def getNEVR(build): '''Extract RPM version identifier in NEVR format from Koji build object