comparison MoinMoin/scripts/migration/12_to_13_mig10.py @ 0:77665d8e2254

tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0 (automatically generated log message) imported from: moin--main--1.5--base-0
author Thomas Waldmann <tw-public@gmx.de>
date Thu, 22 Sep 2005 15:09:50 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:77665d8e2254
1 #!/usr/bin/env python
2 """
3 migration from moin 1.3 < patch-xxx to moin 1.3 >= patch-xxx
4 We fix 2 issues here:
5 * we forgot to handle edit-lock files. We simply delete them now.
6 * we convert attachment names to utf-8
7
8 Steps for a successful migration:
9
10 1. Stop your wiki and make a backup of old data and code
11
12 2. Make a copy of the wiki's "data" directory to your working dir
13
14 3. make sure that from_encoding and to_encoding matches your needs (see
15 beginning of script below and config.charset in moin_config.py) and
16 run python2.3 12_to_13_mig10.py from your working dir
17
18 4. If there was no error, you will find:
19 data.pre-mig10 - the script renames your data directory copy to that name
20 data - converted data dir
21
22 5. Verify conversion results (number of pages, size of logs, attachments,
23 number of backup copies) - everything should be reasonable before
24 you proceed.
25
26 6. Copy additional files from data.pre-mig10 to data (maybe intermaps, logs,
27 etc.). Be aware that the file contents AND file names of wiki content
28 may have changed, so DO NOT copy the files inside the cache/ directory,
29 let the wiki refill it.
30
31 7. Replace the data directory your wiki uses with the data directory
32 you created by previous steps. DO NOT simply copy the converted stuff
33 into the original or you will duplicate pages and create chaos!
34
35 8. Test it - if something has gone wrong, you still have your backup.
36
37
38 @copyright: 2005 Thomas Waldmann
39 @license: GPL, see COPYING for details
40 """
41
42 from_encoding = 'iso8859-1'
43 #from_encoding = 'utf-8'
44
45 to_encoding = 'utf-8'
46
47 import os, os.path, sys, urllib
48
49 # Insert THIS moin dir first into sys path, or you would run another
50 # version of moin!
51 sys.path.insert(0, '../../..')
52 from MoinMoin import wikiutil
53
54 from migutil import opj, listdir, copy_file, move_file, copy_dir
55
56 def migrate(dir_to):
57 """ this removes edit-lock files from the pagedirs and
58 converts attachment filenames
59 """
60 pagesdir = opj(dir_to, 'pages')
61 pagelist = listdir(pagesdir)
62 for pagename in pagelist:
63 pagedir = opj(pagesdir, pagename)
64 editlock = opj(pagedir, 'edit-lock')
65 try:
66 os.remove(editlock)
67 except:
68 pass
69
70 attachdir = os.path.join(pagedir, 'attachments')
71 for root, dirs, files in os.walk(attachdir):
72 for f in files:
73 try:
74 f.decode(to_encoding)
75 except UnicodeDecodeError:
76 fnew = f.decode(from_encoding).encode(to_encoding)
77 os.rename(os.path.join(root,f), os.path.join(root, fnew))
78 print 'renamed', f, '\n ->', fnew, ' in dir:', root
79
80
81 origdir = 'data.pre-mig10'
82 destdir = 'data'
83
84 # Backup original dir and create new empty dir
85 try:
86 os.rename(destdir, origdir)
87 except OSError:
88 print "You need to be in the directory where your copy of the 'data' directory is located."
89 sys.exit(1)
90
91 copy_dir(origdir, destdir)
92 migrate(destdir)
93
94