You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by tv...@apache.org on 2013/09/12 22:51:55 UTC

[05/29] git commit: [#6595] Make 'tarball' controller handle GET and POST

[#6595] Make 'tarball' controller handle GET and POST

Signed-off-by: Tim Van Steenburgh <tv...@gmail.com>


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

Branch: refs/heads/tv/6457
Commit: f9679555198e5246fbbcf003e44d39d9f94e13f9
Parents: 6769dc2
Author: Tim Van Steenburgh <tv...@gmail.com>
Authored: Mon Aug 26 14:00:08 2013 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Wed Aug 28 19:40:32 2013 +0000

----------------------------------------------------------------------
 Allura/allura/controllers/repository.py         | 12 ++---
 Allura/allura/templates/repo/tarball.html       | 13 ++++--
 .../tests/functional/test_controllers.py        | 10 +++-
 .../tests/functional/test_controllers.py        | 49 ++++++++++----------
 4 files changed, 46 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/f9679555/Allura/allura/controllers/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/repository.py b/Allura/allura/controllers/repository.py
index f984a91..14ce77a 100644
--- a/Allura/allura/controllers/repository.py
+++ b/Allura/allura/controllers/repository.py
@@ -20,7 +20,7 @@ import json
 import logging
 import re
 import difflib
-from urllib import quote, unquote
+from urllib import quote, unquote, quote_plus
 from collections import defaultdict
 from itertools import islice
 
@@ -459,24 +459,24 @@ class CommitBrowser(BaseController):
             result.update(self._commit.context())
         return result
 
-    @require_post()
     @expose('jinja:allura:templates/repo/tarball.html')
     def tarball(self, **kw):
-        path = kw.pop('path', None)
+        path = request.params.get('path')
         if not asbool(tg.config.get('scm.repos.tarball.enable', False)):
             raise exc.HTTPNotFound()
         rev = self._commit.url().split('/')[-2]
         status = c.app.repo.get_tarball_status(rev, path)
-        if status is None:
+        if status is None and request.method == 'POST':
             allura.tasks.repo_tasks.tarball.post(revision=rev, path=path)
-        return dict(commit=self._commit, revision=rev, status=status)
+            redirect('tarball' + '?path={0}'.format(path) if path else '')
+        return dict(commit=self._commit, revision=rev, status=status or 'na')
 
     @expose('json:')
     def tarball_status(self, path=None, **kw):
         if not asbool(tg.config.get('scm.repos.tarball.enable', False)):
             raise exc.HTTPNotFound()
         rev = self._commit.url().split('/')[-2]
-        return dict(status=c.app.repo.get_tarball_status(rev, path))
+        return dict(status=c.app.repo.get_tarball_status(rev, path) or 'na')
 
 
     @expose('jinja:allura:templates/repo/log.html')

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/f9679555/Allura/allura/templates/repo/tarball.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/repo/tarball.html b/Allura/allura/templates/repo/tarball.html
index e4a9cad..805293c 100644
--- a/Allura/allura/templates/repo/tarball.html
+++ b/Allura/allura/templates/repo/tarball.html
@@ -53,13 +53,14 @@ 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;
+        var delay = 500;
         // Check tarball status every 5 seconds
         function check_status() {
             $.get('{{commit.url()}}tarball_status?path={{path}}', function(data) {
-                if (data.status === 'ready') {
+                if (data.status !== 'na') {
                     spinner.stop();
-                    $('#snapshot_status h2').toggle();
+                    $('#snapshot_status h2').hide();
+                    $('#snapshot_status h2.' + data.status).show();
                     {% if 'no-redirect' not in request.params %}
                         window.location.href = '{{c.app.repo.tarball_url(revision, path)}}';
                     {% endif %}
@@ -82,6 +83,7 @@ Commit <a href="{{commit.url()}}">{{commit.shorthand_id()}}</a> {{commit_labels(
 <div id='snapshot_status'>
     <h2 class="busy">Generating snapshot...</h2>
     <h2 class="ready">Your download will begin shortly, or use this <a href="{{c.app.repo.tarball_url(revision, path)}}">direct link</a>.</h2>
+    <h2 class="na">Checking snapshot status...</h2>
 </div>
 {% endblock %}
 
@@ -89,9 +91,10 @@ Commit <a href="{{commit.url()}}">{{commit.shorthand_id()}}</a> {{commit_labels(
 <style type="text/css">
     #snapshot_status h2 {
         padding-left: 33px;
-    }
-    #snapshot_status .{{ 'busy' if status == 'ready' else 'ready' }} {
         display: none;
     }
+    #snapshot_status .{{ status }} {
+        display: block;
+    }
 </style>
 {% endblock %}

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/f9679555/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 1222429..c05ef94 100644
--- a/ForgeGit/forgegit/tests/functional/test_controllers.py
+++ b/ForgeGit/forgegit/tests/functional/test_controllers.py
@@ -53,6 +53,8 @@ class _TestCase(TestController):
         # ThreadLocalORMSession.close_all()
         h.set_context('test', 'src-git', neighborhood='Projects')
         c.app.repo.refresh()
+        if os.path.isdir(c.app.repo.tarball_path):
+            shutil.rmtree(c.app.repo.tarball_path)
         ThreadLocalORMSession.flush_all()
         # ThreadLocalORMSession.close_all()
 
@@ -343,14 +345,18 @@ class TestRootController(_TestCase):
         r = self.app.get(ci + 'tree/')
         assert '/p/test/src-git/ci/master/tarball' in r
         assert 'Download Snapshot' in r
-        r = self.app.post('/p/test/src-git/ci/master/tarball')
-        assert 'Generating snapshot...' in r
+        r = self.app.post('/p/test/src-git/ci/master/tarball').follow()
+        assert 'Checking snapshot status...' in r
+        r = self.app.get('/p/test/src-git/ci/master/tarball')
+        assert 'Checking snapshot status...' in r
         M.MonQTask.run_ready()
         ThreadLocalORMSession.flush_all()
         r = self.app.get(ci + 'tarball_status')
         assert '{"status": "ready"}' in r
         r = self.app.get('/p/test/src-git/ci/master/tarball_status')
         assert '{"status": "ready"}' in r
+        r = self.app.get('/p/test/src-git/ci/master/tarball')
+        assert 'Your download will begin shortly' in r
 
     def test_tarball_link_in_subdirs(self):
         '''Go to repo subdir and check 'Download Snapshot' link'''

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/f9679555/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 cc37545..16fd989 100644
--- a/ForgeSVN/forgesvn/tests/functional/test_controllers.py
+++ b/ForgeSVN/forgesvn/tests/functional/test_controllers.py
@@ -38,29 +38,24 @@ class SVNTestController(TestController):
         TestController.setUp(self)
         self.setup_with_tools()
 
-    @with_svn
-    @with_tool('test', 'SVN', 'svn-tags', 'SVN with tags')
-    def setup_with_tools(self):
-        h.set_context('test', 'src', neighborhood='Projects')
+    def _make_app(self, mount_point, name):
+        h.set_context('test', mount_point, neighborhood='Projects')
         repo_dir = pkg_resources.resource_filename(
             'forgesvn', 'tests/data/')
         c.app.repo.fs_path = repo_dir
         c.app.repo.status = 'ready'
-        c.app.repo.name = 'testsvn'
-        ThreadLocalORMSession.flush_all()
-        ThreadLocalORMSession.close_all()
-        h.set_context('test', 'src', neighborhood='Projects')
-        c.app.repo.refresh()
-        ThreadLocalORMSession.flush_all()
-        ThreadLocalORMSession.close_all()
-        h.set_context('test', 'svn-tags', neighborhood='Projects')
-        c.app.repo.fs_path = repo_dir
-        c.app.repo.status = 'ready'
-        c.app.repo.name = 'testsvn-trunk-tags-branches'
+        c.app.repo.name = name
         c.app.repo.refresh()
+        if os.path.isdir(c.app.repo.tarball_path):
+            shutil.rmtree(c.app.repo.tarball_path)
         ThreadLocalORMSession.flush_all()
         ThreadLocalORMSession.close_all()
-        h.set_context('test', 'src', neighborhood='Projects')
+
+    @with_svn
+    @with_tool('test', 'SVN', 'svn-tags', 'SVN with tags')
+    def setup_with_tools(self):
+        self._make_app('svn-tags', 'testsvn-trunk-tags-branches')
+        self._make_app('src', 'testsvn')
 
 
 class TestRootController(SVNTestController):
@@ -194,12 +189,16 @@ class TestRootController(SVNTestController):
     def test_tarball(self):
         r = self.app.get('/src/3/tree/')
         assert 'Download Snapshot' in r
-        r = self.app.post('/src/3/tarball')
-        assert 'Generating snapshot...' in r
+        r = self.app.post('/src/3/tarball').follow()
+        assert 'Checking snapshot status...' in r
+        r = self.app.get('/src/3/tarball')
+        assert 'Checking snapshot status...' in r
         M.MonQTask.run_ready()
         ThreadLocalORMSession.flush_all()
         r = self.app.get('/src/3/tarball_status')
         assert '{"status": "ready"}' in r
+        r = self.app.get('/src/3/tarball')
+        assert 'Your download will begin shortly' in r
 
     @onlyif(os.path.exists(tg.config.get('scm.repos.tarball.zip_binary', '/usr/bin/zip')), 'zip binary is missing')
     def test_tarball_tags_aware(self):
@@ -217,23 +216,23 @@ class TestRootController(SVNTestController):
         assert_equal(form.find('input', attrs=dict(name='path')).get('value'), '/tags/tag-1.0')
 
         r = self.app.get('/p/test/svn-tags/19/tarball_status?path=/tags/tag-1.0')
-        assert_equal(r.json['status'], None)
-        r = self.app.post('/p/test/svn-tags/19/tarball', dict(path='/tags/tag-1.0'))
-        assert 'Generating snapshot...' in r
+        assert_equal(r.json['status'], 'na')
+        r = self.app.post('/p/test/svn-tags/19/tarball', dict(path='/tags/tag-1.0')).follow()
+        assert 'Checking snapshot status...' in r
         M.MonQTask.run_ready()
         r = self.app.get('/p/test/svn-tags/19/tarball_status?path=/tags/tag-1.0')
         assert_equal(r.json['status'], 'ready')
 
         r = self.app.get('/p/test/svn-tags/19/tarball_status?path=/trunk')
-        assert_equal(r.json['status'], None)
-        r = self.app.post('/p/test/svn-tags/19/tarball', dict(path='/trunk/'))
-        assert 'Generating snapshot...' in r
+        assert_equal(r.json['status'], 'na')
+        r = self.app.post('/p/test/svn-tags/19/tarball', dict(path='/trunk/')).follow()
+        assert 'Checking snapshot status...' in r
         M.MonQTask.run_ready()
         r = self.app.get('/p/test/svn-tags/19/tarball_status?path=/trunk')
         assert_equal(r.json['status'], 'ready')
 
         r = self.app.get('/p/test/svn-tags/19/tarball_status?path=/branches/aaa/')
-        assert_equal(r.json['status'], None)
+        assert_equal(r.json['status'], 'na')
 
         # All of the following also should be ready because...
         # ...this is essentially the same as trunk snapshot