incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [2/3] git commit: [#5963] ticket:305 Code snapshot status check changes
Date Mon, 01 Apr 2013 14:53:02 GMT
[#5963] ticket:305 Code snapshot status check changes


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

Branch: refs/heads/master
Commit: 5105ac3318739d1f3b5664204918aa6ba94013ea
Parents: 9110fed
Author: Yuriy Arhipov <yuriyarhipovua@yandex.ru>
Authored: Fri Mar 22 13:49:08 2013 +0400
Committer: Cory Johns <cjohns@slashdotmedia.com>
Committed: Fri Mar 29 18:18:41 2013 +0000

----------------------------------------------------------------------
 Allura/allura/model/repository.py                  |   28 +++++++-------
 Allura/allura/tasks/repo_tasks.py                  |    3 --
 Allura/allura/templates/repo/tarball.html          |    9 ++++-
 Allura/allura/tests/test_tasks.py                  |    6 ---
 ForgeGit/forgegit/model/git_repo.py                |   13 ++++---
 .../forgegit/tests/functional/test_controllers.py  |    7 ----
 ForgeGit/forgegit/tests/model/test_repository.py   |   19 ++++++++++
 ForgeSVN/forgesvn/model/svn.py                     |   10 +++---
 8 files changed, 52 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/5105ac33/Allura/allura/model/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repository.py b/Allura/allura/model/repository.py
index d6f843d..aed4363 100644
--- a/Allura/allura/model/repository.py
+++ b/Allura/allura/model/repository.py
@@ -208,7 +208,6 @@ class Repository(Artifact, ActivityObject):
     branches = FieldProperty([dict(name=str,object_id=str, count=int)])
     repo_tags = FieldProperty([dict(name=str,object_id=str, count=int)])
     upstream_repo = FieldProperty(dict(name=str,url=str))
-    tarball_status = FieldProperty([dict(revision=str, status=str)])
 
     def __init__(self, **kw):
         if 'name' in kw and 'tool' in kw:
@@ -240,10 +239,14 @@ class Repository(Artifact, ActivityObject):
                             self.project.shortname,
                             self.name)
 
-    def tarball_url(self, revision):
+    def tarball_filename(self, revision):
         shortname = c.app.repo.project.shortname.replace('/', '-')
         mount_point = c.app.repo.app.config.options.mount_point
-        filename = '%s-%s-%s.tar.gz' % (shortname, mount_point, revision)
+        filename = '%s-%s-%s' % (shortname, mount_point, revision)
+        return filename
+
+    def tarball_url(self, revision):
+        filename = '%s%s' % (self.tarball_filename(revision), '.tar.gz')
         r = os.path.join(self.tool,
                          self.project.shortname[:1],
                          self.project.shortname[:2],
@@ -253,17 +256,14 @@ class Repository(Artifact, ActivityObject):
         return urljoin(tg.config.get('scm.repos.tarball.url_prefix', '/'), r)
 
     def get_tarball_status(self, revision):
-        tarballs = dict((t.revision, t.status) for t in self.tarball_status)
-        return tarballs.get(revision)
-
-    def set_tarball_status(self, revision, status):
-        for tarball in self.tarball_status:
-            if tarball['revision'] == revision:
-                tarball['status'] = status
-                session(self).flush(self)
-                return
-        self.tarball_status.append(dict(revision=revision, status=status))
-        session(self).flush(self)
+        pathname = os.path.join(self.tarball_path, self.tarball_filename(revision))
+        filename = '%s%s' % (pathname, '.tar.gz')
+        tmpfilename = '%s%s' % (pathname, '.tmp')
+
+        if os.path.isfile(filename):
+            return 'ready'
+        elif os.path.isfile(tmpfilename) or os.path.isdir(pathname):
+            return 'busy'
 
     def __repr__(self): # pragma no cover
         return '<%s %s>' % (

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/5105ac33/Allura/allura/tasks/repo_tasks.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tasks/repo_tasks.py b/Allura/allura/tasks/repo_tasks.py
index 4eff18d..03ce1f2 100644
--- a/Allura/allura/tasks/repo_tasks.py
+++ b/Allura/allura/tasks/repo_tasks.py
@@ -108,12 +108,9 @@ def tarball(revision=None):
     log = logging.getLogger(__name__)
     if revision:
         repo = c.app.repo
-        repo.set_tarball_status(revision, 'busy')
         try:
             repo.tarball(revision)
-            repo.set_tarball_status(revision, 'ready')
         except:
-            repo.set_tarball_status(revision, None)
             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))

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/5105ac33/Allura/allura/templates/repo/tarball.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/repo/tarball.html b/Allura/allura/templates/repo/tarball.html
index c312d8b..c5e071d 100644
--- a/Allura/allura/templates/repo/tarball.html
+++ b/Allura/allura/templates/repo/tarball.html
@@ -34,20 +34,25 @@ Commit <a href="{{commit.url()}}">{{commit.shorthand_id()}}</a>
{{commit_labels(
             left: 10 // Left position relative to parent in px
         };
         var spinner = new Spinner(opts).spin($('#snapshot_status')[0]);
+        var delay = 5000
         // Check tarball status every 5 seconds
         function check_status() {
             $.get('{{commit.url()}}tarball_status', function(data) {
                 if (data.status === 'ready') {
-                    window.clearInterval(status_checker);
                     spinner.stop();
                     $('#snapshot_status h2').toggle();
                     {% if 'no-redirect' not in request.params %}
                         window.location.href = '{{c.app.repo.tarball_url(revision)}}';
                     {% endif %}
+                } else {
+                    if (delay < 600000){
+                        delay = delay * 2
+                    }
+                    window.setTimeout(check_status, delay);
                 }
             });
         }
-        var status_checker = window.setInterval(check_status, 5000);
+        window.setTimeout(check_status, delay);
     {% endif %}
 });
 </script>

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/5105ac33/Allura/allura/tests/test_tasks.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_tasks.py b/Allura/allura/tests/test_tasks.py
index 9e16bfb..74a09d0 100644
--- a/Allura/allura/tests/test_tasks.py
+++ b/Allura/allura/tests/test_tasks.py
@@ -38,12 +38,6 @@ class TestRepoTasks(unittest.TestCase):
         assert_equal(post_event.call_args[0][2], None)
         # ignore args[3] which is a traceback string
 
-    @mock.patch('allura.tasks.repo_tasks.c.app.repo.set_tarball_status')
-    def test_repo_tarball(self,st):
-        repo_tasks.tarball('HEAD')
-        calls = [mock.call('HEAD', 'busy'), mock.call('HEAD', 'ready')]
-        st.assert_has_calls(calls, any_order=True)
-
 
 class TestEventTasks(unittest.TestCase):
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/5105ac33/ForgeGit/forgegit/model/git_repo.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/model/git_repo.py b/ForgeGit/forgegit/model/git_repo.py
index c660d69..27fc8e4 100644
--- a/ForgeGit/forgegit/model/git_repo.py
+++ b/ForgeGit/forgegit/model/git_repo.py
@@ -324,14 +324,15 @@ class GitImplementation(M.RepositoryImplementation):
         return tree._id
 
     def tarball(self, commit):
-        shortname = self._repo.project.shortname.replace('/', '-')
-        mount_point = self._repo.app.config.options.mount_point
         if not os.path.exists(self._repo.tarball_path):
             os.makedirs(self._repo.tarball_path)
-        archive_name = '%s-%s-%s' % (shortname, mount_point, commit)
-        filename = os.path.join(self._repo.tarball_path, archive_name + '.tar.gz')
-        with gzip.open(filename, 'w') as fp:
-            self._git.archive(fp, format='tar', treeish=commit, prefix=archive_name+'/')
+        archive_name = self._repo.tarball_filename(commit)
+        filename = os.path.join(self._repo.tarball_path, '%s%s' % (archive_name, '.tar.gz'))
+        tmpfilename = os.path.join(self._repo.tarball_path, '%s%s' % (archive_name, '.tmp'))
+        with gzip.open(tmpfilename, 'w') as fp:
+            self._git.archive(fp, format='tar', treeish=commit, prefix=archive_name + '/')
+        os.rename(tmpfilename, filename)
+
 
 class _OpenedGitBlob(object):
     CHUNK_SIZE=4096

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/5105ac33/ForgeGit/forgegit/tests/functional/test_controllers.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/tests/functional/test_controllers.py b/ForgeGit/forgegit/tests/functional/test_controllers.py
index 84b0133..1c8e0df 100644
--- a/ForgeGit/forgegit/tests/functional/test_controllers.py
+++ b/ForgeGit/forgegit/tests/functional/test_controllers.py
@@ -290,13 +290,6 @@ class TestRootController(_TestCase):
         r = self.app.get(ci + 'tarball_status')
         assert '{"status": "ready"}' in r
 
-    def test_tarball_status(self):
-        assert_equal(c.app.repo.get_tarball_status('1e146e67985dcd71c74de79613719bef7bddca4a'),
None)
-        c.app.repo.set_tarball_status('1e146e67985dcd71c74de79613719bef7bddca4a', 'ready')
-        c.app.repo.set_tarball_status('df30427c488aeab84b2352bdf88a3b19223f9d7a', 'busy')
-        assert_equal(c.app.repo.get_tarball_status('1e146e67985dcd71c74de79613719bef7bddca4a'),
'ready')
-        assert_equal(c.app.repo.get_tarball_status('df30427c488aeab84b2352bdf88a3b19223f9d7a'),
'busy')
-
 
 class TestRestController(_TestCase):
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/5105ac33/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 6258251..59416c8 100644
--- a/ForgeGit/forgegit/tests/model/test_repository.py
+++ b/ForgeGit/forgegit/tests/model/test_repository.py
@@ -240,6 +240,8 @@ class TestGitRepo(unittest.TestCase, RepoImplTestBase):
         self.assertEqual(new_tree.other_ids, orig_tree.other_ids)
 
     def test_tarball(self):
+        if os.path.isfile("/tmp/tarball/git/t/te/test/testgit.git/test-src-git-HEAD.tar.gz"):
+            os.remove("/tmp/tarball/git/t/te/test/testgit.git/test-src-git-HEAD.tar.gz")
         assert_equal(self.repo.tarball_path, '/tmp/tarball/git/t/te/test/testgit.git')
         assert_equal(self.repo.tarball_url('HEAD'), 'file:///git/t/te/test/testgit.git/test-src-git-HEAD.tar.gz')
         self.repo.tarball('HEAD')
@@ -260,6 +262,23 @@ class TestGitRepo(unittest.TestCase, RepoImplTestBase):
                     'summary': u'Change README'},
                 'name': u'README'}])
 
