mirror of
https://git.FreeBSD.org/ports.git
synced 2024-11-21 00:25:50 +00:00
- Better handling when custom encoding is specified in details
- Use only one request to retreive patchs CR: D400 CR: D401 Submitted by: rakuco
This commit is contained in:
parent
1952e07d57
commit
ffad0a1b50
Notes:
svn2git
2021-03-31 03:12:20 +00:00
svn path=/head/; revision=362667
@ -120,24 +120,29 @@ class BzGetPatch(GetPatch):
|
|||||||
URL_BASE= 'https://bugs.freebsd.org/bugzilla/'
|
URL_BASE= 'https://bugs.freebsd.org/bugzilla/'
|
||||||
URL_SHOW = '%s/show_bug.cgi?id=' % URL_BASE
|
URL_SHOW = '%s/show_bug.cgi?id=' % URL_BASE
|
||||||
REGEX_URL = r'<a href="([^<]+)">Details</a>'
|
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):
|
def __init__(self, pr, category):
|
||||||
GetPatch.__init__(self, pr, category)
|
GetPatch.__init__(self, pr, category)
|
||||||
|
|
||||||
def _extract_patchs_url(self, data):
|
def _get_patch_name(self, url):
|
||||||
pattern = re.compile(self.REGEX_URL)
|
match = re.search(self.REGEX, urllib2.urlopen(url).read())
|
||||||
return re.findall(pattern, data)
|
if match is None:
|
||||||
|
return None
|
||||||
|
return match.group(1)
|
||||||
|
|
||||||
def _extract_patchs_name(self, urls):
|
def _get_patch_urls(self, data):
|
||||||
names = []
|
patch_urls = {}
|
||||||
pattern = re.compile(self.REGEX)
|
for url in re.findall(self.REGEX_URL, data):
|
||||||
for url in urls:
|
url = '%s/%s' % (self.URL_BASE, url)
|
||||||
u = urllib2.urlopen('%s/%s' % (self.URL_BASE, url))
|
file_name = self._get_patch_name(url)
|
||||||
data = u.read()
|
if file_name is None:
|
||||||
names.append(re.findall(pattern, data)[0])
|
self.out("[-] Could not determine the patch file name in %s. "
|
||||||
|
"Skipping." % url)
|
||||||
return names
|
continue
|
||||||
|
download_url = url[:url.find('&')]
|
||||||
|
patch_urls[download_url] = file_name
|
||||||
|
return patch_urls
|
||||||
|
|
||||||
def fetch(self, *largs, **kwargs):
|
def fetch(self, *largs, **kwargs):
|
||||||
category = kwargs['category']
|
category = kwargs['category']
|
||||||
@ -149,19 +154,13 @@ class BzGetPatch(GetPatch):
|
|||||||
self.out("[-] No patch found")
|
self.out("[-] No patch found")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
urls = self._extract_patchs_url(data)
|
patch_urls = self._get_patch_urls(data)
|
||||||
nb_urls = len(urls)
|
if not patch_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:
|
|
||||||
self.out("[-] No patch found")
|
self.out("[-] No patch found")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
for i in range(nb_urls):
|
for url, file_name in patch_urls.iteritems():
|
||||||
self.add_patch(urls[i], names[i])
|
self.add_patch(url, file_name)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user