incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [08/50] git commit: [#3154] ticket:386 Don't run export if another one is running
Date Wed, 21 Aug 2013 20:12:24 GMT
[#3154] ticket:386 Don't run export if another one is running


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

Branch: refs/heads/db/3154b
Commit: 86f91d63990bbfb49a02990aa8c3d4628f939028
Parents: 6b635e6
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Thu Jul 4 15:21:10 2013 +0300
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Wed Aug 21 18:12:22 2013 +0000

----------------------------------------------------------------------
 Allura/allura/model/project.py      |  9 +++++++
 Allura/allura/tasks/export_tasks.py |  3 +++
 Allura/allura/tests/test_tasks.py   | 42 ++++++++++++++++++++++++++++----
 3 files changed, 49 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/86f91d63/Allura/allura/model/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/project.py b/Allura/allura/model/project.py
index aaf5828..fb14fc7 100644
--- a/Allura/allura/model/project.py
+++ b/Allura/allura/model/project.py
@@ -15,6 +15,7 @@
 #       specific language governing permissions and limitations
 #       under the License.
 
+import os
 import logging
 from collections import Counter, OrderedDict
 from datetime import datetime
@@ -828,6 +829,14 @@ class Project(MappedClass, ActivityNode, ActivityObject):
     def bulk_export_filename(self):
         return '%s.zip' % self.shortname
 
+    def bulk_export_status(self):
+        fn = os.path.join(self.bulk_export_path(), self.bulk_export_filename())
+        tmpdir = os.path.join(self.bulk_export_path(), self.shortname)
+        if os.path.isfile(fn):
+            return 'ready'
+        elif os.path.exists(tmpdir):
+            return 'busy'
+
 
 class AppConfig(MappedClass):
     """

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/86f91d63/Allura/allura/tasks/export_tasks.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tasks/export_tasks.py b/Allura/allura/tasks/export_tasks.py
index f2f5371..64aee3f 100644
--- a/Allura/allura/tasks/export_tasks.py
+++ b/Allura/allura/tasks/export_tasks.py
@@ -33,6 +33,9 @@ def bulk_export(project_shortname, tools):
     if not project:
         log.error('Project %s not found' % project_shortname)
         return
+    if project.bulk_export_status() == 'busy':
+        log.info('Another export is running for project %s. Skipping.' % project_shortname)
+        return
     for tool in tools or []:
         app = project.app_instance(tool)
         if not app:

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/86f91d63/Allura/allura/tests/test_tasks.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_tasks.py b/Allura/allura/tests/test_tasks.py
index d6f676e..5f2e44c 100644
--- a/Allura/allura/tests/test_tasks.py
+++ b/Allura/allura/tests/test_tasks.py
@@ -333,6 +333,12 @@ class TestExportTasks(unittest.TestCase):
     def setUp(self):
         setup_basic_test()
         setup_global_objects()
+        project = M.Project.query.get(shortname='test')
+        shutil.rmtree(project.bulk_export_path(), ignore_errors=True)
+
+    def tearDown(self):
+        project = M.Project.query.get(shortname='test')
+        shutil.rmtree(project.bulk_export_path(), ignore_errors=True)
 
     @mock.patch('allura.tasks.export_tasks.log')
     def test_bulk_export_invalid_project(self, log):
@@ -357,35 +363,61 @@ class TestExportTasks(unittest.TestCase):
             mock.call('Tool bugs is not exportable. Skipping.'),
             mock.call('Tool blog is not exportable. Skipping.')])
 
+    @mock.patch('allura.tasks.export_tasks.shutil')
+    @mock.patch('allura.tasks.export_tasks.zipdir')
     @mock.patch('forgewiki.wiki_main.ForgeWikiApp.bulk_export')
     @mock.patch('allura.tasks.export_tasks.log')
     @td.with_wiki
-    def test_bulk_export(self, log, wiki_bulk_export):
+    def test_bulk_export(self, log, wiki_bulk_export, zipdir, shutil):
         export_tasks.bulk_export('test', [u'wiki'])
         assert_equal(log.info.call_count, 1)
         assert_equal(log.info.call_args_list, [
             mock.call('Exporting wiki...')])
         wiki_bulk_export.assert_called_once()
+        temp = '/tmp/bulk_export/p/test/test'
+        zipfn = '/tmp/bulk_export/p/test/test.zip'
+        zipdir.assert_caled_once_with(temp, temp + '/test.zip')
+        shutil.move.assert_called_once_with(temp + '/test.zip',  zipfn)
+        shutil.rmtree.assert_called_once_with(temp)
+
+    @mock.patch('forgewiki.wiki_main.ForgeWikiApp.bulk_export')
+    @mock.patch('allura.tasks.export_tasks.log')
+    @td.with_wiki
+    def test_bulk_export_quits_if_another_export_is_running(self, log, wiki_bulk_export):
+        project = M.Project.query.get(shortname='test')
+        export_tasks.create_export_dir(project)
+        assert_equal(project.bulk_export_status(), 'busy')
+        export_tasks.bulk_export('test', [u'wiki'])
+        log.info.assert_called_once_with('Another export is running for project test. Skipping.')
+        assert_equal(wiki_bulk_export.call_count, 0)
 
     def test_create_export_dir(self):
         project = M.Project.query.get(shortname='test')
         export_path = project.bulk_export_path()
-        shutil.rmtree(export_path, ignore_errors=True)
         path = export_tasks.create_export_dir(project)
         assert_equal(path, '/tmp/bulk_export/p/test/test')
         assert os.path.exists(os.path.join(export_path, project.shortname))
-        shutil.rmtree(export_path, ignore_errors=True)
 
     @onlyif(os.path.exists(tg.config.get('scm.repos.tarball.zip_binary', '/usr/bin/zip')),
'zip binary is missing')
     def test_zip_and_cleanup(self):
         project = M.Project.query.get(shortname='test')
         export_path = project.bulk_export_path()
-        shutil.rmtree(export_path, ignore_errors=True)
         path = export_tasks.create_export_dir(project)
         export_tasks.zip_and_cleanup(project)
         assert not os.path.exists(path)
         assert os.path.exists(os.path.join(export_path, 'test.zip'))
-        shutil.rmtree(export_path, ignore_errors=True)
+
+    def test_bulk_export_status(self):
+        project = M.Project.query.get(shortname='test')
+        assert_equal(project.bulk_export_status(), None)
+
+        export_tasks.create_export_dir(project)
+        assert_equal(project.bulk_export_status(), 'busy')
+
+        with open(os.path.join(project.bulk_export_path(),
+                               project.bulk_export_filename()), 'w') as f:
+            f.write('just test')
+        assert_equal(project.bulk_export_status(), 'ready')
 
 
 Mapper.compile_all()


Mime
View raw message