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/12/07 23:26:36 UTC
[49/49] git commit: [#5187] ticket:208 Admin interface for
reclone-repo
[#5187] ticket:208 Admin interface for reclone-repo
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/50cc9893
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/50cc9893
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/50cc9893
Branch: refs/heads/db/4803
Commit: 50cc9893b55ba22e1cae452ae5ecc76873257d77
Parents: 1f96f38
Author: Yuriy Arhipov <yu...@yandex.ru>
Authored: Tue Nov 13 18:13:06 2012 +0400
Committer: Cory Johns <jo...@geek.net>
Committed: Tue Nov 27 17:38:56 2012 +0000
----------------------------------------------------------------------
Allura/allura/controllers/site_admin.py | 39 +++++++++++++++
Allura/allura/tasks/repo_tasks.py | 18 +++++++
Allura/allura/templates/site_admin.html | 2 +
.../allura/templates/site_admin_reclone_repo.html | 22 ++++++++
Allura/allura/tests/functional/test_site_admin.py | 14 +++++
ForgeGit/forgegit/tests/test_tasks.py | 14 +++++
6 files changed, 109 insertions(+), 0 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/50cc9893/Allura/allura/controllers/site_admin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/site_admin.py b/Allura/allura/controllers/site_admin.py
index eb5f606..8bb4f0d 100644
--- a/Allura/allura/controllers/site_admin.py
+++ b/Allura/allura/controllers/site_admin.py
@@ -14,6 +14,7 @@ from allura.lib.security import require_access
from allura.lib.widgets import form_fields as ffw
from allura import model as M
from allura.command.show_models import dfs, build_model_inheritance_graph
+import allura
from urlparse import urlparse
@@ -191,3 +192,41 @@ class SiteAdminController(object):
'pagenum': pagenum,
'count': count
}
+
+ @expose('jinja:allura:templates/site_admin_reclone_repo.html')
+ @validate(dict(prefix=validators.NotEmpty(),
+ shortname=validators.NotEmpty(),
+ mount_point=validators.NotEmpty()))
+ def reclone_repo(self, prefix=None, shortname=None, mount_point=None, **data):
+ if request.method == 'POST':
+ if c.form_errors:
+ error_msg = 'Error: '
+ for msg in list(c.form_errors):
+ names = {'prefix': 'Neighborhood prefix', 'shortname': 'Project shortname', 'mount_point': 'Repository mount point'}
+ error_msg += '%s: %s ' % (names[msg], c.form_errors[msg])
+ flash(error_msg, 'error')
+ return dict(prefix=prefix, shortname=shortname, mount_point=mount_point)
+ nbhd = M.Neighborhood.query.get(url_prefix='/%s/' % prefix)
+ if not nbhd:
+ flash('Neighborhood with prefix %s not found' % prefix, 'error')
+ return dict(prefix=prefix, shortname=shortname, mount_point=mount_point)
+ c.project = M.Project.query.get(shortname=shortname, neighborhood_id=nbhd._id)
+ if not c.project:
+ flash('Project with shortname %s not found in neighborhood %s' % (shortname, nbhd.name), 'error')
+ return dict(prefix=prefix, shortname=shortname, mount_point=mount_point)
+ c.app = c.project.app_instance(mount_point)
+ if not c.app:
+ flash('Mount point %s not found on project %s' % (mount_point, c.project.shortname), 'error')
+ return dict(prefix=prefix, shortname=shortname, mount_point=mount_point)
+ source_url = c.app.config.options.get('init_from_url')
+ source_path = c.app.config.options.get('init_from_path')
+ if not (source_url or source_path):
+ flash('%s does not appear to be a cloned repo' % c.app, 'error')
+ return dict(prefix=prefix, shortname=shortname, mount_point=mount_point)
+ allura.tasks.repo_tasks.reclone_repo.post(prefix=prefix, shortname=shortname, mount_point=mount_point)
+ flash('Repository is being recloned')
+ else:
+ prefix = 'p'
+ shortname = ''
+ mount_point = ''
+ return dict(prefix=prefix, shortname=shortname, mount_point=mount_point)
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/50cc9893/Allura/allura/tasks/repo_tasks.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tasks/repo_tasks.py b/Allura/allura/tasks/repo_tasks.py
index cc074d8..9a6820f 100644
--- a/Allura/allura/tasks/repo_tasks.py
+++ b/Allura/allura/tasks/repo_tasks.py
@@ -84,3 +84,21 @@ def uninstall(**kwargs):
def nop():
log = logging.getLogger(__name__)
log.info('nop')
+
+@task
+def reclone_repo(*args, **kwargs):
+ from allura import model as M
+ try:
+ nbhd = M.Neighborhood.query.get(url_prefix='/%s/' % kwargs['prefix'])
+ c.project = M.Project.query.get(shortname=kwargs['shortname'], neighborhood_id=nbhd._id)
+ c.app = c.project.app_instance(kwargs['mount_point'])
+ source_url = c.app.config.options.get('init_from_url')
+ source_path = c.app.config.options.get('init_from_path')
+ c.app.repo.init_as_clone(source_path, None, source_url)
+ M.Notification.post_user(
+ c.user, c.app.repo, 'created',
+ text='Repository %s/%s created' % (
+ c.project.shortname, c.app.config.options.mount_point))
+ except Exception, e:
+ source_url = source_path or source_url
+ g.post_event('repo_clone_task_failed', source_url, traceback.format_exc())
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/50cc9893/Allura/allura/templates/site_admin.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/site_admin.html b/Allura/allura/templates/site_admin.html
index 04a2da4..25ccc18 100644
--- a/Allura/allura/templates/site_admin.html
+++ b/Allura/allura/templates/site_admin.html
@@ -20,6 +20,8 @@
<li class="{{page=='api_tickets' and 'active' or ''}}"><a href="api_tickets"><b data-icon="{{g.icons['admin'].char}}" class="ico {{g.icons['admin'].css}}"></b>API Tickets</a></li>
<li class="{{page=='add_subscribers' and 'active' or ''}}"><a href="add_subscribers"><b data-icon="{{g.icons['admin'].char}}" class="ico {{g.icons['admin'].css}}"></b>Add Subscribers</a></li>
<li class="{{page=='new_projects' and 'active' or ''}}"><a href="new_projects"><b data-icon="{{g.icons['admin'].char}}" class="ico {{g.icons['admin'].css}}"></b>New Projects</a></li>
+ <li class="{{page=='reclone_repo' and 'active' or ''}}"><a href="reclone_repo"><b data-icon="{{g.icons['admin'].char}}" class="ico {{g.icons['admin'].css}}"></b>Reclone repo</a></li>
+
</ul>
</div>
{% endblock %}
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/50cc9893/Allura/allura/templates/site_admin_reclone_repo.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/site_admin_reclone_repo.html b/Allura/allura/templates/site_admin_reclone_repo.html
new file mode 100644
index 0000000..ef2dd54
--- /dev/null
+++ b/Allura/allura/templates/site_admin_reclone_repo.html
@@ -0,0 +1,22 @@
+{% set page="reclone_repo" %}
+{% extends 'allura:templates/site_admin.html' %}
+
+{% block content %}
+<h1>Reclone repository</h1>
+<form name="add_subscriber" method="POST">
+ <table>
+ <tr>
+ <td>Neighborhood prefix:</td> <td><input name="prefix" type="text" value="{{prefix}}"></td>
+ </tr>
+ <tr>
+ <td> Project shortname:</td> <td><input name="shortname" type="text" value="{{shortname}}"></td>
+ </tr>
+ <tr>
+ <td> Repository mount point:</td> <td><input name="mount_point" type="text" value="{{mount_point}}"></td>
+ </tr>
+ <tr>
+ <td><input type="submit" value="Reclone"></td>
+ </tr>
+ </table>
+</form>
+{% endblock %}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/50cc9893/Allura/allura/tests/functional/test_site_admin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_site_admin.py b/Allura/allura/tests/functional/test_site_admin.py
index c944707..6f1a3f1 100644
--- a/Allura/allura/tests/functional/test_site_admin.py
+++ b/Allura/allura/tests/functional/test_site_admin.py
@@ -1,6 +1,7 @@
import os, allura
from allura.tests import TestController
+from nose.tools import assert_equal
class TestSiteAdmin(TestController):
@@ -60,3 +61,16 @@ class TestSiteAdmin(TestController):
assert headers[6].contents[0] == 'Deleted?'
assert headers[7].contents[0] == 'Homepage'
assert headers[8].contents[0] == 'Admins'
+
+ def test_reclone_repo_access(self):
+ r = self.app.get('/nf/admin/reclone_repo', extra_environ=dict(
+ username='*anonymous'), status=302).follow()
+ assert 'Login' in r
+
+ def test_reclone_repo(self):
+ r = self.app.get('/nf/admin/reclone_repo')
+ assert 'Reclone repository' in r
+
+ def test_reclone_repo_default_value(self):
+ r = self.app.get('/nf/admin/reclone_repo')
+ assert 'value="p"' in r
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/50cc9893/ForgeGit/forgegit/tests/test_tasks.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/tests/test_tasks.py b/ForgeGit/forgegit/tests/test_tasks.py
index c8e4909..291fb0f 100644
--- a/ForgeGit/forgegit/tests/test_tasks.py
+++ b/ForgeGit/forgegit/tests/test_tasks.py
@@ -1,10 +1,13 @@
import unittest
+import mock
from ming.orm import ThreadLocalORMSession
+from pylons import c
from alluratest.controller import setup_basic_test, setup_global_objects
from allura.lib import helpers as h
from allura.tasks import repo_tasks
+from allura import model as M
from forgegit.tests import with_git
class TestGitTasks(unittest.TestCase):
@@ -25,3 +28,14 @@ class TestGitTasks(unittest.TestCase):
def test_refresh_commit(self):
repo_tasks.refresh()
+
+ @with_git
+ def test_reclone(self):
+ ns = M.Notification.query.find().count()
+ with mock.patch.object(c.app.repo, 'init_as_clone') as f:
+ c.app.config.options['init_from_path'] = 'test_path'
+ c.app.config.options['init_from_url'] = 'test_url'
+ repo_tasks.reclone_repo(prefix='p', shortname='test', mount_point='src-git')
+ M.main_orm_session.flush()
+ f.assert_called_with('test_path', None, 'test_url')
+ assert ns + 1 == M.Notification.query.find().count()