From owner-freebsd-ports-bugs@FreeBSD.ORG Sat Feb 9 13:40:00 2013 Return-Path: Delivered-To: freebsd-ports-bugs@smarthost.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 8F0CD2CF for ; Sat, 9 Feb 2013 13:40:00 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) by mx1.freebsd.org (Postfix) with ESMTP id 71D65A8E; Sat, 9 Feb 2013 13:40:00 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.6/8.14.6) with ESMTP id r19De0RI061156; Sat, 9 Feb 2013 13:40:00 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.6/8.14.6/Submit) id r19De0Jw061155; Sat, 9 Feb 2013 13:40:00 GMT (envelope-from gnats) Resent-Date: Sat, 9 Feb 2013 13:40:00 GMT Resent-Message-Id: <201302091340.r19De0Jw061155@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-ports-bugs@FreeBSD.org Resent-Cc: Sofian Brabez Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Christoph Mallon Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id DFD922A2 for ; Sat, 9 Feb 2013 13:35:03 +0000 (UTC) (envelope-from christoph.mallon@gmx.de) Received: from mout.gmx.net (mout.gmx.net [212.227.17.20]) by mx1.freebsd.org (Postfix) with ESMTP id 8F0A5A74 for ; Sat, 9 Feb 2013 13:35:03 +0000 (UTC) Received: from mailout-de.gmx.net ([10.1.76.24]) by mrigmx.server.lan (mrigmx002) with ESMTP (Nemesis) id 0LoKed-1UbZWx2DtZ-00gJ3D for ; Sat, 09 Feb 2013 14:35:02 +0100 Received: (qmail invoked by alias); 09 Feb 2013 13:34:59 -0000 Received: from p5B132F8B.dip.t-dialin.net (EHLO rotluchs.lokal) [91.19.47.139] by mail.gmx.net (mp024) with SMTP; 09 Feb 2013 14:34:59 +0100 Received: from tron by rotluchs.lokal with local (Exim 4.80.1 (FreeBSD)) (envelope-from ) id 1U4AZu-0005kO-3z; Sat, 09 Feb 2013 14:34:50 +0100 Message-Id: Date: Sat, 09 Feb 2013 14:34:50 +0100 From: Christoph Mallon To: FreeBSD-gnats-submit@freebsd.org X-Send-Pr-Version: 3.114 X-GNATS-Notify: Sofian Brabez Subject: ports/175984: [PATCH] getpatch: Make retrieving patches from GNATS more robust. Cc: Sofian Brabez X-BeenThere: freebsd-ports-bugs@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: Christoph Mallon List-Id: Ports bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 09 Feb 2013 13:40:00 -0000 >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 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'Download ([^<]*)' + 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: