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

« back to all changes in this revision

Viewing changes to MoinMoin/script/maint/globaledit.py

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2008-06-22 21:17:13 UTC
  • mfrom: (0.9.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080622211713-fpo2zrq3s5dfecxg
Tags: 1.7.0-3
Simplify /etc/moin/wikilist format: "USER URL" (drop unneeded middle
CONFIG_DIR that was wrongly advertised as DATA_DIR).  Make
moin-mass-migrate handle both formats and warn about deprecation of
the old one.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: iso-8859-1 -*-
2
 
"""
3
 
    MoinMoin - do global changes to all pages in a wiki.
4
 
 
5
 
    The changes being done are hardcoded in function do_edit.
6
 
    As it is, this script is mostly useful for the MoinMoin release maintainer
7
 
    using: moin ... --wiki-url=moinmaster.wikiwikiweb.de/ maint globaledit
8
 
    
9
 
    @copyright: 2004-2006 by MoinMoin:ThomasWaldmann
10
 
    @license: GNU GPL, see COPYING for details.
11
 
"""
 
1
# -*- coding: utf-8 -*-
 
2
"""
 
3
MoinMoin - do global changes to all pages in a wiki.
 
4
 
 
5
@copyright: 2004-2006 MoinMoin:ThomasWaldmann
 
6
@license: GNU GPL, see COPYING for details.
 
7
"""
 
8
 
12
9
debug = False
13
10
 
14
11
from MoinMoin import PageEditor
15
 
from MoinMoin.script._util import MoinScript
 
12
from MoinMoin.script import MoinScript
16
13
 
17
14
class PluginScript(MoinScript):
 
15
    """\
 
16
Purpose:
 
17
========
 
18
This tool allows you to edit all the pages in a wiki.
 
19
 
 
20
Detailed Instructions:
 
21
======================
 
22
General syntax: moin [options] maint globaledit [globaledit-options]
 
23
 
 
24
[options] usually should be:
 
25
    --config-dir=/path/to/my/cfg/ --wiki-url=wiki.example.org/
 
26
 
 
27
[globaledit-options] see below:
 
28
    0. The changes that will be performed are hardcoded in the function
 
29
       do_edit.
 
30
 
 
31
    1. This script takes no command line arguments.
 
32
"""
 
33
 
18
34
    def __init__(self, argv, def_values):
19
35
        MoinScript.__init__(self, argv, def_values)
20
 
    
 
36
 
21
37
    def do_edit(self, pagename, origtext):
22
 
        if pagename in ['LocalSpellingWords', 'LocalBadContent',] or pagename.endswith('Template'):
 
38
        if pagename in ['LocalSpellingWords', 'LocalBadContent', ]:
23
39
            return origtext
24
40
        language_line = format_line = masterpage = None
25
41
        acl_lines = []
40
56
                elif l.startswith('#format '):
41
57
                    format_line = l
42
58
                elif l.startswith('##master-page:'):
43
 
                    masterpage = l.split(':',1)[1].strip()
 
59
                    masterpage = l.split(':', 1)[1].strip()
44
60
                    master_lines.append(l)
45
61
                elif l.startswith('##master-date:'):
46
62
                    master_lines.append(l)
47
 
                elif l.startswith('##acl'):
48
 
                    pass # throw away
49
63
                elif l.startswith('##'):
50
64
                    comment_lines.append(l)
51
65
                elif l.startswith('#'):
57
71
            language_line = '#language en'
58
72
        if not format_line:
59
73
            format_line = '#format wiki'
 
74
        aclold = '#acl MoinPagesEditorGroup:read,write,delete,revert All:read'
 
75
        if aclold in acl_lines:
 
76
            acl_lines.remove(aclold)
60
77
        if not acl_lines and (
61
 
            masterpage is None or masterpage not in ['FrontPage', 'WikiSandBox',] and not masterpage.endswith('Template')):
62
 
            acl_lines = ['#acl MoinPagesEditorGroup:read,write,delete,revert All:read']
 
78
            masterpage is None and not pagename.endswith('Template') or
 
79
            masterpage not in ['FrontPage', 'WikiSandBox', ] and not (pagename.endswith('Template') or masterpage.endswith('Template'))):
 
80
            acl_lines = ['#acl -All:write Default']
63
81
        if not master_lines:
64
 
            master_lines = ['##master-page:Unknown-Page', '##master-date:Unknown-Date',]
 
82
            master_lines = ['##master-page:Unknown-Page', '##master-date:Unknown-Date', ]
65
83
 
66
 
        c1old = "## Please edit (or translate) system/help pages on the moinmaster wiki ONLY."
67
 
        c2old = "## For more information, please see MoinMaster:MoinPagesEditorGroup."
68
 
        c1 = "## Please edit system and help pages ONLY in the moinmaster wiki! For more"
69
 
        c2 = "## information, please see MoinMaster:MoinPagesEditorGroup."
70
 
        for c in (c1old, c2old, c1, c2):
 
84
        cold = [u"## Please edit system and help pages ONLY in the moinmaster wiki! For more",
 
85
                u"## information, please see MoinMaster:MoinPagesEditorGroup.",
 
86
        ]
 
87
        cnew = [u"## Please edit system and help pages ONLY in the master wiki!",
 
88
                u"## For more information, please see MoinMoin:MoinDev/Translation.",
 
89
        ]
 
90
        for c in cold + cnew:
71
91
            if c in comment_lines:
72
92
                comment_lines.remove(c)
73
 
            
74
 
        comment_lines = [c1, c2, ] + comment_lines
 
93
 
 
94
        comment_lines = cnew + comment_lines
75
95
 
76
96
        if content_lines and content_lines[-1].strip(): # not an empty line at EOF
77
97
            content_lines.append('')
78
98
 
79
99
        if masterpage and masterpage.endswith('Template'):
80
 
            changedtext = master_lines + [format_line, language_line,] + pragma_lines + content_lines
 
100
            changedtext = master_lines + [format_line, language_line, ] + pragma_lines + content_lines
81
101
        else:
82
 
            changedtext = comment_lines + master_lines + acl_lines + [format_line, language_line,] + pragma_lines + content_lines
 
102
            changedtext = comment_lines + master_lines + acl_lines + [format_line, language_line, ] + pragma_lines + content_lines
83
103
        changedtext = '\n'.join(changedtext)
84
104
        return changedtext
85
105
 
87
107
        if debug:
88
108
            import codecs
89
109
            origtext = codecs.open('origtext', 'r', 'utf-8').read()
90
 
            origtext = origtext.replace('\r\n','\n')
 
110
            origtext = origtext.replace('\r\n', '\n')
91
111
            changedtext = self.do_edit("", origtext)
92
 
            changedtext = changedtext.replace('\n','\r\n')
 
112
            changedtext = changedtext.replace('\n', '\r\n')
93
113
            f = codecs.open('changedtext', 'w', 'utf-8')
94
114
            f.write(changedtext)
95
115
            f.close()
101
121
            pagelist = request.rootpage.getPageList(user='')
102
122
 
103
123
            for pagename in pagelist:
104
 
                #request = RequestCLI(url=url, pagename=pagename.encode('utf-8'))
 
124
                #request = CLI.Request(url=url, pagename=pagename.encode('utf-8'))
105
125
                p = PageEditor.PageEditor(request, pagename, do_editor_backup=0)
106
126
                origtext = p.get_raw_body()
107
127
                changedtext = self.do_edit(pagename, origtext)