incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [7/50] git commit: [#4954] Add command to re-clone a repo from original clone URL
Date Wed, 19 Sep 2012 18:43:27 GMT
[#4954] Add command to re-clone a repo from original clone URL

Signed-off-by: Cory Johns <johnsca@geek.net>


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

Branch: refs/heads/master
Commit: 24c231fd5c6489d7fb17ef02d3817f49e8f3380f
Parents: 110ba68
Author: Cory Johns <johnsca@geek.net>
Authored: Mon Sep 17 20:56:10 2012 +0000
Committer: Cory Johns <johnsca@geek.net>
Committed: Mon Sep 17 20:56:10 2012 +0000

----------------------------------------------------------------------
 Allura/allura/command/reclone_repo.py |   52 ++++++++++++++++++++++++++++
 Allura/setup.py                       |    1 +
 2 files changed, 53 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/24c231fd/Allura/allura/command/reclone_repo.py
----------------------------------------------------------------------
diff --git a/Allura/allura/command/reclone_repo.py b/Allura/allura/command/reclone_repo.py
new file mode 100644
index 0000000..a677f0e
--- /dev/null
+++ b/Allura/allura/command/reclone_repo.py
@@ -0,0 +1,52 @@
+import warnings
+
+from pylons import c
+
+from allura import model as M
+from allura.tasks import repo_tasks
+
+from . import base
+
+
+class RecloneRepoCommand(base.Command):
+    min_args=3
+    max_args=None
+    usage = '<ini file> [-n nbhd] <project_shortname> <mount_point>'
+    summary = 'Reinitialize a repo from the original clone source'
+    parser = base.Command.standard_parser(verbose=True)
+    parser.add_option('-n', '--nbhd', dest='nbhd', type='string', default='p',
+                      help='neighborhood prefix (default: p)')
+
+    def command(self):
+        self._setup()
+        self._load_objects()
+        self._clone_repo()
+
+    def _setup(self):
+        '''Perform basic setup, suppressing superfluous warnings.'''
+        with warnings.catch_warnings():
+            try:
+                from sqlalchemy import exc
+            except ImportError:
+                pass
+            else:
+                warnings.simplefilter("ignore", category=exc.SAWarning)
+            self.basic_setup()
+
+    def _load_objects(self):
+        '''Load objects to be operated on.'''
+        c.user = M.User.query.get(username='sfrobot')
+        nbhd = M.Neighborhood.query.get(url_prefix='/%s/' % self.options.nbhd)
+        assert nbhd, 'Neighborhood with prefix %s not found' % self.options.nbhd
+        c.project = M.Project.query.get(shortname=self.args[1], neighborhood_id=nbhd._id)
+        assert c.project, 'Project with shortname %s not found in neighborhood %s' % (self.args[1],
nbhd.name)
+        c.app = c.project.app_instance(self.args[2])
+        assert c.app, 'Mount point %s not found on project %s' % (self.args[2], c.project.shortname)
+
+
+    def _clone_repo(self):
+        '''Initiate the repo clone.'''
+        source_url = c.app.config.options.get('init_from_url')
+        source_path = c.app.config.options.get('init_from_path')
+        assert source_url or source_path, '%s does not appear to be a cloned repo' % c.app
+        c.app.repo.init_as_clone(source_path, None, source_url)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/24c231fd/Allura/setup.py
----------------------------------------------------------------------
diff --git a/Allura/setup.py b/Allura/setup.py
index c0e9b5f..3837535 100644
--- a/Allura/setup.py
+++ b/Allura/setup.py
@@ -118,6 +118,7 @@ setup(
     update-neighborhood-home-tool = allura.command:UpdateNeighborhoodCommand
     create-trove-categories = allura.command:CreateTroveCategoriesCommand
     set-neighborhood-features = allura.command:SetNeighborhoodFeaturesCommand
+    reclone-repo = allura.command.reclone_repo:RecloneRepoCommand
 
     [easy_widgets.resources]
     ew_resources=allura.config.resources:register_ew_resources


Mime
View raw message