allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [2/4] git commit: [#7381] update page fetching for hosted urls
Date Thu, 29 May 2014 21:08:10 GMT
[#7381] update page fetching for hosted urls


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

Branch: refs/heads/db/7381
Commit: d99a1c7cae5a123a62e35b0daed00a3f37e28e9a
Parents: 5c6f983
Author: Dave Brondsema <dbrondsema@slashdotmedia.com>
Authored: Thu May 29 19:53:39 2014 +0000
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Thu May 29 19:53:39 2014 +0000

----------------------------------------------------------------------
 .../forgeimporters/google/__init__.py           | 32 +++++++++++++++++---
 .../tests/google/test_extractor.py              |  5 +++
 2 files changed, 33 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/d99a1c7c/ForgeImporters/forgeimporters/google/__init__.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/google/__init__.py b/ForgeImporters/forgeimporters/google/__init__.py
index a7bb1d9..8c9081e 100644
--- a/ForgeImporters/forgeimporters/google/__init__.py
+++ b/ForgeImporters/forgeimporters/google/__init__.py
@@ -154,15 +154,31 @@ class GoogleCodeProjectNameValidator(fev.FancyValidator):
         return project_name
 
 
+def split_project_name(project_name):
+    '''
+    For hosted projects, the project_name includes the hosted domain.  Split, like:
+
+    :param str project_name: "a/eclipselabs.org/p/restclient-tool"
+    :return: ``("/a/eclipselabs.org", "restclient-tool")``
+    '''
+    if project_name.startswith('a/'):
+        hosted_domain_prefix = '/a/' + project_name.split('/')[1]
+        project_name = project_name.split('/')[3]
+    else:
+        hosted_domain_prefix = ''
+        project_name = project_name
+    return hosted_domain_prefix, project_name
+
+
 class GoogleCodeProjectExtractor(ProjectExtractor):
     BASE_URL = 'http://code.google.com'
     RE_REPO_TYPE = re.compile(r'(svn|hg|git)')
 
     PAGE_MAP = {
-        'project_info': BASE_URL + '/p/{project_name}/',
-        'source_browse': BASE_URL + '/p/{project_name}/source/browse/',
-        'issues_csv': BASE_URL + '/p/{project_name}/issues/csv?can=1&colspec=ID&sort=ID&start={start}',
-        'issue': BASE_URL + '/p/{project_name}/issues/detail?id={issue_id}',
+        'project_info': BASE_URL + '{hosted_domain_prefix}/p/{project_name}/',
+        'source_browse': BASE_URL + '{hosted_domain_prefix}/p/{project_name}/source/browse/',
+        'issues_csv': BASE_URL + '{hosted_domain_prefix}/p/{project_name}/issues/csv?can=1&colspec=ID&sort=ID&start={start}',
+        'issue': BASE_URL + '{hosted_domain_prefix}/p/{project_name}/issues/detail?id={issue_id}',
     }
 
     LICENSE_MAP = defaultdict(lambda: 'Other/Proprietary License', {
@@ -180,6 +196,14 @@ class GoogleCodeProjectExtractor(ProjectExtractor):
 
     DEFAULT_ICON = 'http://www.gstatic.com/codesite/ph/images/defaultlogo.png'
 
+    def get_page_url(self, page_name, **kw):
+        # override, to handle hosted domains
+        hosted_domain_prefix, project_name = split_project_name(self.project_name)
+        return self.PAGE_MAP[page_name].format(
+            project_name=urllib.quote(project_name),
+            hosted_domain_prefix=hosted_domain_prefix,
+            **kw)
+
     def check_readable(self):
         resp = requests.head(self.get_page_url('project_info'))
         return resp.status_code == 200

http://git-wip-us.apache.org/repos/asf/allura/blob/d99a1c7c/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 fb82a57..228fa0b 100644
--- a/ForgeImporters/forgeimporters/tests/google/test_extractor.py
+++ b/ForgeImporters/forgeimporters/tests/google/test_extractor.py
@@ -85,6 +85,11 @@ class TestGoogleCodeProjectExtractor(TestCase):
         self.assertEqual(extractor.get_page_url('project_info'),
                          'http://code.google.com/p/my-project/')
 
+    def test_get_page_url_hosted(self):
+        extractor = google.GoogleCodeProjectExtractor('a/eclipselabs.org/p/restclient-tool')
+        self.assertEqual(extractor.get_page_url('project_info'),
+                         'http://code.google.com/a/eclipselabs.org/p/restclient-tool/')
+
     def test_get_short_description(self):
         extractor = google.GoogleCodeProjectExtractor(
             'my-project', 'project_info')


Mime
View raw message