incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [18/22] git commit: [#6464] Fixed handling of attachment links in GC Tracker importer
Date Tue, 20 Aug 2013 17:45:48 GMT
[#6464] Fixed handling of attachment links in GC Tracker importer

Signed-off-by: Cory Johns <cjohns@slashdotmedia.com>


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/511e57d7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/511e57d7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/511e57d7

Branch: refs/heads/cj/6464
Commit: 511e57d73061c9dd35c7b3f503a54e3a9c6ff793
Parents: a013355
Author: Cory Johns <cjohns@slashdotmedia.com>
Authored: Fri Aug 16 22:04:00 2013 +0000
Committer: Cory Johns <cjohns@slashdotmedia.com>
Committed: Tue Aug 20 17:34:14 2013 +0000

----------------------------------------------------------------------
 ForgeImporters/forgeimporters/google/__init__.py    | 16 ++++++++--------
 .../forgeimporters/tests/google/test_extractor.py   |  6 +++---
 2 files changed, 11 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/511e57d7/ForgeImporters/forgeimporters/google/__init__.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/google/__init__.py b/ForgeImporters/forgeimporters/google/__init__.py
index 22be7c2..fbf3eb0 100644
--- a/ForgeImporters/forgeimporters/google/__init__.py
+++ b/ForgeImporters/forgeimporters/google/__init__.py
@@ -17,7 +17,7 @@
 
 import re
 import urllib
-from urlparse import urlparse, urljoin
+from urlparse import urlparse, urljoin, parse_qs
 from collections import defaultdict
 from contextlib import closing
 try:
@@ -123,7 +123,7 @@ class GoogleCodeProjectExtractor(ProjectExtractor):
 
     def get_icon(self, project):
         page = self.get_page('project_info')
-        icon_url = urljoin(self.url, page.find(itemprop='image').attrMap['src'])
+        icon_url = urljoin(self.url, page.find(itemprop='image').get('src'))
         if icon_url == self.DEFAULT_ICON:
             return
         icon_name = urllib.unquote(urlparse(icon_url).path).split('/')[-1]
@@ -222,7 +222,7 @@ class GoogleCodeProjectExtractor(ProjectExtractor):
     def get_issue_attachments(self):
         attachments = self.page.find(id='hc0').find('div', 'attachments')
         if attachments:
-            return map(Attachment, attachments.findAll('tr'))
+            return [Attachment(a.parent) for a in attachments.findAll('a', text='Download')]
         else:
             return []
 
@@ -233,8 +233,8 @@ class GoogleCodeProjectExtractor(ProjectExtractor):
 class UserLink(object):
     def __init__(self, tag):
         self.name = tag.string.strip()
-        if 'href' in tag.attrMap:
-            self.url = urljoin(GoogleCodeProjectExtractor.BASE_URL, tag.attrMap['href'])
+        if tag.get('href'):
+            self.url = urljoin(GoogleCodeProjectExtractor.BASE_URL, tag.get('href'))
         else:
             self.url = None
 
@@ -264,7 +264,7 @@ class Comment(object):
     def _get_attachments(self, tag):
         attachments = tag.find('div', 'attachments')
         if attachments:
-            self.attachments = map(Attachment, attachments.findAll('tr'))
+            self.attachments = [Attachment(a.parent) for a in attachments.findAll('a', text='Download')]
         else:
             self.attachments = []
 
@@ -288,8 +288,8 @@ class Comment(object):
 
 class Attachment(object):
     def __init__(self, tag):
-        self.filename = _as_text(tag).strip().split()[0]
-        self.url = urljoin(GoogleCodeProjectExtractor.BASE_URL, tag.a.get('href'))
+        self.url = urljoin(GoogleCodeProjectExtractor.BASE_URL, tag.get('href'))
+        self.filename = parse_qs(urlparse(self.url).query)['name'][0]
         self.type = None
 
     @property

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/511e57d7/ForgeImporters/forgeimporters/tests/google/test_extractor.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/tests/google/test_extractor.py b/ForgeImporters/forgeimporters/tests/google/test_extractor.py
index 4157c98..e208e8d 100644
--- a/ForgeImporters/forgeimporters/tests/google/test_extractor.py
+++ b/ForgeImporters/forgeimporters/tests/google/test_extractor.py
@@ -76,7 +76,7 @@ class TestGoogleCodeProjectExtractor(TestCase):
     def test_get_icon(self, M, StringIO):
         self.urlopen.return_value.info.return_value = {'content-type': 'image/png'}
         extractor = google.GoogleCodeProjectExtractor('my-project', 'project_info')
-        extractor.page.find.return_value.attrMap = {'src': 'http://example.com/foo/bar/my-logo.png'}
+        extractor.page.find.return_value.get.return_value = 'http://example.com/foo/bar/my-logo.png'
         self.urlopen.reset_mock()
 
         extractor.get_icon(self.project)
@@ -260,13 +260,13 @@ class TestUserLink(TestCase):
     def test_plain(self):
         tag = mock.Mock()
         tag.string.strip.return_value = 'name'
-        tag.attrMap = {}
+        tag.get.return_value = None
         link = google.UserLink(tag)
         self.assertEqual(str(link), 'name')
 
     def test_linked(self):
         tag = mock.Mock()
         tag.string.strip.return_value = 'name'
-        tag.attrMap = {'href': '/p/project'}
+        tag.get.return_value = '/p/project'
         link = google.UserLink(tag)
         self.assertEqual(str(link), '[name](http://code.google.com/p/project)')


Mime
View raw message