← Back to team overview

ubuntu-bugcontrol team mailing list archive

[Merge] ~pfsmorigo/ubuntu-qa-tools:iso_search into ubuntu-qa-tools:master

 

Paulo Flabiano Smorigo has proposed merging ~pfsmorigo/ubuntu-qa-tools:iso_search into ubuntu-qa-tools:master.

Requested reviews:
  Ubuntu Bug Control (ubuntu-bugcontrol)

For more details, see:
https://code.launchpad.net/~pfsmorigo/ubuntu-qa-tools/+git/ubuntu-qa-tools/+merge/393571
-- 
Your team Ubuntu Bug Control is requested to review the proposed merge of ~pfsmorigo/ubuntu-qa-tools:iso_search into ubuntu-qa-tools:master.
diff --git a/vm-tools/uvt b/vm-tools/uvt
index 0d5d198..5932cd8 100755
--- a/vm-tools/uvt
+++ b/vm-tools/uvt
@@ -2795,14 +2795,15 @@ def locate_release_iso(release, release_num, arch, iso_type, force):
         iso_type = "mini"
 
     # Try and find the latest point release
-    # FIXME: this should list the directory instead of guessing
-    for r in [".7", ".6", ".5", ".4", ".3", ".2", ".1", ""]:
-        if iso_type == "server" and float(release_num) >= 20.04:
-            release_iso = "ubuntu-%s%s-legacy-%s-%s.iso" % (release_num, r, iso_type, arch)
-        else:
-            release_iso = "ubuntu-%s%s-%s-%s.iso" % (release_num, r, iso_type, arch)
-        #print "looking for %s" % release_iso
-        iso_path = os.path.join(uvt_conf['vm_dir_iso'],release_iso)
+    if iso_type == "server" and float(release_num) >= 20.04:
+        match_iso = "ubuntu-{}(|.[0-9])-legacy-{}-{}.iso".format(release_num, iso_type, arch)
+    else:
+        match_iso = "ubuntu-{}(|.[0-9])-{}-{}.iso".format(release_num, iso_type, arch)
+
+    matches = [f for f in os.listdir(uvt_conf['vm_dir_iso']) if re.search(match_iso, f)]
+    if len(matches) > 0:
+        release_iso = sorted(matches)[-1]
+        iso_path = os.path.join(uvt_conf['vm_dir_iso'], release_iso)
         if os.path.exists(iso_path):
             # iso image is there, but we don't have read access
             # this sometimes happens when libvirt mucks with the
@@ -2811,7 +2812,7 @@ def locate_release_iso(release, release_num, arch, iso_type, force):
                 print("Found iso at '%s',\nbut you don't have read permission!\n" % iso_path, file=sys.stderr)
                 print("Please fix permissions on iso file and try again! Aborting.\n", file=sys.stderr)
                 sys.exit(1)
-            return (release_iso, release_num + r)
+            return (release_iso, release_iso.split('-')[1])
 
     # Fall back to daily/alpha/beta style iso naming
     release_iso = "%s-%s-%s.iso" % (release, iso_type, arch)
@@ -2900,12 +2901,16 @@ def find_latest_release(release_num, iso_type):
         print("Could not reach web server! Please download manually.")
         sys.exit(1)
 
-    for r in [".6", ".5", ".4", ".3", ".2", ".1", ""]:
-        attempt = release_num + r
-        search = '<a href="%s/">' % attempt
-        if search in html:
-            print("Found release %s" % attempt)
-            return attempt
+    text = re.compile(r'<[^>]+>').sub('', html).split('\n')
+    matches = []
+    for line in text:
+        if line.startswith(' ' + release_num):
+            matches.append(line[0:].split('/')[0][1:])
+
+    if len(matches) > 0:
+        latest_release = sorted(matches)[-1]
+        print("Found release %s" % latest_release)
+        return latest_release
 
     print("Could not find release to download! Please download manually.")
     sys.exit(1)

Follow ups