Openembedded Bitbake Development
 help / color / mirror / Atom feed
From: "Aníbal Limón" <anibal.limon@linux.intel.com>
To: bitbake-devel@lists.openembedded.org
Subject: [PATCH 2/7] fetch2: wget latest_versionstring _check_latest_version improvments
Date: Fri, 13 Feb 2015 15:58:09 -0600	[thread overview]
Message-ID: <1423864694-24940-3-git-send-email-anibal.limon@linux.intel.com> (raw)
In-Reply-To: <1423864694-24940-1-git-send-email-anibal.limon@linux.intel.com>

In order to reduce code duplication now compile package_regex in
_init_regexes instead of make this decision at _check_latest_version,

Signed-off-by: Aníbal Limón <anibal.limon@linux.intel.com>
---
 lib/bb/fetch2/wget.py | 51 +++++++++++++++++++++++++--------------------------
 1 file changed, 25 insertions(+), 26 deletions(-)

diff --git a/lib/bb/fetch2/wget.py b/lib/bb/fetch2/wget.py
index 04e2b33..96d895d 100644
--- a/lib/bb/fetch2/wget.py
+++ b/lib/bb/fetch2/wget.py
@@ -243,26 +243,21 @@ class Wget(FetchMethod):
     def _check_latest_version(self, url, package, package_regex, current_version, ud, d):
         """
         Return the latest version of a package inside a given directory path
-        If error or no version, return None
+        If error or no version, return ""
         """
         valid = 0
-        version = ('', '', '')
+        version = ['', '', '']
 
         bb.debug(3, "VersionURL: %s" % (url))
         soup = BeautifulSoup(self._fetch_index(url, ud, d))
         if not soup:
             bb.debug(3, "*** %s NO SOUP" % (url))
-            return None
+            return ""
 
-        pn_regex = d.getVar('REGEX', True)
-        if pn_regex:
-            pn_regex = re.compile(pn_regex)
-            package_regex = pn_regex
-            bb.debug(3, "pn_regex = '%s'" % (pn_regex.pattern))
-            
         for line in soup.find_all('a', href=True):
-            newver = None
-            bb.debug(3, "line = '%s'" % (line['href']))
+            bb.debug(3, "line = '%s'" % (str(line)))
+            bb.debug(3, "line['href'] = '%s'" % (line['href']))
+
             newver = self._parse_path(package_regex, line['href'])
             if not newver:
                 newver = self._parse_path(package_regex, str(line))
@@ -279,12 +274,12 @@ class Wget(FetchMethod):
         bb.debug(3, "*** %s -> UpstreamVersion = %s (CurrentVersion = %s)" %
                 (package, version[1] or "N/A", current_version[1]))
 
-        if valid and version:
+        if valid:
             return re.sub('_', '.', version[1])
 
-        return None
+        return ""
 
-    def _init_regexes(self, package):
+    def _init_regexes(self, package, ud, d):
         """
         Match as many patterns as possible such as:
                 gnome-common-2.20.0.tar.gz (most common format)
@@ -318,7 +313,7 @@ class Wget(FetchMethod):
         psuffix_regex = "(tar\.gz|tgz|tar\.bz2|zip|xz|rpm|bz2|orig\.tar\.gz|tar\.xz|src\.tar\.gz|src\.tgz|svnr\d+\.tar\.bz2|stable\.tar\.gz|src\.rpm)"
 
         # match name, version and archive type of a package
-        self.package_regex_comp = re.compile("(?P<name>%s?)\.?v?(?P<pver>%s)(?P<arch>%s)?[\.\-](?P<type>%s$)"
+        package_regex_comp = re.compile("(?P<name>%s?)\.?v?(?P<pver>%s)(?P<arch>%s)?[\.\-](?P<type>%s$)"
                                                     % (pn_regex, pver_regex, parch_regex, psuffix_regex))
         self.suffix_regex_comp = re.compile(psuffix_regex)
 
@@ -326,13 +321,18 @@ class Wget(FetchMethod):
         # "5.7" in http://download.gnome.org/sources/${PN}/5.7/${PN}-${PV}.tar.gz
         self.dirver_regex_comp = re.compile("(?P<dirver>[^/]*(\d+\.)*\d+([\-_]r\d+)*)/")
 
-        # make custom regex for search in uri's
-        package_custom_regex_comp = None
-        version = self._parse_path(self.package_regex_comp, package)
-        if version:
-            package_custom_regex_comp = re.compile(
-                "(?P<name>%s)(?P<pver>%s)(?P<arch>%s)?[\.\-](?P<type>%s)$" %
-                (re.escape(version[0]), pver_regex, parch_regex, psuffix_regex))
+        # compile regex, can be specific by package or generic regex
+        pn_regex = d.getVar('REGEX', True)
+        if pn_regex:
+            package_custom_regex_comp = re.compile(pn_regex)
+        else:
+            version = self._parse_path(package_regex_comp, package)
+            if version:
+                package_custom_regex_comp = re.compile(
+                    "(?P<name>%s)(?P<pver>%s)(?P<arch>%s)?[\.\-](?P<type>%s)$" %
+                    (re.escape(version[0]), pver_regex, parch_regex, psuffix_regex))
+            else:
+                package_custom_regex_comp = package_regex_comp
 
         return package_custom_regex_comp
 
@@ -347,7 +347,7 @@ class Wget(FetchMethod):
         newpath = regex_uri or ud.path
         pupver = ""
 
-        package_custom_regex_comp = self._init_regexes(package)
+        package_regex = self._init_regexes(package, ud, d)
 
         current_version = ('', d.getVar('PV', True), '')
 
@@ -371,6 +371,5 @@ class Wget(FetchMethod):
         else:
             newuri = newpath
 
-        return self._check_latest_version(newuri, package,
-                        package_custom_regex_comp or package_regex_comp,
-                        current_version, ud, d) or ""
+        return self._check_latest_version(newuri, package, package_regex,
+                        current_version, ud, d)
-- 
1.9.1



  parent reply	other threads:[~2015-02-13 21:58 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-13 21:58 [PATCH 0/7] fetch2: wget latest_versionstring improvments Aníbal Limón
2015-02-13 21:58 ` [PATCH 1/7] fetch2: wget latest_versionstring improve _parse_path Aníbal Limón
2015-02-13 21:58 ` Aníbal Limón [this message]
2015-02-13 21:58 ` [PATCH 3/7] fetch2: wget add _check_latest_version_by_dir Aníbal Limón
2015-02-13 21:58 ` [PATCH 4/7] fetch2: wget latest_versionstring improvments in get version by dir Aníbal Limón
2015-02-13 21:58 ` [PATCH 5/7] fetch2: wget _modelate_version improvments Aníbal Limón
2015-02-13 21:58 ` [PATCH 6/7] fetch2: wget remove scape of - in regexes don't needed Aníbal Limón
2015-02-13 21:58 ` [PATCH 7/7] tests/fetch.py: latest_versionstring add set of PN Aníbal Limón

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1423864694-24940-3-git-send-email-anibal.limon@linux.intel.com \
    --to=anibal.limon@linux.intel.com \
    --cc=bitbake-devel@lists.openembedded.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox