1
1
# -*- coding: iso-8859-1 -*-
3
MoinMoin - Push files into the wiki.
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
8
One application is to use it to store IRC logs into the wiki.
11
moin --config-dir=... --wiki-url=... import irclog --author=IrcLogImporter --file-dir=.
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.
5
@copyright: 2005-2007 MoinMoin:AlexanderSchremmer
6
2006 MoinMoin:ThomasWaldmann
7
@license: GNU GPL, see COPYING for details.
18
10
# this function generates a pagename from the file name
21
13
splitted = filename.split('.')
22
14
return '/'.join(splitted[0:2])
16
class IAmRoot(object):
17
def __getattr__(self, name):
18
return lambda *args, **kwargs: True
26
23
from MoinMoin.PageEditor import PageEditor
27
from MoinMoin.script._util import MoinScript
24
from MoinMoin.script import MoinScript
29
26
def decodeLinewise(text):
40
37
class PluginScript(MoinScript):
41
""" irclog importer script class """
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
44
One application is to use it to store IRC logs into the wiki.
46
Detailed Instructions:
47
======================
48
General syntax: moin [options] import irclog [irclog-options]
50
[options] usually should be:
51
--config-dir=/path/to/my/cfg/ --wiki-url=wiki.example.org/
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=.
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"
68
self.parser.add_option("--acl", dest="acl", default="", help="Set a specific ACL for the pages.")
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):
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)
82
if filename != files[-1]:
85
p = PageEditor(request, pagename, do_editor_backup=0, uid_override=self.options.author)
65
87
fileObj = open(os.path.join(root, filename), 'rb')
67
p.saveText("#format plain\n" + decodeLinewise(fileObj.read()), 0)
91
acl = "#acl %s\n" % (self.options.acl, )
92
p.saveText(acl + "#format plain\n" + decodeLinewise(fileObj.read()), 0)
93
except PageEditor.Unchanged, e:
68
95
except PageEditor.SaveError, e:
69
96
print "Got %r" % (e, )