You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2012/09/19 20:43:27 UTC

[3/50] git commit: [#3027] ticket:165 fixed errors

[#3027] ticket:165 fixed errors


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

Branch: refs/heads/master
Commit: c4ef0bc5967bd9b2eadb020b10d47788bca4c9e5
Parents: 6d09948
Author: Yuriy Arhipov <yu...@yandex.ru>
Authored: Fri Sep 14 13:04:17 2012 +0400
Committer: Cory Johns <jo...@geek.net>
Committed: Tue Sep 18 22:07:05 2012 +0000

----------------------------------------------------------------------
 Allura/allura/lib/utils.py                         |   10 +++++++++
 Allura/allura/lib/validators.py                    |   11 ----------
 ForgeSVN/forgesvn/model/svn.py                     |    3 ++
 ForgeSVN/forgesvn/svn_main.py                      |   16 +++++++-------
 ForgeSVN/forgesvn/templates/svn/checkout_url.html  |    2 +-
 .../forgesvn/tests/functional/test_controllers.py  |   15 ++++++++-----
 6 files changed, 31 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c4ef0bc5/Allura/allura/lib/utils.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/utils.py b/Allura/allura/lib/utils.py
index 57d6878..9d70415 100644
--- a/Allura/allura/lib/utils.py
+++ b/Allura/allura/lib/utils.py
@@ -25,6 +25,7 @@ from pygments.formatters import HtmlFormatter
 
 from ew import jinja2_ew as ew
 from ming.utils import LazyProperty
+import pysvn
 
 def permanent_redirect(url):
     try:
@@ -428,3 +429,12 @@ def generate_code_stats(blob):
     spaces = re.compile(r'^\s*$')
     stats['data_line_count'] = sum([1 for l in lines if not spaces.match(l)])
     return stats
+
+def check_svn_repo(path):
+    svn = pysvn.Client()
+    try:
+        svn.info2(path)
+        return True
+    except pysvn.ClientError, e:
+        return False
+

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c4ef0bc5/Allura/allura/lib/validators.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/validators.py b/Allura/allura/lib/validators.py
index de3d517..5bab308 100644
--- a/Allura/allura/lib/validators.py
+++ b/Allura/allura/lib/validators.py
@@ -3,7 +3,6 @@ from bson import ObjectId
 import formencode as fe
 from formencode import validators as fev
 from . import helpers as h
-import pysvn
 
 class Ming(fev.FancyValidator):
 
@@ -62,13 +61,3 @@ class JsonValidator(fev.FancyValidator):
         except ValueError, e:
             raise fe.Invalid('Invalid JSON: ' + str(e), value, state)
         return value
-
-
-class CheckoutUrlValidator(fev.FancyValidator):
-    def _to_python(self, value, state):
-        svn = pysvn.Client()
-        try:
-            svn.info2(value)
-        except pysvn.ClientError, e:
-            raise  fe.Invalid(str(e), value, state)
-        return value

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c4ef0bc5/ForgeSVN/forgesvn/model/svn.py
----------------------------------------------------------------------
diff --git a/ForgeSVN/forgesvn/model/svn.py b/ForgeSVN/forgesvn/model/svn.py
index 0802480..4930c55 100644
--- a/ForgeSVN/forgesvn/model/svn.py
+++ b/ForgeSVN/forgesvn/model/svn.py
@@ -25,6 +25,7 @@ from allura import model as M
 from allura.lib import helpers as h
 from allura.model.repository import GitLikeTree
 from allura.model.auth import User
+from allura.lib.utils import check_svn_repo
 
 log = logging.getLogger(__name__)
 
@@ -161,6 +162,8 @@ class SVNImplementation(M.RepositoryImplementation):
         check_call(['svnsync', 'init', self._url, source_url])
         check_call(['svnsync', '--non-interactive', 'sync', self._url])
         log.info('... %r cloned', self._repo)
+        if not check_svn_repo(self._repo.fs_path+self._repo.name):
+            c.app.config.options['checkout_url'] = ""
         self._repo.refresh(notify=False)
         self._setup_special_files()
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c4ef0bc5/ForgeSVN/forgesvn/svn_main.py
----------------------------------------------------------------------
diff --git a/ForgeSVN/forgesvn/svn_main.py b/ForgeSVN/forgesvn/svn_main.py
index ec8b899..c06dc6e 100644
--- a/ForgeSVN/forgesvn/svn_main.py
+++ b/ForgeSVN/forgesvn/svn_main.py
@@ -1,7 +1,6 @@
 #-*- python -*-
 import logging
 from pylons import c, request
-import pylons
 
 # Non-stdlib imports
 from ming.utils import LazyProperty
@@ -18,7 +17,7 @@ from allura.lib.repository import RepositoryApp, RepoAdminController
 from allura.app import SitemapEntry, ConfigOption
 from allura.lib import helpers as h
 from allura import model as M
-from allura.lib import validators as V
+from allura.lib.utils import check_svn_repo
 
 # Local imports
 from . import model as SM
@@ -99,14 +98,15 @@ class SVNRepoAdminController(RepoAdminController):
     @without_trailing_slash
     @expose()
     @require_post()
-    @validate(dict(checkout_url=V.CheckoutUrlValidator()))
     def set_checkout_url(self, **post_data):
-        if not pylons.c.form_errors:
-            url = post_data['checkout_url'].replace(
-                self.app.repo.clone_url('ro', self.app), "")
-            self.app.config.options['checkout_url'] = url
+        if check_svn_repo("file://%s%s/%s" %
+                          (self.app.repo.fs_path,
+                           self.app.repo.name,
+                           post_data['checkout_url'])):
+            self.app.config.options['checkout_url'] = post_data['checkout_url']
+            flash("Checkout URL successfully changed")
         else:
-            flash(pylons.c.form_errors["checkout_url"], "error")
+            flash("%s isn't a valid svn repository" % post_data['checkout_url'], "error")
 
 
 class SVNImportController(BaseController):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c4ef0bc5/ForgeSVN/forgesvn/templates/svn/checkout_url.html
----------------------------------------------------------------------
diff --git a/ForgeSVN/forgesvn/templates/svn/checkout_url.html b/ForgeSVN/forgesvn/templates/svn/checkout_url.html
index 2283a5d..089e39e 100644
--- a/ForgeSVN/forgesvn/templates/svn/checkout_url.html
+++ b/ForgeSVN/forgesvn/templates/svn/checkout_url.html
@@ -26,7 +26,7 @@
     function save_checkout_url() {
         var cval = $.cookie('_session_id');
         $.post('{{c.project.url()}}admin/{{app.config.options.mount_point}}/set_checkout_url', {
-            checkout_url: "{{app.repo.clone_url('ro', app)}}" + $('#checkout_url').val(),
+            checkout_url: $('#checkout_url').val(),
             _session_id:cval
         },
         function () {

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c4ef0bc5/ForgeSVN/forgesvn/tests/functional/test_controllers.py
----------------------------------------------------------------------
diff --git a/ForgeSVN/forgesvn/tests/functional/test_controllers.py b/ForgeSVN/forgesvn/tests/functional/test_controllers.py
index c0dc4b1..dd88d5e 100644
--- a/ForgeSVN/forgesvn/tests/functional/test_controllers.py
+++ b/ForgeSVN/forgesvn/tests/functional/test_controllers.py
@@ -8,7 +8,6 @@ from pylons import c
 from ming.orm import ThreadLocalORMSession
 
 from allura.lib import helpers as h
-from allura.lib import validators as V
 from allura.tests import decorators as td
 from alluratest.controller import TestController
 
@@ -110,11 +109,15 @@ class TestRootController(SVNTestController):
         self.app.post('/p/test/admin/src/set_checkout_url',
                       {"checkout_url": "badurl"})
         r = self.app.get('/p/test/admin/src/checkout_url')
-        assert "trunk" in r
-
-    def test_validator(self):
-        v_svn = V.CheckoutUrlValidator()
-        v_svn.to_python("file:///" + c.app.repo.fs_path + c.app.repo.name)
+        assert 'value="trunk"' in r
+        self.app.post('/p/test/admin/src/set_checkout_url',
+                      {"checkout_url": ""})
+        r = self.app.get('/p/test/admin/src/checkout_url')
+        assert 'value="trunk"' not in r
+        self.app.post('/p/test/admin/src/set_checkout_url',
+                      {"checkout_url": "a"})
+        r = self.app.get('/p/test/admin/src/checkout_url')
+        assert 'value="a"' in r
 
 
 class TestImportController(SVNTestController):