def testGITHUBTags(self): p = Package("cnucnu_test", "GITHUB-TAGS", "test_url", Repository()) p._html = """ "name": "0.1.2" """ self.assertEqual(p.upstream_versions, ["0.1.2"]) p._html = """ "name": "v0.1.2" """ self.assertEqual(p.upstream_versions, ["0.1.2"])
def testUrlUpdate(self): p = Package("name", "regex", "url", Repository()) p._upstream_versions = [0, 1] p._latest_upstream = 1 p._rpm_diff = 1 p.url = "new url" self.assertEqual(p.url, "new url") self.assertEqual(p._upstream_versions, None) self.assertEqual(p._latest_upstream, None) self.assertEqual(p._rpm_diff, None)
def _get_version(self, pkg_name, branch): ver = {} args = {"pkg_name": pkg_name, "branch": branch} try: repo = Repository() p = Package(pkg_name, None, None, repo) p.url = self.url_base % args p.regex = self.regex % args #print (p.name, p.upstream_versions, p.latest_upstream) p.upstream_versions except Exception as e: ver['error'] = str(e) ver['error'] += ' - Bad regex or URL?' return ver nvr = parse_nvr(p.latest_upstream, pkg_name) ver.update(nvr) return ver
def testUpstreamVersions(self): """ Test finding upstream versions """ # default matching p = Package("cnucnu_test", "DEFAULT", "test_url", Repository()) p._html = "cnucnu_test-1.23.tar.gz" self.assertEqual(p.upstream_versions, ["1.23"]) # multiple groups p = Package("cnucnu_test", "cnucnu_test-([1-9]+\.[1-9]+\.[1-9]+)-p([0-9]+)\.tar\.gz", "test_url", Repository()) p._html = "cnucnu_test-1.2.3-p4.tar.gz" self.assertEqual(p.upstream_versions, ["1.2.3.4"]) # empty group p = Package( "cnucnu_test", "cnucnu_test-([1-9]+\.[1-9]+\.[1-9]+)(-p([0-9]+))?\.tar\.gz", "test_url", Repository()) p._html = "cnucnu_test-1.2.3.tar.gz" self.assertEqual(p.upstream_versions, ["1.2.3"])
self.url_base = options['url_base'] def _get_version(self, pkg_name, branch): ver = {} args = {"pkg_name": pkg_name, "branch": branch} try: repo = Repository() p = Package(pkg_name, None, None, repo) p.url = self.url_base % args p.regex = self.regex % args #print (p.name, p.upstream_versions, p.latest_upstream) p.upstream_versions except Exception as e: ver['error'] = str(e) ver['error'] += ' - Bad regex or URL?' return ver nvr = parse_nvr(p.latest_upstream, pkg_name) ver.update(nvr) return ver if __name__ == "__main__": repo = Repository() p = Package("ovirt-node", None, None, repo) p.url = "http://plain.resources.ovirt.org/pub/ovirt-node-base-stable/rpm/el6/noarch/" p.regex = r"(%s-[\d.]+-[\d.]+)\..*" % p.name print (p.name, p.upstream_versions, p.latest_upstream) f = CnucnuFetcher() print (f._get_version(p.name, p.url + "/$(branch)"))