comparison MoinMoin/scripts/reducewiki/reducewiki.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 2202f548cbb0
comparison
equal deleted inserted replaced
-1:000000000000 0:77665d8e2254
1 #!/usr/bin/env python
2 """
3 Use this script to reduce a data/ directory to the latest page revision of
4 each non-deleted page.
5 This is used to make the distributed underlay directory, but can also be
6 used for other purposes.
7
8 So we change like this:
9 * data/pages/PageName/revisions/{1,2,3,4}
10 -> data/pages/revisions/1
11 * data/pages/PageName/current (pointing to e.g. 4)
12 -> same (pointing to 1)
13 * data/pages/PageName/edit-log and data/edit-log
14 -> do not copy
15
16 Steps for a successful conversion:
17
18 1. Stop your wiki and make a backup of old data and code
19
20 2. Make a copy of the wiki's "data" directory to your working dir
21
22 3. Run this script from your working dir
23
24 4. If there was no error, you will find:
25 data.pre-reduce - the script renames your data directory copy to that name
26 data - reduced data dir
27
28 5. Verify conversion results (number of pages, ...)
29
30 6. Test it - if something has gone wrong, you still have your backup.
31
32
33 @copyright: 2004 Thomas Waldmann
34 @license: GPL, see COPYING for details
35 """
36
37 url = 'moinmaster.wikiwikiweb.de/'
38 destdir = 'underlay'
39
40 import sys
41 sys.path.insert(0, '/org/de.wikiwikiweb.moinmaster/bin') # farmconfig/wikiconfig location
42 sys.path.insert(0, '../../..')
43
44 import os.path, urllib, codecs
45 from MoinMoin import config
46 from MoinMoin import wikiutil
47 from MoinMoin.request import RequestCLI
48 from MoinMoin.Page import Page
49 from MoinMoin.PageEditor import PageEditor
50
51 def makepage(rootdir, pagename, text):
52 """quick and dirty!"""
53 pagedir = os.path.join(rootdir, 'pages', wikiutil.quoteWikinameFS(pagename))
54 os.makedirs(pagedir)
55
56 revstr = '%08d' % 1
57 cf = os.path.join(pagedir, 'current')
58 open(cf, 'w').write(revstr+'\n')
59
60 revdir = os.path.join(pagedir, 'revisions')
61 os.makedirs(revdir)
62 tf = os.path.join(revdir, revstr)
63 text = text.replace("\n","\r\n")
64 codecs.open(tf, 'wb', config.charset).write(text)
65
66 request = RequestCLI(url=url)
67 request.form = request.args = request.setup_args()
68
69 pagelist = list(request.rootpage.getPageList(user=''))
70 for pagename in pagelist:
71 p = Page(request, pagename)
72 text = p.get_raw_body()
73 makepage(destdir, pagename, text)
74
75