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

« back to all changes in this revision

Viewing changes to MoinMoin/script/import/irclog.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
1
# -*- coding: iso-8859-1 -*-
2
2
"""
3
 
    MoinMoin - Push files into the wiki.
4
 
 
5
 
    This script pushes files from a directory into the wiki (to be exact: it
6
 
    pushes all except the last file, as this is maybe still written to in
7
 
    case of irc logs).
8
 
    One application is to use it to store IRC logs into the wiki.
9
 
 
10
 
    Usage:
11
 
    moin --config-dir=... --wiki-url=... import irclog --author=IrcLogImporter --file-dir=.
12
 
    
13
 
    @copyright: 2005 by MoinMoin:AlexanderSchremmer
14
 
                2006 by MoinMoin:ThomasWaldmann
15
 
    @license: GNU GPL, see COPYING for details.
 
3
MoinMoin - Push files into the wiki.
 
4
 
 
5
@copyright: 2005-2007 MoinMoin:AlexanderSchremmer
 
6
            2006 MoinMoin:ThomasWaldmann
 
7
@license: GNU GPL, see COPYING for details.
16
8
"""
17
9
 
18
10
# this function generates a pagename from the file name
21
13
    splitted = filename.split('.')
22
14
    return '/'.join(splitted[0:2])
23
15
 
 
16
class IAmRoot(object):
 
17
    def __getattr__(self, name):
 
18
        return lambda *args, **kwargs: True
 
19
 
 
20
 
24
21
import os
25
22
 
26
23
from MoinMoin.PageEditor import PageEditor
27
 
from MoinMoin.script._util import MoinScript
 
24
from MoinMoin.script import MoinScript
28
25
 
29
26
def decodeLinewise(text):
30
27
    resultList = []
38
35
 
39
36
 
40
37
class PluginScript(MoinScript):
41
 
    """ irclog importer script class """
 
38
    """\
 
39
Purpose:
 
40
========
 
41
This script pushes files from a directory into the wiki (to be exact: it
 
42
pushes all except the last file, as this is maybe still written to in
 
43
case of irc logs).
 
44
One application is to use it to store IRC logs into the wiki.
 
45
 
 
46
Detailed Instructions:
 
47
======================
 
48
General syntax: moin [options] import irclog [irclog-options]
 
49
 
 
50
[options] usually should be:
 
51
    --config-dir=/path/to/my/cfg/ --wiki-url=wiki.example.org/
 
52
 
 
53
[irclog-options] see below:
 
54
    0. To add all the files in the current directory to the wiki as the user 'JohnSmith'
 
55
       moin ... import irclog --author=JohnSmirh --file-dir=.
 
56
"""
42
57
 
43
58
    def __init__(self, argv, def_values):
44
59
        MoinScript.__init__(self, argv, def_values)
50
65
            "--file-dir", dest="file_dir", default='.',
51
66
            help="read files from DIRECTORY"
52
67
        )
53
 
    
 
68
        self.parser.add_option("--acl", dest="acl", default="", help="Set a specific ACL for the pages.")
 
69
 
54
70
    def mainloop(self):
55
71
        self.init_request()
56
72
        request = self.request
 
73
        request.user.may = IAmRoot()
 
74
        request.cfg.mail_enabled = False
57
75
        for root, dirs, files in os.walk(self.options.file_dir):
58
76
            files.sort()
59
 
            for filename in files[:-1]: # do not push the last file as it is constantly written to
 
77
            for filename in files:
60
78
                pagename = self.options.page + filename_function(filename)
61
 
                print "Pushing %r as %r" % (filename, pagename)
62
 
                p = PageEditor(request, pagename, do_editor_backup=0, uid_override=self.options.author)
 
79
                #print "Pushing %r as %r" % (filename, pagename)
 
80
                p = PageEditor(request, pagename, do_editor_backup=0, uid_override=self.options.author, do_revision_backup=0)
63
81
                if p.exists():
64
 
                    continue
 
82
                    if filename != files[-1]:
 
83
                        continue
 
84
                else:
 
85
                    p = PageEditor(request, pagename, do_editor_backup=0, uid_override=self.options.author)
 
86
 
65
87
                fileObj = open(os.path.join(root, filename), 'rb')
66
88
                try:
67
 
                    p.saveText("#format plain\n" + decodeLinewise(fileObj.read()), 0)
 
89
                    acl = ""
 
90
                    if self.options.acl:
 
91
                        acl = "#acl %s\n" % (self.options.acl, )
 
92
                    p.saveText(acl + "#format plain\n" + decodeLinewise(fileObj.read()), 0)
 
93
                except PageEditor.Unchanged, e:
 
94
                    pass
68
95
                except PageEditor.SaveError, e:
69
96
                    print "Got %r" % (e, )
70
97
                fileObj.close()
71
 
        print "Finished."
 
98
        #print "Finished."
72
99