+    def test_tarball_status(self):
+        if os.path.isfile("/tmp/tarball/git/t/te/test/testgit.git/test-src-git-HEAD.tar.gz"):
+            os.remove("/tmp/tarball/git/t/te/test/testgit.git/test-src-git-HEAD.tar.gz")
+        if os.path.isfile("/tmp/tarball/git/t/te/test/testgit.git/test-src-git-HEAD.tmp"):
+            os.remove("/tmp/tarball/git/t/te/test/testgit.git/test-src-git-HEAD.tmp")
+        if os.path.isdir("/tmp/tarball/git/t/te/test/testgit.git/test-src-git-HEAD/"):
+            os.removedirs("/tmp/tarball/git/t/te/test/testgit.git/test-src-git-HEAD/")
+        self.repo.tarball('HEAD')
+        assert_equal(self.repo.get_tarball_status('HEAD'), 'ready')
+        os.rename("/tmp/tarball/git/t/te/test/testgit.git/test-src-git-HEAD.tar.gz",
+                  "/tmp/tarball/git/t/te/test/testgit.git/test-src-git-HEAD.tmp")
+        assert_equal(self.repo.get_tarball_status('HEAD'), 'busy')
+        os.remove("/tmp/tarball/git/t/te/test/testgit.git/test-src-git-HEAD.tmp")
+        assert_equal(self.repo.get_tarball_status('HEAD'), None)
+        os.makedirs("/tmp/tarball/git/t/te/test/testgit.git/test-src-git-HEAD")
+        assert_equal(self.repo.get_tarball_status('HEAD'), 'busy')
+
 
 class TestGitCommit(unittest.TestCase):
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/5105ac33/ForgeSVN/forgesvn/model/svn.py
----------------------------------------------------------------------
diff --git a/ForgeSVN/forgesvn/model/svn.py b/ForgeSVN/forgesvn/model/svn.py
index 7c7515a..902c829 100644
--- a/ForgeSVN/forgesvn/model/svn.py
+++ b/ForgeSVN/forgesvn/model/svn.py
@@ -611,8 +611,6 @@ class SVNImplementation(M.RepositoryImplementation):
         return entries
 
     def tarball(self, commit):
-        shortname = self._repo.project.shortname.replace('/', '-')
-        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)
@@ -621,11 +619,13 @@ class SVNImplementation(M.RepositoryImplementation):
         self._svn.export(self._url,
                          path,
                          revision=pysvn.Revision(pysvn.opt_revision_kind.number, commit))
-        archive_name = '%s-%s-%s' % (shortname, mount_point, commit)
-        filename = os.path.join(self._repo.tarball_path, archive_name + '.tar.gz')
-        with tarfile.open(filename, "w:gz") as tar:
+        archive_name = self._repo.tarball_filename(commit)
+        filename = os.path.join(self._repo.tarball_path, '%s%s' % (archive_name, '.tar.gz'))
+        tmpfilename = os.path.join(self._repo.tarball_path, '%s%s' % (archive_name, '.tmp'))
+        with tarfile.open(tmpfilename, "w:gz") as tar:
             tar.add(path, arcname=archive_name)
         rmtree(path)
+        os.rename(tmpfilename, filename)
 
 
 Mapper.compile_all()


Mime
View raw message