Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 23 Jul 2014 12:14:32 +0000 (UTC)
From:      Sofian Brabez <sbz@FreeBSD.org>
To:        ports-committers@freebsd.org, svn-ports-all@freebsd.org, svn-ports-head@freebsd.org
Subject:   svn commit: r362667 - head/Tools/scripts
Message-ID:  <201407231214.s6NCEW1o026065@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: sbz
Date: Wed Jul 23 12:14:32 2014
New Revision: 362667
URL: http://svnweb.freebsd.org/changeset/ports/362667
QAT: https://qat.redports.org/buildarchive/r362667/

Log:
  - Better handling when custom encoding is specified in details
  - Use only one request to retreive patchs
  
  CR:	D400
  CR:	D401
  Submitted by:	rakuco

Modified:
  head/Tools/scripts/getpatch

Modified: head/Tools/scripts/getpatch
==============================================================================
--- head/Tools/scripts/getpatch	Wed Jul 23 12:13:02 2014	(r362666)
+++ head/Tools/scripts/getpatch	Wed Jul 23 12:14:32 2014	(r362667)
@@ -120,24 +120,29 @@ class BzGetPatch(GetPatch):
     URL_BASE= 'https://bugs.freebsd.org/bugzilla/'
     URL_SHOW = '%s/show_bug.cgi?id=' % URL_BASE
     REGEX_URL = r'<a href="([^<]+)">Details</a>'
-    REGEX = r'<div class="details">([^ ]+) \(text/plain\)'
+    REGEX = r'<div class="details">([^ ]+) \(text/plain(?:; charset=[-\w]+)?\)'
 
     def __init__(self, pr, category):
         GetPatch.__init__(self, pr, category)
 
-    def _extract_patchs_url(self, data):
-        pattern = re.compile(self.REGEX_URL)
-        return re.findall(pattern, data)
-
-    def _extract_patchs_name(self, urls):
-        names = []
-        pattern = re.compile(self.REGEX)
-        for url in urls:
-            u = urllib2.urlopen('%s/%s' % (self.URL_BASE, url))
-            data = u.read()
-            names.append(re.findall(pattern, data)[0])
-
-        return names
+    def _get_patch_name(self, url):
+        match = re.search(self.REGEX, urllib2.urlopen(url).read())
+        if match is None:
+            return None
+        return match.group(1)
+
+    def _get_patch_urls(self, data):
+        patch_urls = {}
+        for url in re.findall(self.REGEX_URL, data):
+            url = '%s/%s' % (self.URL_BASE, url)
+            file_name = self._get_patch_name(url)
+            if file_name is None:
+                self.out("[-] Could not determine the patch file name in %s. "
+                         "Skipping." % url)
+                continue
+            download_url = url[:url.find('&')]
+            patch_urls[download_url] = file_name
+        return patch_urls
 
     def fetch(self, *largs, **kwargs):
         category = kwargs['category']
@@ -149,19 +154,13 @@ class BzGetPatch(GetPatch):
             self.out("[-] No patch found")
             sys.exit(1)
 
-        urls = self._extract_patchs_url(data)
-        nb_urls = len(urls)
-        names = self._extract_patchs_name(urls)
-        nb_names = len(names)
-
-        urls = ['%s/%s' % (self.URL_BASE, u[:u.find('&')]) for u in urls]
-
-        if nb_names == 0 or nb_urls == 0 or nb_names != nb_urls:
+        patch_urls = self._get_patch_urls(data)
+        if not patch_urls:
             self.out("[-] No patch found")
             sys.exit(1)
 
-        for i in range(nb_urls):
-            self.add_patch(urls[i], names[i])
+        for url, file_name in patch_urls.iteritems():
+            self.add_patch(url, file_name)
 
 def main():
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201407231214.s6NCEW1o026065>