incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [6/8] git commit: [#2840] ticket:272 task for code snapshots generation
Date Mon, 11 Mar 2013 23:07:10 GMT
[#2840] ticket:272 task for code snapshots generation


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

Branch: refs/heads/master
Commit: 6ffde84f5d9c072352fac3b1274481b6a55a8910
Parents: 6049825
Author: Yuriy Arhipov <yuriyarhipovua@yandex.ru>
Authored: Mon Feb 18 14:29:49 2013 +0400
Committer: Cory Johns <johnsca@geek.net>
Committed: Mon Mar 11 22:29:45 2013 +0000

----------------------------------------------------------------------
 Allura/allura/controllers/repository.py          |    5 ++++
 Allura/allura/model/repository.py                |   14 +++++++++++
 Allura/allura/tasks/repo_tasks.py                |   12 ++++++++++
 Allura/allura/templates/repo/tree.html           |    4 +++
 Allura/development.ini                           |    1 +
 Allura/test.ini                                  |    1 +
 ForgeGit/forgegit/model/git_repo.py              |    9 +++++++
 ForgeGit/forgegit/tests/model/test_repository.py |    6 +++++
 ForgeSVN/forgesvn/model/svn.py                   |   20 +++++++++++++++++
 ForgeSVN/forgesvn/tests/model/test_repository.py |    5 ++++
 10 files changed, 77 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/6ffde84f/Allura/allura/controllers/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/repository.py b/Allura/allura/controllers/repository.py
index f543c6a..6a38f74 100644
--- a/Allura/allura/controllers/repository.py
+++ b/Allura/allura/controllers/repository.py
@@ -425,6 +425,11 @@ class CommitBrowser(BaseController):
             result.update(self._commit.context())
         return result
 
+    @expose()
+    def tarball(self, **kw):
+        allura.tasks.repo_tasks.tarball.post(revision=self._revision)
+        redirect(redirect(request.referer))
+
     @expose('jinja:allura:templates/repo/log.html')
     @with_trailing_slash
     @validate(dict(page=validators.Int(if_empty=0),

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/6ffde84f/Allura/allura/model/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repository.py b/Allura/allura/model/repository.py
index f293f4e..5653e2b 100644
--- a/Allura/allura/model/repository.py
+++ b/Allura/allura/model/repository.py
@@ -112,6 +112,10 @@ class RepositoryImplementation(object):
         '''Return count of the commits related to path'''
         raise NotImplementedError, 'commits_count'
 
+    def tarball(self, revision):
+        '''Create a tarball for the revision'''
+        raise NotImplementedError, 'tarball'
+
     def last_commit_ids(self, commit, paths):
         '''
         Return a mapping {path: commit_id} of the _id of the last
@@ -225,6 +229,13 @@ class Repository(Artifact, ActivityObject):
     def default_url_path(cls, project, tool):
         return project.url()
 
+    @property
+    def tarball_path(self):
+        return os.path.join(tg.config.get('scm.repos.tarball.root', '/'),
+                            self.tool,
+                            self.project.url()[1:],
+                            self.name)
+
     def __repr__(self): # pragma no cover
         return '<%s %s>' % (
             self.__class__.__name__,
@@ -479,6 +490,9 @@ class Repository(Artifact, ActivityObject):
     def forks(self):
         return self.query.find({'upstream_repo.name': self.url()}).all()
 
+    def tarball(self, revision):
+        self._impl.tarball(revision)
+
 class MergeRequest(VersionedArtifact, ActivityObject):
     statuses=['open', 'merged', 'rejected']
     class __mongometa__:

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/6ffde84f/Allura/allura/tasks/repo_tasks.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tasks/repo_tasks.py b/Allura/allura/tasks/repo_tasks.py
index 355daf7..87d4f72 100644
--- a/Allura/allura/tasks/repo_tasks.py
+++ b/Allura/allura/tasks/repo_tasks.py
@@ -102,3 +102,15 @@ def reclone_repo(*args, **kwargs):
     except Exception, e:
         source_url = source_path or source_url
         g.post_event('repo_clone_task_failed', source_url, traceback.format_exc())
+
+@task
+def tarball(revision=None):
+    log = logging.getLogger(__name__)
+    if revision:
+        repo = c.app.repo
+        try:
+            repo.tarball(revision)
+        except:
+            log.error('Could not create tarball for repository %s:%s revision %s' % (c.project.shortname,
c.app.config.options.mount_point, revision), exc_info=True)
+    else:
+        log.warn('Creation of tarball for %s:%s skipped because revision is not specified'
% (c.project.shortname, c.app.config.options.mount_point))
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/6ffde84f/Allura/allura/templates/repo/tree.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/repo/tree.html b/Allura/allura/templates/repo/tree.html
index 31d7b2b..b3e3094 100644
--- a/Allura/allura/templates/repo/tree.html
+++ b/Allura/allura/templates/repo/tree.html
@@ -12,6 +12,10 @@ Tree <a href="{{commit.url()}}">{{commit.shorthand_id()}}</a>
{{commit_labels(co
 {% endblock %}
 
 {% block actions %}
+<a href="{{commit.url()}}tarball">
+     Tarball
+</a>
+
 <a href="{{commit.url()}}log/?path={{ path }}">
   <b data-icon="{{g.icons.history.char}}" class="ico {{g.icons.history.css}}" title="History">
</b> History
 </a>

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/6ffde84f/Allura/development.ini
----------------------------------------------------------------------
diff --git a/Allura/development.ini b/Allura/development.ini
index ae550ae..fce244c 100644
--- a/Allura/development.ini
+++ b/Allura/development.ini
@@ -120,6 +120,7 @@ scm.new_refresh = true
 gitweb.cgi = /usr/lib/cgi-bin/gitweb.cgi
 
 scm.repos.root = /tmp
+scm.repos.tarball.root = /tmp/tarball
 
 trovecategories.enableediting = true
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/6ffde84f/Allura/test.ini
----------------------------------------------------------------------
diff --git a/Allura/test.ini b/Allura/test.ini
index fa951e2..3e0d18e 100644
--- a/Allura/test.ini
+++ b/Allura/test.ini
@@ -81,6 +81,7 @@ scm.clone.ro.svn = svn checkout $source_url $dest_path
 scm.clone.svn = svn checkout --username=$username $source_url $dest_path
 
 scm.repos.root = /tmp
+scm.repos.tarball.root = /tmp/tarball
 
 #stats.sample_rate = 0
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/6ffde84f/ForgeGit/forgegit/model/git_repo.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/model/git_repo.py b/ForgeGit/forgegit/model/git_repo.py
index 092d24d..097630e 100644
--- a/ForgeGit/forgegit/model/git_repo.py
+++ b/ForgeGit/forgegit/model/git_repo.py
@@ -322,6 +322,15 @@ class GitImplementation(M.RepositoryImplementation):
         tree = self.refresh_tree_info(ci.tree, set())
         return tree._id
 
+    def tarball(self, commit):
+        shortname = self._repo.project.shortname
+        mount_point = self._repo.app.config.options.mount_point
+        if not os.path.exists(self._repo.tarball_path):
+            os.makedirs(self._repo.tarball_path)
+        filename = '%s-%s-%s.tar' % (shortname, mount_point, commit)
+        self._git.archive(open(os.path.join(self._repo.tarball_path, filename), 'w'),
+                          treeish=commit)
+
 class _OpenedGitBlob(object):
     CHUNK_SIZE=4096
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/6ffde84f/ForgeGit/forgegit/tests/model/test_repository.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/tests/model/test_repository.py b/ForgeGit/forgegit/tests/model/test_repository.py
index 223c1af..48c82ab 100644
--- a/ForgeGit/forgegit/tests/model/test_repository.py
+++ b/ForgeGit/forgegit/tests/model/test_repository.py
@@ -238,6 +238,12 @@ class TestGitRepo(unittest.TestCase, RepoImplTestBase):
         self.assertEqual(new_tree.blob_ids, orig_tree.blob_ids)
         self.assertEqual(new_tree.other_ids, orig_tree.other_ids)
 
+    def test_tarball(self):
+        assert_equal(self.repo.tarball_path, '/tmp/tarball/git/p/test/testgit.git')
+        self.repo.tarball('HEAD')
+        assert os.path.isfile("/tmp/tarball/git/p/test/testgit.git/test-src-git-HEAD.tar")
+
+
 class TestGitCommit(unittest.TestCase):
 
     def setUp(self):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/6ffde84f/ForgeSVN/forgesvn/model/svn.py
----------------------------------------------------------------------
diff --git a/ForgeSVN/forgesvn/model/svn.py b/ForgeSVN/forgesvn/model/svn.py
index 0b94028..41753ae 100644
--- a/ForgeSVN/forgesvn/model/svn.py
+++ b/ForgeSVN/forgesvn/model/svn.py
@@ -10,6 +10,8 @@ from hashlib import sha1
 from cStringIO import StringIO
 from datetime import datetime
 import tempfile
+import tarfile
+from shutil import rmtree
 
 import tg
 import pysvn
@@ -608,4 +610,22 @@ class SVNImplementation(M.RepositoryImplementation):
                 entries[path] = self._oid(info.last_changed_rev.number)
         return entries
 
+    def tarball(self, commit):
+        shortname = self._repo.project.shortname
+        mount_point = self._repo.app.config.options.mount_point
+        if not os.path.exists(self._repo.tarball_path):
+            os.makedirs(self._repo.tarball_path)
+        path = os.path.join(self._repo.tarball_path, commit)
+        if os.path.exists(path):
+            rmtree(path)
+        self._svn.export(self._url,
+                         path,
+                         revision=pysvn.Revision(pysvn.opt_revision_kind.number, commit))
+        filename = '%s-%s-%s.tar' % (shortname, mount_point, commit)
+        tar = tarfile.open(os.path.join(self._repo.tarball_path, filename), "w")
+        tar.add(path, arcname=commit)
+        tar.close()
+        rmtree(path)
+
+
 Mapper.compile_all()

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/6ffde84f/ForgeSVN/forgesvn/tests/model/test_repository.py
----------------------------------------------------------------------
diff --git a/ForgeSVN/forgesvn/tests/model/test_repository.py b/ForgeSVN/forgesvn/tests/model/test_repository.py
index 5174c00..0eb7f19 100644
--- a/ForgeSVN/forgesvn/tests/model/test_repository.py
+++ b/ForgeSVN/forgesvn/tests/model/test_repository.py
@@ -265,6 +265,11 @@ class TestSVNRepo(unittest.TestCase, RepoImplTestBase):
         ci = mock.Mock(_id='deadbeef:100')
         self.assertEqual(self.repo.count_revisions(ci), 100)
 
+    def test_tarball(self):
+        assert_equal(self.repo.tarball_path, '/tmp/tarball/svn/p/test/testsvn')
+        self.repo.tarball('1')
+        assert os.path.isfile("/tmp/tarball/svn/p/test/testsvn/test-src-1.tar")
+
 
 class TestSVNRev(unittest.TestCase):
 


Mime
View raw message