changeset 4438:c9b66b3cac07

merged main
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 28 Dec 2008 17:40:23 +0100
parents c768bceac25e (current diff) 4122e38d9582 (diff)
children ec62380ae400
files
diffstat 1 files changed, 52 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/script/migration/1089999.py	Sun Dec 28 17:40:23 2008 +0100
@@ -0,0 +1,52 @@
+#!/usr/bin/env python
+"""
+    MoinMoin - migrate from several twikidraw files to one tarfile.
+
+    This script looks at all pages' attachments and checks whether they
+    contain TWikiDraw items. If this is the case, the TWikiDraw items are
+    transformed into a single tarfile on the disk.
+    (The intention is to later store this as a single Item in the new storage
+    layer.)
+
+    @copyright: 2008 by Christopher Denter
+    @license: GNU GPL, see COPYING for details.
+
+"""
+
+import os
+import tarfile
+
+from MoinMoin.action.AttachFile import getAttachDir
+
+
+def execute(script, data_dir, rev):
+    pagenames = script.request.rootpage.getPageList(user='', include_underlay=False)
+
+    for pagename in pagenames:
+        attachdir = getAttachDir(script.request, pagename)
+        try:
+           filenames = os.listdir(attachdir)
+        except OSError:
+            # silenced. attachment directory does not exist. proceed with next page
+            continue
+        for filename in filenames:
+            if filename.endswith('.draw'):
+                filename = filename.split('.')[0]  # XXX only 1 dot in filename allowed atm
+                # Open for uncompressed writing
+                os.chdir(attachdir)  # XXX Do we really need to catch permission errors here?
+                tar = tarfile.open(filename + '.tar', 'w:')  # XXX same question here.
+                tar.add(filename + '.draw')
+                os.remove(filename + '.draw')  # XXX and here
+                try:
+                    tar.add(filename + '.map')
+                    os.remove(filename + '.map')  # XXX and here
+                except OSError:
+                    # The .map file is optional
+                    pass
+
+                # TODO Decide whether png files shall be included in the
+                # TODO tar file and take appropriate action.
+
+                tar.close()
+
+    return 1090000