incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tvansteenbu...@apache.org
Subject [11/50] [abbrv] git commit: [#2840] ticket:273 user interface for tarball
Date Tue, 12 Mar 2013 20:04:51 GMT
[#2840] ticket:273 user interface for tarball


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

Branch: refs/heads/si/5453
Commit: bb43fdad55541c6e52b906807deb192a06f5dcf2
Parents: 6ffde84
Author: Yuriy Arhipov <yuriyarhipovua@yandex.ru>
Authored: Wed Feb 27 16:17:01 2013 +0400
Committer: Cory Johns <johnsca@geek.net>
Committed: Mon Mar 11 22:29:45 2013 +0000

----------------------------------------------------------------------
 Allura/allura/controllers/repository.py            |   23 +++++-
 Allura/allura/model/repository.py                  |   22 +++++
 Allura/allura/nf/allura/css/site_style.css         |    4 +
 Allura/allura/tasks/repo_tasks.py                  |    6 ++
 Allura/allura/templates/repo/tarball.html          |   64 +++++++++++++++
 Allura/allura/templates/repo/tree.html             |    6 +-
 Allura/development.ini                             |    2 +
 Allura/test.ini                                    |    2 +
 .../forgegit/tests/functional/test_controllers.py  |   11 +++
 ForgeGit/forgegit/tests/model/test_repository.py   |    3 +
 .../forgesvn/tests/functional/test_controllers.py  |   11 +++
 ForgeSVN/forgesvn/tests/model/test_repository.py   |    3 +
 12 files changed, 151 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/bb43fdad/Allura/allura/controllers/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/repository.py b/Allura/allura/controllers/repository.py
index 6a38f74..f3ead26 100644
--- a/Allura/allura/controllers/repository.py
+++ b/Allura/allura/controllers/repository.py
@@ -425,10 +425,27 @@ class CommitBrowser(BaseController):
             result.update(self._commit.context())
         return result
 
-    @expose()
+    @expose('jinja:allura:templates/repo/tarball.html')
     def tarball(self, **kw):
-        allura.tasks.repo_tasks.tarball.post(revision=self._revision)
-        redirect(redirect(request.referer))
+        if tg.config.get('scm.repos.tarball.enable', 'false') != 'true':
+            return
+        c.app.repo.set_tarball_status(self._revision, None)
+        shortname = c.app.repo.project.shortname
+        mount_point = c.app.repo.app.config.options.mount_point
+        filename = '%s-%s-%s.tar' % (shortname, mount_point, self._revision)
+        if (os.path.isfile(os.path.join(c.app.repo.tarball_path, filename)) and
+                (c.app.repo.get_tarball_status(self._revision) == 'ready')):
+            redirect(c.app.repo.tarball_url(self._revision))
+        else:
+            allura.tasks.repo_tasks.tarball.post(revision=self._revision)
+        return dict(commit=self._commit)
+
+    @expose('json:')
+    def tarball_status(self):
+        if tg.config.get('scm.repos.tarball.enable', 'false') != 'true':
+            return
+        return dict(status=c.app.repo.get_tarball_status(self._revision))
+
 
     @expose('jinja:allura:templates/repo/log.html')
     @with_trailing_slash

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/bb43fdad/Allura/allura/model/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repository.py b/Allura/allura/model/repository.py
index 5653e2b..19ec7cb 100644
--- a/Allura/allura/model/repository.py
+++ b/Allura/allura/model/repository.py
@@ -207,6 +207,7 @@ 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:
@@ -236,6 +237,27 @@ class Repository(Artifact, ActivityObject):
                             self.project.url()[1:],
                             self.name)
 
+    def tarball_url(self, revision):
+        shortname = c.app.repo.project.shortname
+        mount_point = c.app.repo.app.config.options.mount_point
+        filename = '%s-%s-%s.tar' % (shortname, mount_point, revision)
+        r = os.path.join(self.tool,self.project.url()[1:],self.name,filename)
+        return tg.config.get('scm.repos.tarball.url', '/') + r
+
+    def get_tarball_status(self, revision):
+        tarballs = dict((t.revision, t.status) for t in self.tarball_status)
+        if revision in tarballs.keys():
+            return tarballs[revision]
+
+    def set_tarball_status(self, revision, status):
+        if self.get_tarball_status(revision):
+            for tarball in self.tarball_status:
+                if tarball['revision'] == revision:
+                    tarball['status'] = status
+        else:
+            self.tarball_status.append(dict(revision=revision, status=status))
+
+
     def __repr__(self): # pragma no cover
         return '<%s %s>' % (
             self.__class__.__name__,

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/bb43fdad/Allura/allura/nf/allura/css/site_style.css
----------------------------------------------------------------------
diff --git a/Allura/allura/nf/allura/css/site_style.css b/Allura/allura/nf/allura/css/site_style.css
index 1b28457..10b13f3 100644
--- a/Allura/allura/nf/allura/css/site_style.css
+++ b/Allura/allura/nf/allura/css/site_style.css
@@ -2745,6 +2745,10 @@ h1.title .viewer:hover {
   padding-left: 33px;
 }
 
+#tarball_status h2 {
+    padding-left: 33px;
+}
+
 .neighborhood_feed_entry h3 {
   font-size: 1.1em;
 }

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/bb43fdad/Allura/allura/tasks/repo_tasks.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tasks/repo_tasks.py b/Allura/allura/tasks/repo_tasks.py
index 87d4f72..4d5047b 100644
--- a/Allura/allura/tasks/repo_tasks.py
+++ b/Allura/allura/tasks/repo_tasks.py
@@ -105,12 +105,18 @@ def reclone_repo(*args, **kwargs):
 
 @task
 def tarball(revision=None):
+    from ming.orm import ThreadLocalORMSession
+
     log = logging.getLogger(__name__)
+    c.app.repo.set_tarball_status(revision, None)
     if revision:
         repo = c.app.repo
         try:
             repo.tarball(revision)
+            c.app.repo.set_tarball_status(revision, 'ready')
+            ThreadLocalORMSession.flush_all()
         except:
+            c.app.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))
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/bb43fdad/Allura/allura/templates/repo/tarball.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/repo/tarball.html b/Allura/allura/templates/repo/tarball.html
new file mode 100644
index 0000000..72e482d
--- /dev/null
+++ b/Allura/allura/templates/repo/tarball.html
@@ -0,0 +1,64 @@
+{% extends 'allura:templates/repo/repo_master.html' %}
+
+{% do g.register_forge_css('css/forge/diff.css') %}
+
+{% block title %}
+{{c.project.name}} / {{c.app.config.options.mount_label}} / Commit {{commit.shorthand_id()}}
+{% endblock %}
+
+{% block header -%}
+Commit <a href="{{commit.url()}}">{{commit.shorthand_id()}}</a> {{commit_labels(commit)}}
+{%- endblock %}
+
+{% block actions %}
+<a href="{{commit.url()}}log/">
+    <b data-icon="{{g.icons.history.char}}" class="ico {{g.icons.history.css}}" title="History">
</b> History
+</a>
+{% endblock %}
+
+{% block extra_js %}
+{{ super() }}
+<script type="text/javascript">(function() {
+    var tarball_status = document.getElementById('tarball_status');
+    if (tarball_status) {
+        var opts = {
+            lines: 9, // The number of lines to draw
+            length: 4, // The length of each line
+            width: 2, // The line thickness
+            radius: 3, // The radius of the inner circle
+            rotate: 0, // The rotation offset
+            color: '#555', // #rgb or #rrggbb
+            speed: 1, // Rounds per second
+            trail: 60, // Afterglow percentage
+            shadow: false, // Whether to render a shadow
+            hwaccel: false, // Whether to use hardware acceleration
+            className: 'spinner', // The CSS class to assign to the spinner
+            zIndex: 2e9, // The z-index (defaults to 2000000000)
+            top: 10, // Top position relative to parent in px
+            left: 10 // Left position relative to parent in px
+        };
+        var spinner = new Spinner(opts).spin(tarball_status);
+        function check_status() {
+            $.get('{{commit.url()}}tarball_status', function(data) {
+                if (data.status === 'ready') {
+                    window.clearInterval(status_checker);
+                    spinner.opts.speed = 0;
+                    spinner.opts.opacity = 1;
+                    spinner.spin(tarball_status);
+                    $('#tarball_status h2').html(' <a href="{{commit.url()}}tree">Click
here to return to repository</a>');
+                    window.location.href = '{{c.app.repo.tarball_url(commit._id)}}';
+                }
+            });
+        }
+        // Check tarball status every 5 seconds
+        var status_checker = window.setInterval(check_status, 5000);
+    }
+}());
+</script>
+{% endblock %}
+
+{% block content %}
+<div id='tarball_status'>
+    <h2>Please wait..</h2>
+</div>
+{% endblock %}

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/bb43fdad/Allura/allura/templates/repo/tree.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/repo/tree.html b/Allura/allura/templates/repo/tree.html
index b3e3094..83f6e6d 100644
--- a/Allura/allura/templates/repo/tree.html
+++ b/Allura/allura/templates/repo/tree.html
@@ -12,9 +12,9 @@ Tree <a href="{{commit.url()}}">{{commit.shorthand_id()}}</a>
{{commit_labels(co
 {% endblock %}
 
 {% block actions %}
-<a href="{{commit.url()}}tarball">
-     Tarball
-</a>
+{% if tg.config.get('scm.repos.tarball.enable', 'false')=='true' %}
+<a href="{{commit.url()}}tarball">Download tarball</a>
+{% endif %}
 
 <a href="{{commit.url()}}log/?path={{ path }}">
   <b data-icon="{{g.icons.history.char}}" class="ico {{g.icons.history.css}}" title="History">
</b> History

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

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/bb43fdad/Allura/test.ini
----------------------------------------------------------------------
diff --git a/Allura/test.ini b/Allura/test.ini
index 3e0d18e..9ee8420 100644
--- a/Allura/test.ini
+++ b/Allura/test.ini
@@ -81,7 +81,9 @@ 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.enable = true
 scm.repos.tarball.root = /tmp/tarball
+scm.repos.tarball.url = file://
 
 #stats.sample_rate = 0
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/bb43fdad/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 c8abd79..ac1ddd1 100644
--- a/ForgeGit/forgegit/tests/functional/test_controllers.py
+++ b/ForgeGit/forgegit/tests/functional/test_controllers.py
@@ -266,6 +266,17 @@ class TestRootController(_TestCase):
         r = self.app.get(ci + 'tree/')
         assert '<div id="access_urls"' in r
 
+    def test_tarball(self):
+        ci = self._get_ci()
+        r = self.app.get(ci + 'tree/')
+        assert 'Download tarball' in r
+        r = self.app.get(ci + 'tarball')
+        assert 'Please wait' in r
+        M.MonQTask.run_ready()
+        ThreadLocalORMSession.flush_all()
+        r = self.app.get(ci + 'tarball_status')
+        assert '{"status": "ready"}' in r
+
 
 class TestRestController(_TestCase):
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/bb43fdad/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 48c82ab..496fa27 100644
--- a/ForgeGit/forgegit/tests/model/test_repository.py
+++ b/ForgeGit/forgegit/tests/model/test_repository.py
@@ -240,8 +240,11 @@ class TestGitRepo(unittest.TestCase, RepoImplTestBase):
 
     def test_tarball(self):
         assert_equal(self.repo.tarball_path, '/tmp/tarball/git/p/test/testgit.git')
+        assert_equal(self.repo.tarball_url('HEAD'), 'file://git/p/test/testgit.git/test-src-git-HEAD.tar')
         self.repo.tarball('HEAD')
         assert os.path.isfile("/tmp/tarball/git/p/test/testgit.git/test-src-git-HEAD.tar")
+        self.repo.set_tarball_status('HEAD', 'ready')
+        assert_equal(self.repo.get_tarball_status('HEAD'), 'ready')
 
 
 class TestGitCommit(unittest.TestCase):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/bb43fdad/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 535e609..35af593 100644
--- a/ForgeSVN/forgesvn/tests/functional/test_controllers.py
+++ b/ForgeSVN/forgesvn/tests/functional/test_controllers.py
@@ -4,6 +4,7 @@ import pkg_resources
 from pylons import tmpl_context as c
 from ming.orm import ThreadLocalORMSession
 
+from allura import model as M
 from allura.lib import helpers as h
 from alluratest.controller import TestController
 from forgesvn.tests import with_svn
@@ -133,6 +134,16 @@ class TestRootController(SVNTestController):
         r = self.app.get('/src/2/log/?path=does/not/exist/')
         assert 'No (more) commits' in r
 
+    def test_tarball(self):
+        r = self.app.get('/src/3/tree/')
+        assert 'Download tarball' in r
+        r = self.app.get('/src/3/tarball')
+        assert 'Please wait' in r
+        M.MonQTask.run_ready()
+        ThreadLocalORMSession.flush_all()
+        r = self.app.get('/src/3/tarball_status')
+        assert '{"status": "ready"}' in r
+
 
 class TestImportController(SVNTestController):
     def test_index(self):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/bb43fdad/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 0eb7f19..e91c71e 100644
--- a/ForgeSVN/forgesvn/tests/model/test_repository.py
+++ b/ForgeSVN/forgesvn/tests/model/test_repository.py
@@ -267,8 +267,11 @@ class TestSVNRepo(unittest.TestCase, RepoImplTestBase):
 
     def test_tarball(self):
         assert_equal(self.repo.tarball_path, '/tmp/tarball/svn/p/test/testsvn')
+        assert_equal(self.repo.tarball_url('1'), 'file://svn/p/test/testsvn/test-src-1.tar')
         self.repo.tarball('1')
         assert os.path.isfile("/tmp/tarball/svn/p/test/testsvn/test-src-1.tar")
+        self.repo.set_tarball_status('1', 'ready')
+        assert_equal(self.repo.get_tarball_status('1'), 'ready')
 
 
 class TestSVNRev(unittest.TestCase):


Mime
View raw message