~ubuntu-branches/ubuntu/natty/moin/natty-updates

« back to all changes in this revision

Viewing changes to MoinMoin/script/migration/1089999.py

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2008-06-22 21:17:13 UTC
  • mto: This revision was merged to the branch mainline in revision 18.
  • Revision ID: james.westby@ubuntu.com-20080622211713-inlv5k4eifxckelr
ImportĀ upstreamĀ versionĀ 1.7.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python
2
 
"""
3
 
    MoinMoin - migrate from several twikidraw files to one tarfile.
4
 
 
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
9
 
    layer.)
10
 
 
11
 
    @copyright: 2008 by Christopher Denter
12
 
    @license: GNU GPL, see COPYING for details.
13
 
 
14
 
"""
15
 
 
16
 
import os, errno
17
 
 
18
 
from MoinMoin.support import tarfile
19
 
from MoinMoin.action.AttachFile import getAttachDir
20
 
 
21
 
 
22
 
def execute(script, data_dir, rev):
23
 
    pagenames = script.request.rootpage.getPageList(user='', include_underlay=False)
24
 
 
25
 
    for pagename in pagenames:
26
 
        attachdir = getAttachDir(script.request, pagename)
27
 
        try:
28
 
            drawings = [fn for fn in os.listdir(attachdir) if fn.endswith('.draw')]
29
 
        except OSError:
30
 
            # silenced. attachment directory does not exist. proceed with next page
31
 
            continue
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)
38
 
                try:
39
 
                    if ext != '.gif':
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)
46
 
                    os.remove(filename)
47
 
                except OSError, err:
48
 
                    if err.errno != errno.ENOENT:
49
 
                        # .map and .png are optional, .draw should be there
50
 
                        raise
51
 
            tar.close()
52
 
 
53
 
    return 1090000
54