3
MoinMoin - Push files into the wiki.
5
This script pushes files from a directory into the wiki. It is usable in order
6
to mirror IRC logs for example.
8
@copyright: 2005 by MoinMoin:AlexanderSchremmer
9
@license: GNU GPL, see COPYING for details.
13
# the request URL, important for farm configurations
14
url = "moinmoin.wikiwikiweb.de/"
16
# the author, visible in RecentChanges etc.
17
author = "IrcLogImporter"
19
# the directory that should be pushed
20
local_dir = '/home/aschremmer/channel-logging/logs/ChannelLogger/freenode/#moin-dev'
22
# basepage of the pushed files
23
base_page = 'MoinMoinChat/Logs/'
25
# this function generates a pagename from the file name
26
def filename_function(filename):
27
filename = filename.lstrip('#')
28
splitted = filename.split('.')
29
return '/'.join(splitted[0:2])
30
### end of configuration
33
sys.path.insert(0, '/srv/moin_tw/moin--main--1.5')
34
sys.path.insert(0, '/srv/de.wikiwikiweb.moinmaster/bin15')
36
from MoinMoin import wikiutil
37
from MoinMoin.request import RequestCLI
38
from MoinMoin.PageEditor import PageEditor
40
def decodeLinewise(text):
42
for line in text.splitlines():
44
decoded_line = line.decode("utf-8")
45
except UnicodeDecodeError:
46
decoded_line = line.decode("iso-8859-1")
47
resultList.append(decoded_line)
48
return '\n'.join(resultList)
50
request = RequestCLI(url=url) #pagename necessary here?
52
for root, dirs, files in os.walk(local_dir):
54
for filename in files[:-1]: # do not push the last file as it is constantly written to
55
pagename = base_page + filename_function(filename)
56
print "Pushing %r as %r" % (filename, pagename)
57
p = PageEditor(request, pagename,
58
do_editor_backup=0, uid_override=author)
62
fileObj = open(os.path.join(root, filename), 'rb')
64
p.saveText("#format plain\n" + decodeLinewise(fileObj.read()), 0)
65
except PageEditor.SaveError, e:
66
print "Got %r" % (e, )