Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 09 Feb 2013 14:34:50 +0100
From:      Christoph Mallon <christoph.mallon@gmx.de>
To:        FreeBSD-gnats-submit@freebsd.org
Cc:        Sofian Brabez <sbz@FreeBSD.org>
Subject:   ports/175984: [PATCH] getpatch: Make retrieving patches from GNATS more robust.
Message-ID:  <E1U4AZu-0005kO-3z@rotluchs.lokal>
Resent-Message-ID: <201302091340.r19De0Jw061155@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         175984
>Category:       ports
>Synopsis:       [PATCH] getpatch: Make retrieving patches from GNATS more robust.
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          update
>Submitter-Id:   current-users
>Arrival-Date:   Sat Feb 09 13:40:00 UTC 2013
>Closed-Date:
>Last-Modified:
>Originator:     Christoph Mallon
>Release:        FreeBSD 9.1-STABLE amd64
>Organization:
>Environment:


	
>Description:
Parse the raw PR, instead of hoping that GNATS got it right.
	
>How-To-Repeat:
	
>Fix:
Please apply the patch.

	

--- 0001-getpatch-Make-retrieving-patches-from-GNATS-more-rob.patch begins here ---
>From 698e00d7154f885cdc9d13a7ee306b04289cdfdd Mon Sep 17 00:00:00 2001
From: Christoph Mallon <christoph.mallon@gmx.de>
Date: Sat, 9 Feb 2013 14:09:37 +0100
Subject: [PATCH] getpatch: Make retrieving patches from GNATS more robust.

Parse the raw PR, instead of hoping that GNATS got it right.
---
 Tools/scripts/getpatch | 42 ++++++++++++++++++++++++++++++++++--------
 1 file changed, 34 insertions(+), 8 deletions(-)

diff --git a/Tools/scripts/getpatch b/Tools/scripts/getpatch
index baf762c..c5844fa 100755
--- a/Tools/scripts/getpatch
+++ b/Tools/scripts/getpatch
@@ -79,7 +79,10 @@ class GetPatch(object):
             url = patch['url']
             p = patch['name']
 
-            data = urllib2.urlopen(url).read()
+            if url:
+                data = urllib2.urlopen(url).read()
+            else:
+                data = patch['data']
 
             if self.output_stdout:
                 sys.stdout.write(data.decode(self.default_locale))
@@ -93,25 +96,47 @@ class GetPatch(object):
 class GnatsGetPatch(GetPatch):
 
     URL_BASE = 'http://www.freebsd.org/cgi'
-    URL = '%s/query-pr.cgi?pr=' % URL_BASE
-    REGEX = r'<b>Download <a href="([^"]*)">([^<]*)</a>'
+    URL = '%s/query-pr.cgi?f=raw&pr=' % URL_BASE
 
     def __init__(self, pr, category):
         GetPatch.__init__(self, pr, category)
 
+    def add_patch(self, name, data):
+        self.patchs.append({'url': None, 'name': name, 'data': data})
+
     def fetch(self, *largs, **kwargs):
         category = kwargs['category']
         target = ("%s/%s" % (category, self.pr), "%s" % self.pr)[category=='']
         self.out("[+] Fetching patch for pr %s" % target)
-        pattern = re.compile(self.REGEX)
         u = urllib2.urlopen(self.URL+'%s' % target)
-        data = u.read()
-        if data == None:
+        content = u.read()
+        if content == None:
             self.out("[-] No patch found")
             sys.exit(1)
 
-        for patchs in re.findall(pattern, str(data)):
-            self.patchs.append({'url': patchs[0], 'name': patchs[1]})
+        data  = ''
+        name  = None
+        end   = None
+        begin = re.compile('^--- (.*) begins here ---$')
+        for line in str(content).splitlines(True):
+            match = re.search(begin, line)
+            if match:
+                if name:
+                    self.out("[-] File '%s' is not terminated" % name)
+                    self.add_patch(name, data)
+                name = match.group(1)
+                end  = re.compile('^--- %s ends here ---$' % re.escape(name))
+            if end:
+                if re.search(end, line):
+                    self.add_patch(name, data)
+                    data = ''
+                    name = None
+                    end  = None
+                else:
+                    data += line
+        if name:
+            self.out("[-] File '%s' is not terminated" % name)
+            self.add_patch(name, data)
 
 class BzGetPatch(GetPatch):
 
-- 
1.8.1.3
--- 0001-getpatch-Make-retrieving-patches-from-GNATS-more-rob.patch ends here ---


>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?E1U4AZu-0005kO-3z>