view MoinMoin/script/migration/ @ 4440:847d257bee5f

twikidraw mig script: use .tdraw for the tar file, get rid of .gif
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Mon, 29 Dec 2008 22:12:07 +0100
parents 4122e38d9582
children 6cfcb25278a7
line wrap: on
line source
#!/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
    bundled into a single tar file (.tdraw) on the disk.
    (The intention is to later store this as a single Item in the new storage

    @copyright: 2008 by Christopher Denter
    @license: GNU GPL, see COPYING for details.


import os, errno

from 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)
            drawings = [fn for fn in os.listdir(attachdir) if fn.endswith('.draw')]
        except OSError:
            # silenced. attachment directory does not exist. proceed with next page
        for drawing in drawings:
            basename = os.path.splitext(drawing)[0]
            tar_filename = os.path.join(attachdir, basename + '.tdraw')
            tar =, 'w:')
            for ext in ['.draw', '.map', '.png', '.gif', ]:
                filename = os.path.join(attachdir, basename + ext)
                    if ext != '.gif':
                        # get rid of the gif (TWikiDraw will (re)create
                        # a .png when someone edits the drawing)
                        tar.add(filename, basename + ext)
                except OSError, err:
                    if err.errno != errno.ENOENT:
                        # .map and .png are optional, .draw should be there

    return 1090000