3
MoinMoin - migrate from several twikidraw files to one tarfile.
5
This script looks at all pages' attachments and checks whether they
6
contain TWikiDraw items. If this is the case, the TWikiDraw items are
7
bundled into a single tar file (.tdraw) on the disk.
8
(The intention is to later store this as a single Item in the new storage
11
@copyright: 2008 by Christopher Denter
12
@license: GNU GPL, see COPYING for details.
18
from MoinMoin.support import tarfile
19
from MoinMoin.action.AttachFile import getAttachDir
22
def execute(script, data_dir, rev):
23
pagenames = script.request.rootpage.getPageList(user='', include_underlay=False)
25
for pagename in pagenames:
26
attachdir = getAttachDir(script.request, pagename)
28
drawings = [fn for fn in os.listdir(attachdir) if fn.endswith('.draw')]
30
# silenced. attachment directory does not exist. proceed with next page
32
for drawing in drawings:
33
basename = os.path.splitext(drawing)[0]
34
tar_filename = os.path.join(attachdir, basename + '.tdraw')
35
tar = tarfile.open(tar_filename, 'w:')
36
for ext in ['.draw', '.map', '.png', '.gif', ]:
37
filename = os.path.join(attachdir, basename + ext)
40
# get rid of the gif (TWikiDraw will (re)create
41
# a .png when someone edits the drawing)
42
# we use drawing.* as tar member filenames EVER, so the
43
# member filenames do not need to be changed when the
44
# tar container file gets renamed:
45
tar.add(filename, 'drawing' + ext)
48
if err.errno != errno.ENOENT:
49
# .map and .png are optional, .draw should be there