You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2013/08/22 23:53:28 UTC
[02/50] git commit: [#3154] ticket:386 Zip exported data
[#3154] ticket:386 Zip exported data
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/d74c0ff4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/d74c0ff4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/d74c0ff4
Branch: refs/heads/master
Commit: d74c0ff4bd09f9535c1304f2dc19f1be406828d7
Parents: 0d8e6e1
Author: Igor Bondarenko <je...@gmail.com>
Authored: Thu Jul 4 14:55:35 2013 +0300
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Thu Aug 22 20:04:39 2013 +0000
----------------------------------------------------------------------
Allura/allura/model/project.py | 3 +++
Allura/allura/tasks/export_tasks.py | 28 ++++++++++++++++++++++------
Allura/allura/tests/test_tasks.py | 24 ++++++++++++++++++++++++
Allura/test.ini | 2 ++
4 files changed, 51 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/d74c0ff4/Allura/allura/model/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/project.py b/Allura/allura/model/project.py
index 82c9a97..aaf5828 100644
--- a/Allura/allura/model/project.py
+++ b/Allura/allura/model/project.py
@@ -825,6 +825,9 @@ class Project(MappedClass, ActivityNode, ActivityObject):
nbhd=self.neighborhood.url_prefix.strip('/'),
project=self.shortname)
+ def bulk_export_filename(self):
+ return '%s.zip' % self.shortname
+
class AppConfig(MappedClass):
"""
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/d74c0ff4/Allura/allura/tasks/export_tasks.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tasks/export_tasks.py b/Allura/allura/tasks/export_tasks.py
index 4c1f95a..f2f5371 100644
--- a/Allura/allura/tasks/export_tasks.py
+++ b/Allura/allura/tasks/export_tasks.py
@@ -17,9 +17,11 @@
import os
import logging
+import shutil
from allura import model as M
from allura.lib.decorators import task
+from allura.model.repository import zipdir
log = logging.getLogger(__name__)
@@ -49,19 +51,33 @@ def bulk_export(project_shortname, tools):
continue
try:
- cleanup()
+ zip_and_cleanup(project)
except:
- log.error('Error on cleanup.', exc_info=True)
+ log.error('Something went wrong during zipping exported data.', exc_info=True)
def create_export_dir(project):
"""Create temporary directory for export files"""
- path = os.path.join(project.bulk_export_path(), 'tmp')
+ zip_fn = project.bulk_export_filename()
+ # Name temporary directory after project shortname,
+ # thus zipdir() will use proper prefix inside the archive.
+ tmp_dir_suffix = zip_fn.split('.')[0]
+ path = os.path.join(project.bulk_export_path(), tmp_dir_suffix)
if not os.path.exists(path):
os.makedirs(path)
return path
-def cleanup():
- """Copy zip with export data to proper location. Remove temporary files."""
- pass
+def zip_and_cleanup(project):
+ """Zip exported data. Copy it to proper location. Remove temporary files."""
+ path = project.bulk_export_path()
+ zip_fn = project.bulk_export_filename()
+ temp = os.path.join(path, zip_fn.split('.')[0])
+ zip_path_temp = os.path.join(temp, zip_fn)
+ zip_path = os.path.join(path, zip_fn)
+
+ zipdir(temp, zip_path_temp)
+
+ # cleanup
+ shutil.move(zip_path_temp, zip_path)
+ shutil.rmtree(temp)
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/d74c0ff4/Allura/allura/tests/test_tasks.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_tasks.py b/Allura/allura/tests/test_tasks.py
index 74a5d18..d6f676e 100644
--- a/Allura/allura/tests/test_tasks.py
+++ b/Allura/allura/tests/test_tasks.py
@@ -17,12 +17,15 @@
# specific language governing permissions and limitations
# under the License.
+import os
import operator
+import shutil
import sys
import unittest
from base64 import b64encode
import logging
+import tg
import mock
from pylons import tmpl_context as c, app_globals as g
from datadiff.tools import assert_equal
@@ -30,6 +33,7 @@ from nose.tools import assert_in
from ming.orm import FieldProperty, Mapper
from ming.orm import ThreadLocalORMSession
from testfixtures import LogCapture
+from IPython.testing.decorators import onlyif
from alluratest.controller import setup_basic_test, setup_global_objects
@@ -363,5 +367,25 @@ class TestExportTasks(unittest.TestCase):
mock.call('Exporting wiki...')])
wiki_bulk_export.assert_called_once()
+ 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)
+
Mapper.compile_all()
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/d74c0ff4/Allura/test.ini
----------------------------------------------------------------------
diff --git a/Allura/test.ini b/Allura/test.ini
index 7394359..6babfaf 100644
--- a/Allura/test.ini
+++ b/Allura/test.ini
@@ -102,6 +102,8 @@ scm.repos.tarball.enable = true
scm.repos.tarball.root = /tmp/tarball
scm.repos.tarball.url_prefix = file://
+bulk_export_path = /tmp/bulk_export/{nbhd}/{project}
+
support_tool_choices = wiki tickets discussion
#stats.sample_rate = 0