annotate MoinMoin/script/migration/1089999.py @ 6133:a6283e189869 tip

fixup: remove nonexisting passlib.utils._blowfish this was removed by the passlib 1.7.1 upgrade.
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Thu, 01 Jun 2017 18:10:19 +0200
parents 68f8bea727e5
children
rev   line source
4436
4122e38d9582 add simple script that converts the several elements of one twikidraw item into one tar archive. the script needs further love and integration
Christopher Denter
parents:
diff changeset
1 #!/usr/bin/env python
4122e38d9582 add simple script that converts the several elements of one twikidraw item into one tar archive. the script needs further love and integration
Christopher Denter
parents:
diff changeset
2 """
4122e38d9582 add simple script that converts the several elements of one twikidraw item into one tar archive. the script needs further love and integration
Christopher Denter
parents:
diff changeset
3 MoinMoin - migrate from several twikidraw files to one tarfile.
4122e38d9582 add simple script that converts the several elements of one twikidraw item into one tar archive. the script needs further love and integration
Christopher Denter
parents:
diff changeset
4
4122e38d9582 add simple script that converts the several elements of one twikidraw item into one tar archive. the script needs further love and integration
Christopher Denter
parents:
diff changeset
5 This script looks at all pages' attachments and checks whether they
4122e38d9582 add simple script that converts the several elements of one twikidraw item into one tar archive. the script needs further love and integration
Christopher Denter
parents:
diff changeset
6 contain TWikiDraw items. If this is the case, the TWikiDraw items are
4440
847d257bee5f twikidraw mig script: use .tdraw for the tar file, get rid of .gif
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4436
diff changeset
7 bundled into a single tar file (.tdraw) on the disk.
4436
4122e38d9582 add simple script that converts the several elements of one twikidraw item into one tar archive. the script needs further love and integration
Christopher Denter
parents:
diff changeset
8 (The intention is to later store this as a single Item in the new storage
4122e38d9582 add simple script that converts the several elements of one twikidraw item into one tar archive. the script needs further love and integration
Christopher Denter
parents:
diff changeset
9 layer.)
4122e38d9582 add simple script that converts the several elements of one twikidraw item into one tar archive. the script needs further love and integration
Christopher Denter
parents:
diff changeset
10
4122e38d9582 add simple script that converts the several elements of one twikidraw item into one tar archive. the script needs further love and integration
Christopher Denter
parents:
diff changeset
11 @copyright: 2008 by Christopher Denter
4122e38d9582 add simple script that converts the several elements of one twikidraw item into one tar archive. the script needs further love and integration
Christopher Denter
parents:
diff changeset
12 @license: GNU GPL, see COPYING for details.
4122e38d9582 add simple script that converts the several elements of one twikidraw item into one tar archive. the script needs further love and integration
Christopher Denter
parents:
diff changeset
13
4122e38d9582 add simple script that converts the several elements of one twikidraw item into one tar archive. the script needs further love and integration
Christopher Denter
parents:
diff changeset
14 """
4122e38d9582 add simple script that converts the several elements of one twikidraw item into one tar archive. the script needs further love and integration
Christopher Denter
parents:
diff changeset
15
4440
847d257bee5f twikidraw mig script: use .tdraw for the tar file, get rid of .gif
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4436
diff changeset
16 import os, errno
6104
68f8bea727e5 remove usage of MoinMoin.support.tarfile
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5091
diff changeset
17 import tarfile
4436
4122e38d9582 add simple script that converts the several elements of one twikidraw item into one tar archive. the script needs further love and integration
Christopher Denter
parents:
diff changeset
18
4122e38d9582 add simple script that converts the several elements of one twikidraw item into one tar archive. the script needs further love and integration
Christopher Denter
parents:
diff changeset
19 from MoinMoin.action.AttachFile import getAttachDir
4122e38d9582 add simple script that converts the several elements of one twikidraw item into one tar archive. the script needs further love and integration
Christopher Denter
parents:
diff changeset
20
4122e38d9582 add simple script that converts the several elements of one twikidraw item into one tar archive. the script needs further love and integration
Christopher Denter
parents:
diff changeset
21
4122e38d9582 add simple script that converts the several elements of one twikidraw item into one tar archive. the script needs further love and integration
Christopher Denter
parents:
diff changeset
22 def execute(script, data_dir, rev):
4122e38d9582 add simple script that converts the several elements of one twikidraw item into one tar archive. the script needs further love and integration
Christopher Denter
parents:
diff changeset
23 pagenames = script.request.rootpage.getPageList(user='', include_underlay=False)
4122e38d9582 add simple script that converts the several elements of one twikidraw item into one tar archive. the script needs further love and integration
Christopher Denter
parents:
diff changeset
24
4122e38d9582 add simple script that converts the several elements of one twikidraw item into one tar archive. the script needs further love and integration
Christopher Denter
parents:
diff changeset
25 for pagename in pagenames:
4122e38d9582 add simple script that converts the several elements of one twikidraw item into one tar archive. the script needs further love and integration
Christopher Denter
parents:
diff changeset
26 attachdir = getAttachDir(script.request, pagename)
4122e38d9582 add simple script that converts the several elements of one twikidraw item into one tar archive. the script needs further love and integration
Christopher Denter
parents:
diff changeset
27 try:
4440
847d257bee5f twikidraw mig script: use .tdraw for the tar file, get rid of .gif
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4436
diff changeset
28 drawings = [fn for fn in os.listdir(attachdir) if fn.endswith('.draw')]
4436
4122e38d9582 add simple script that converts the several elements of one twikidraw item into one tar archive. the script needs further love and integration
Christopher Denter
parents:
diff changeset
29 except OSError:
4122e38d9582 add simple script that converts the several elements of one twikidraw item into one tar archive. the script needs further love and integration
Christopher Denter
parents:
diff changeset
30 # silenced. attachment directory does not exist. proceed with next page
4122e38d9582 add simple script that converts the several elements of one twikidraw item into one tar archive. the script needs further love and integration
Christopher Denter
parents:
diff changeset
31 continue
4440
847d257bee5f twikidraw mig script: use .tdraw for the tar file, get rid of .gif
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4436
diff changeset
32 for drawing in drawings:
847d257bee5f twikidraw mig script: use .tdraw for the tar file, get rid of .gif
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4436
diff changeset
33 basename = os.path.splitext(drawing)[0]
847d257bee5f twikidraw mig script: use .tdraw for the tar file, get rid of .gif
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4436
diff changeset
34 tar_filename = os.path.join(attachdir, basename + '.tdraw')
847d257bee5f twikidraw mig script: use .tdraw for the tar file, get rid of .gif
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4436
diff changeset
35 tar = tarfile.open(tar_filename, 'w:')
847d257bee5f twikidraw mig script: use .tdraw for the tar file, get rid of .gif
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4436
diff changeset
36 for ext in ['.draw', '.map', '.png', '.gif', ]:
847d257bee5f twikidraw mig script: use .tdraw for the tar file, get rid of .gif
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4436
diff changeset
37 filename = os.path.join(attachdir, basename + ext)
4436
4122e38d9582 add simple script that converts the several elements of one twikidraw item into one tar archive. the script needs further love and integration
Christopher Denter
parents:
diff changeset
38 try:
4440
847d257bee5f twikidraw mig script: use .tdraw for the tar file, get rid of .gif
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4436
diff changeset
39 if ext != '.gif':
847d257bee5f twikidraw mig script: use .tdraw for the tar file, get rid of .gif
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4436
diff changeset
40 # get rid of the gif (TWikiDraw will (re)create
847d257bee5f twikidraw mig script: use .tdraw for the tar file, get rid of .gif
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4436
diff changeset
41 # a .png when someone edits the drawing)
5091
6cfcb25278a7 adapt the migration script to use drawing.* as member file names within the .tdraw container files
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4440
diff changeset
42 # we use drawing.* as tar member filenames EVER, so the
6cfcb25278a7 adapt the migration script to use drawing.* as member file names within the .tdraw container files
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4440
diff changeset
43 # member filenames do not need to be changed when the
6cfcb25278a7 adapt the migration script to use drawing.* as member file names within the .tdraw container files
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4440
diff changeset
44 # tar container file gets renamed:
6cfcb25278a7 adapt the migration script to use drawing.* as member file names within the .tdraw container files
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4440
diff changeset
45 tar.add(filename, 'drawing' + ext)
4440
847d257bee5f twikidraw mig script: use .tdraw for the tar file, get rid of .gif
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4436
diff changeset
46 os.remove(filename)
847d257bee5f twikidraw mig script: use .tdraw for the tar file, get rid of .gif
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4436
diff changeset
47 except OSError, err:
847d257bee5f twikidraw mig script: use .tdraw for the tar file, get rid of .gif
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4436
diff changeset
48 if err.errno != errno.ENOENT:
847d257bee5f twikidraw mig script: use .tdraw for the tar file, get rid of .gif
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4436
diff changeset
49 # .map and .png are optional, .draw should be there
847d257bee5f twikidraw mig script: use .tdraw for the tar file, get rid of .gif
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4436
diff changeset
50 raise
847d257bee5f twikidraw mig script: use .tdraw for the tar file, get rid of .gif
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4436
diff changeset
51 tar.close()
4436
4122e38d9582 add simple script that converts the several elements of one twikidraw item into one tar archive. the script needs further love and integration
Christopher Denter
parents:
diff changeset
52
4122e38d9582 add simple script that converts the several elements of one twikidraw item into one tar archive. the script needs further love and integration
Christopher Denter
parents:
diff changeset
53 return 1090000
4440
847d257bee5f twikidraw mig script: use .tdraw for the tar file, get rid of .gif
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4436
diff changeset
54