allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tvansteenbu...@apache.org
Subject [50/50] git commit: [#6595] Make 'tarball' controller handle GET and POST
Date Mon, 26 Aug 2013 14:01:29 GMT
[#6595] Make 'tarball' controller handle GET and POST

Signed-off-by: Tim Van Steenburgh <tvansteenburgh@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/5b7c11f1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/5b7c11f1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/5b7c11f1

Branch: refs/heads/tv/6595
Commit: 5b7c11f1776440ce3f15f061c112885e5e8269ac
Parents: e42b20b
Author: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Authored: Mon Aug 26 14:00:08 2013 +0000
Committer: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Committed: Mon Aug 26 14:00:08 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/5b7c11f1/Allura/allura/controllers/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/repository.py b/Allura/allura/controllers/repository.py
index b1b743c..44acfcc 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
 
@@ -458,24 +458,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/5b7c11f1/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/5b7c11f1/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 5af224e..ab52f8c 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()
 
@@ -342,14 +344,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/5b7c11f1/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 78e7705..3c83ce7 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):
@@ -193,12 +188,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):
@@ -216,23 +215,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


Mime
View raw message