From 411be57bf43022de3edec7a24e26993c3e977402 Mon Sep 17 00:00:00 2001 From: Daniel Farrell Date: Wed, 11 Oct 2017 14:59:44 -0400 Subject: [PATCH] Simplify most-recent-snap-URL given ODL version fn Change-Id: I3d1d82615f89077bd854f8955abdd9a83539da3d Signed-off-by: Daniel Farrell --- packages/build.py | 3 +- packages/lib.py | 78 ++++++++++++++++------------------------------- 2 files changed, 28 insertions(+), 53 deletions(-) diff --git a/packages/build.py b/packages/build.py index a4fd587..1539eea 100755 --- a/packages/build.py +++ b/packages/build.py @@ -111,8 +111,7 @@ if __name__ == "__main__": # If doing a latest-snap build, find latest build tarball URL for given # major version and add to build definition. Else, add URL directly. if hasattr(args, "major"): - # FIXME: In the process of removing minor_version, pass None for now - build.update({"download_url": lib.get_snap_url(args.major, None)}) + build.update({"download_url": lib.get_snap_url(args.major)}) else: build.update({"download_url": args.download_url}) diff --git a/packages/lib.py b/packages/lib.py index fce85ef..b51cfd7 100644 --- a/packages/lib.py +++ b/packages/lib.py @@ -162,59 +162,35 @@ def extract_snapshot_version(url, version): return version -def get_snap_url(version_major, version_minor=None): - """Fetches tarball url for snapshot releases using version information +def get_snap_url(version_major): + """Get the most recent snapshot build of the given ODL major version + + :arg str version_major: ODL major version to get latest snapshot of + :return str snapshot_url: URL to latest snapshot tarball of ODL version - :arg str version_major: Major version for snapshot build - :arg str version_minor: Minor version for snapshot build(optional) - :return arg snapshot_url: URL of the snapshot release """ - parent_dir = "https://nexus.opendaylight.org/content/repositories/" \ - "opendaylight.snapshot/org/opendaylight/integration/{}/" \ - .format(get_distro_name_prefix(version_major)) - - # If the minor verison is given, get the sub-directory directly - # else, find the latest sub-directory - sub_dir = '' - snapshot_dir = '' - if version_minor: - sub_dir = '0.' + version_major + '.' + version_minor + '-SNAPSHOT/' - snapshot_dir = parent_dir + sub_dir - else: - subdir_url = urlopen(parent_dir) - content = subdir_url.read().decode('utf-8') - all_dirs = BeautifulSoup(content, 'html.parser') - - # Loops through all the sub-directories present and stores the - # latest sub directory as sub-directories are already sorted - # in early to late order. - for tag in all_dirs.find_all('a', href=True): - # Checks if the sub-directory name is of the form - # '0..-SNAPSHOT'. - dir = re.search(r'\/(\d)\.(\d)\.(\d).(.*)\/', tag['href']) - # If the major version matches the argument provided - # store the minor version, else ignore. - if dir: - if dir.group(2) == version_major: - snapshot_dir = tag['href'] - version_minor = dir.group(3) - - try: - req = requests.get(snapshot_dir) - req.raise_for_status() - except HTTPError: - print "Could not find the snapshot directory" - else: - urlpath = urlopen(snapshot_dir) - content = urlpath.read().decode('utf-8') - html_content = BeautifulSoup(content, 'html.parser') - # Loops through all the files present in `snapshot_dir` - # and stores the url of latest tarball because files are - # already sorted in early to late order. - for tag in html_content.find_all('a', href=True): - if tag['href'].endswith('tar.gz'): - snapshot_url = tag['href'] - return snapshot_url + # Dir that contains all shapshot build dirs, varies based on Karaf 3/4 + parent_dir_url = "https://nexus.opendaylight.org/content/repositories/" \ + "opendaylight.snapshot/org/opendaylight/integration/{}/" \ + .format(get_distro_name_prefix(version_major)) + + # Get HTML of dir that contains all shapshot dirs + parent_dir_html = urlopen(parent_dir_url).read().decode('utf-8') + + # Get most recent minor version of the given major version + version_minor = max(re.findall(r'>\d\.{}\.(\d)-SNAPSHOT\/'.format(version_major), + parent_dir_html)) + + # Dir that contains snapshot builds for the given major version + snapshot_dir_url = parent_dir_url + "0.{}.{}-SNAPSHOT/".format( + version_major, + version_minor) + + # Get HTML of dir that contains snapshot builds for given major version + snapshot_dir_html = urlopen(snapshot_dir_url).read().decode('utf-8') + + # Find most recent URL to tarball, ie most recent snapshot build + return re.findall(r'href="(.*\.tar\.gz)"', snapshot_dir_html)[-1] def get_sysd_commit(): -- 2.36.6