Back to index

moin  1.9.0~rc2
1089999.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 """
00003     MoinMoin - migrate from several twikidraw files to one tarfile.
00004 
00005     This script looks at all pages' attachments and checks whether they
00006     contain TWikiDraw items. If this is the case, the TWikiDraw items are
00007     bundled into a single tar file (.tdraw) on the disk.
00008     (The intention is to later store this as a single Item in the new storage
00009     layer.)
00010 
00011     @copyright: 2008 by Christopher Denter
00012     @license: GNU GPL, see COPYING for details.
00013 
00014 """
00015 
00016 import os, errno
00017 
00018 from MoinMoin.support import tarfile
00019 from MoinMoin.action.AttachFile import getAttachDir
00020 
00021 
00022 def execute(script, data_dir, rev):
00023     pagenames = script.request.rootpage.getPageList(user='', include_underlay=False)
00024 
00025     for pagename in pagenames:
00026         attachdir = getAttachDir(script.request, pagename)
00027         try:
00028             drawings = [fn for fn in os.listdir(attachdir) if fn.endswith('.draw')]
00029         except OSError:
00030             # silenced. attachment directory does not exist. proceed with next page
00031             continue
00032         for drawing in drawings:
00033             basename = os.path.splitext(drawing)[0]
00034             tar_filename = os.path.join(attachdir, basename + '.tdraw')
00035             tar = tarfile.open(tar_filename, 'w:')
00036             for ext in ['.draw', '.map', '.png', '.gif', ]:
00037                 filename = os.path.join(attachdir, basename + ext)
00038                 try:
00039                     if ext != '.gif':
00040                         # get rid of the gif (TWikiDraw will (re)create
00041                         # a .png when someone edits the drawing)
00042                         # we use drawing.* as tar member filenames EVER, so the
00043                         # member filenames do not need to be changed when the
00044                         # tar container file gets renamed:
00045                         tar.add(filename, 'drawing' + ext)
00046                     os.remove(filename)
00047                 except OSError, err:
00048                     if err.errno != errno.ENOENT:
00049                         # .map and .png are optional, .draw should be there
00050                         raise
00051             tar.close()
00052 
00053     return 1090000
00054