Skip to contentSkip to conversation

fetch2/wget.py: _check_latest_version_by_dir use group names

PATCH New Aníbal Limón 1 participant 2 messages Mar 24, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 fetch2/wget.py: _check_latest_version_by_dir use group names

From: Aníbal Limón <[email protected]>

Little improvement for reference tokens by names instead of index.

---
 lib/bb/fetch2/wget.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
lib/bb/fetch2/wget.py +4 -4
index 202ed0b..ffae540 100644
@@ -420,10 +420,10 @@ class Wget(FetchMethod):
         version_dir = ['', '', '']
         version = ['', '', '']
 
-        dirver_regex = re.compile("(\D*)((\d+[\.\-_])+(\d+))")
+        dirver_regex = re.compile("(?P<pfx>\D*)(?P<ver>(\d+[\.\-_])+(\d+))")
         s = dirver_regex.search(dirver)
         if s:
-            version_dir[1] = s.group(2)
+            version_dir[1] = s.group('ver')
         else:
             version_dir[1] = dirver
 
@@ -438,9 +438,9 @@ class Wget(FetchMethod):
         for line in soup.find_all('a', href=True):
             s = dirver_regex.search(line['href'].strip("/"))
             if s:
-                version_dir_new = ['', s.group(2), '']
+                version_dir_new = ['', s.group('ver'), '']
                 if self._vercmp(version_dir, version_dir_new) <= 0:
-                    dirver_new = s.group(1) + s.group(2)
+                    dirver_new = s.group('pfx') + s.group('ver')
                     path = ud.path.replace(dirver, dirver_new, True) \
                         .split(package)[0]
                     uri = bb.fetch.encodeurl([ud.type, ud.host, path,
Signature · 1 line
2.1.4
#1 lore raw

PATCH 2/2 fetch2/wget.py: _check_latest_version_by_dir fix prefix detection

From: Aníbal Limón <[email protected]>

When prefix is part of the version directory it need to ensure that only version directory is used so remove previous directories if exists.

Example: pfx = '/dir1/dir2/v' and version = '2.5' the expected result is 'v2.5' instead of '/dir1/dir2/v2.5'.

[YOCTO #8778]

---
 lib/bb/fetch2/wget.py | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
lib/bb/fetch2/wget.py +12 -2
index ffae540..8bc9e93 100644
@@ -438,9 +438,19 @@ class Wget(FetchMethod):
         for line in soup.find_all('a', href=True):
             s = dirver_regex.search(line['href'].strip("/"))
             if s:
-                version_dir_new = ['', s.group('ver'), '']
+                sver = s.group('ver')
+
+                # When prefix is part of the version directory it need to
+                # ensure that only version directory is used so remove previous
+                # directories if exists.
+                #
+                # Example: pfx = '/dir1/dir2/v' and version = '2.5' the expected
+                # result is v2.5.
+                spfx = s.group('pfx').split('/')[-1]
+
+                version_dir_new = ['', sver, '']
                 if self._vercmp(version_dir, version_dir_new) <= 0:
-                    dirver_new = s.group('pfx') + s.group('ver')
+                    dirver_new = spfx + sver
                     path = ud.path.replace(dirver, dirver_new, True) \
                         .split(package)[0]
                     uri = bb.fetch.encodeurl([ud.type, ud.host, path,
Signature · 1 line
2.1.4