allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [32/50] git commit: [#6759] Allow full project URL for GC import
Date Tue, 22 Oct 2013 21:50:42 GMT
[#6759] Allow full project URL for GC import

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/7ee8200e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/7ee8200e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/7ee8200e

Branch: refs/heads/cj/6422
Commit: 7ee8200e707efa574b1221c8be28b93a199755c3
Parents: 0e8aa5e
Author: Cory Johns <cjohns@slashdotmedia.com>
Authored: Wed Oct 16 19:50:21 2013 +0000
Committer: Cory Johns <cjohns@slashdotmedia.com>
Committed: Wed Oct 16 19:56:39 2013 +0000

----------------------------------------------------------------------
 .../forgeimporters/google/__init__.py           | 20 +++++++++++++
 ForgeImporters/forgeimporters/google/code.py    |  3 +-
 ForgeImporters/forgeimporters/google/project.py | 11 +++----
 .../google/templates/project.html               | 30 ++++++++++++++++++--
 ForgeImporters/forgeimporters/google/tracker.py |  3 +-
 5 files changed, 55 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/7ee8200e/ForgeImporters/forgeimporters/google/__init__.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/google/__init__.py b/ForgeImporters/forgeimporters/google/__init__.py
index 2f51aa0..6231cdb 100644
--- a/ForgeImporters/forgeimporters/google/__init__.py
+++ b/ForgeImporters/forgeimporters/google/__init__.py
@@ -22,8 +22,11 @@ from urlparse import urlparse, urljoin, parse_qs
 from collections import defaultdict
 from contextlib import closing
 import logging
+import os
+import re
 
 from BeautifulSoup import BeautifulSoup
+from formencode import validators as fev
 
 from allura.lib import helpers as h
 from allura import model as M
@@ -62,6 +65,23 @@ def csv_parser(page):
     return [line.strip('",\n') for line in lines]
 
 
+class GoogleCodeProjectNameValidator(fev.FancyValidator):
+    not_empty = True
+    messages={
+            'invalid': 'Please enter a project URL, or a project name containing only letters,
numbers, and dashes.',
+        }
+
+    def _to_python(self, value, state=None):
+        url = urlparse(value.strip())
+        if url.netloc.endswith('.googlecode.com'):
+            project_name = url.netloc.split('.')[0]
+        else:
+            project_name = os.path.basename(url.path.strip('/'))
+        if not re.match(r'^[a-z0-9][a-z0-9-]{,61}$', project_name):
+            raise fev.Invalid(self.message('invalid'))
+        return project_name
+
+
 class GoogleCodeProjectExtractor(ProjectExtractor):
     BASE_URL = 'http://code.google.com'
     RE_REPO_TYPE = re.compile(r'(svn|hg|git)')

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/7ee8200e/ForgeImporters/forgeimporters/google/code.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/google/code.py b/ForgeImporters/forgeimporters/google/code.py
index d4f90eb..ff97447 100644
--- a/ForgeImporters/forgeimporters/google/code.py
+++ b/ForgeImporters/forgeimporters/google/code.py
@@ -42,6 +42,7 @@ from forgeimporters.base import (
         ToolImporter,
         )
 from forgeimporters.google import GoogleCodeProjectExtractor
+from forgeimporters.google import GoogleCodeProjectNameValidator
 
 REPO_APPS = {}
 TARGET_APPS = []
@@ -85,7 +86,7 @@ def get_repo_class(type_):
 
 
 class GoogleRepoImportForm(fe.schema.Schema):
-    gc_project_name = fev.UnicodeString(not_empty=True)
+    gc_project_name = GoogleCodeProjectNameValidator()
     mount_point = fev.UnicodeString()
     mount_label = fev.UnicodeString()
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/7ee8200e/ForgeImporters/forgeimporters/google/project.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/google/project.py b/ForgeImporters/forgeimporters/google/project.py
index e69ac9e..4bd6181 100644
--- a/ForgeImporters/forgeimporters/google/project.py
+++ b/ForgeImporters/forgeimporters/google/project.py
@@ -24,19 +24,16 @@ from tg.decorators import with_trailing_slash
 
 from allura.lib.decorators import require_post
 
-from .. import base
-from . import tasks
+from forgeimporters import base
+from forgeimporters.google import tasks
+from forgeimporters.google import GoogleCodeProjectNameValidator
 
 
 log = logging.getLogger(__name__)
 
 
 class GoogleCodeProjectForm(base.ProjectImportForm):
-    project_name = fev.Regex(r'^[a-z0-9][a-z0-9-]{,61}$',
-            not_empty=True,
-            messages={
-                'invalid': 'Please use only letters, numbers, and dashes.',
-            })
+    project_name = GoogleCodeProjectNameValidator()
 
 
 class GoogleCodeProjectImporter(base.ProjectImporter):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/7ee8200e/ForgeImporters/forgeimporters/google/templates/project.html
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/google/templates/project.html b/ForgeImporters/forgeimporters/google/templates/project.html
index 353c056..7617622 100644
--- a/ForgeImporters/forgeimporters/google/templates/project.html
+++ b/ForgeImporters/forgeimporters/google/templates/project.html
@@ -18,9 +18,33 @@
 -#}
 {% extends 'forgeimporters:templates/project_base.html' %}
 
+{% block extra_js %}
+    {{super()}}
+    <script type="text/javascript">
+        function suggest_name() {  // overrides base suggest_names
+            var $project_shortname = $('#project_shortname');
+            if (!manual) {
+                var name_or_url = $('#project_name').val().replace(/\s/g, '').toLowerCase();
+                name_or_url = name_or_url.replace(/\/$/, '');  // strip any trailing slash
+                var a = $('<a>', {href: name_or_url})[0];  // leverage DOM to parse
URL
+                var project_name;
+                var old_style = a.hostname.match(/^(.*)\.googlecode\.com$/);
+                if (old_style) {
+                    project_name = old_style[1];
+                } else {
+                    var parts = a.pathname.split('/');
+                    project_name = parts.pop();
+                }
+                $project_shortname.val(project_name);
+            }
+            $project_shortname.trigger('change');
+        }
+    </script>
+{% endblock %}
+
 {% block project_fields %}
-    <div class="grid-6">
-        <label>Google Project Name</label>
+    <div class="grid-7">
+        <label>Google Project Name or URL</label>
     </div>
     <div class="grid-10">
         <input id="project_name" name="project_name" value="{{c.form_values['project_name']}}"
autofocus/>
@@ -29,7 +53,7 @@
         </div>
     </div>
 
-    <div class="grid-6" style="clear:left">
+    <div class="grid-7" style="clear:left">
         <label>{{config.site_name}} URL Name</label>
     </div>
     <div class="grid-10">

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/7ee8200e/ForgeImporters/forgeimporters/google/tracker.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/google/tracker.py b/ForgeImporters/forgeimporters/google/tracker.py
index 1481772..29bde5f 100644
--- a/ForgeImporters/forgeimporters/google/tracker.py
+++ b/ForgeImporters/forgeimporters/google/tracker.py
@@ -44,6 +44,7 @@ from allura import model as M
 from forgetracker.tracker_main import ForgeTrackerApp
 from forgetracker import model as TM
 from forgeimporters.google import GoogleCodeProjectExtractor
+from forgeimporters.google import GoogleCodeProjectNameValidator
 from forgeimporters.base import (
         ToolImporter,
         ToolImportForm,
@@ -51,7 +52,7 @@ from forgeimporters.base import (
 
 
 class GoogleCodeTrackerImportForm(ToolImportForm):
-    gc_project_name = fev.UnicodeString(not_empty=True)
+    gc_project_name = GoogleCodeProjectNameValidator()
 
 
 class GoogleCodeTrackerImportController(BaseController):


Mime
View raw message