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/21 17:26:46 UTC

[04/50] git commit: [#3154] ticket:386 Pass file handles to the bulk_export()

[#3154] ticket:386 Pass file handles to the bulk_export()


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

Branch: refs/heads/db/3154b
Commit: 1024e06394c108bfb479904e2d01a80b90371a3a
Parents: b8397ea
Author: Igor Bondarenko <je...@gmail.com>
Authored: Thu Jul 4 12:48:56 2013 +0300
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Wed Aug 21 15:25:54 2013 +0000

----------------------------------------------------------------------
 Allura/allura/tasks/export_tasks.py | 28 ++++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1024e063/Allura/allura/tasks/export_tasks.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tasks/export_tasks.py b/Allura/allura/tasks/export_tasks.py
index 29f99a8..4c1f95a 100644
--- a/Allura/allura/tasks/export_tasks.py
+++ b/Allura/allura/tasks/export_tasks.py
@@ -15,6 +15,7 @@
 #       specific language governing permissions and limitations
 #       under the License.
 
+import os
 import logging
 
 from allura import model as M
@@ -39,5 +40,28 @@ def bulk_export(project_shortname, tools):
             log.info('Tool %s is not exportable. Skipping.' % tool)
             continue
         log.info('Exporting %s...' % tool)
-        # TODO: Create file handle for *.json and pass it to bulk_export
-        app.bulk_export()
+        try:
+            path = create_export_dir(project)
+            with open(os.path.join(path, '%s.json' % tool), 'w') as f:
+                app.bulk_export(f)
+        except:
+            log.error('Something went wrong during export of %s' % tool, exc_info=True)
+            continue
+
+    try:
+        cleanup()
+    except:
+        log.error('Error on cleanup.', exc_info=True)
+
+
+def create_export_dir(project):
+    """Create temporary directory for export files"""
+    path = os.path.join(project.bulk_export_path(), 'tmp')
+    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