view MoinMoin/scripts/import/ @ 241:27757d338074

Modified filename_function, really. imported from: moin--main--1.5--patch-244
author Alexander Schremmer <>
date Sun, 27 Nov 2005 11:16:27 +0000
parents 983e3a3a9b9e
line wrap: on
line source

MoinMoin - Push files into the wiki.

This script pushes files from a directory into the wiki. It is usable in order
to mirror IRC logs for example.

    @copyright: 2005 by MoinMoin:AlexanderSchremmer
    @license: GNU GPL, see COPYING for details.

### Configuration
# the request URL, important for farm configurations
url = ""

# the author, visible in RecentChanges etc.
author = "WikiSyncronisationDaemon"

# the directory that should be pushed
local_dir = '/home/aschremmer/channel-logging/logs/ChannelLogger/freenode/#moin-dev'

# basepage of the pushed files
base_page = 'MoinMoinChat/Logs/'

# this function generates a pagename from the file name
def filename_function(filename):
    splitted = filename.split('.')
    return '/'.join([splitted[0]] + [x.replace('-', '/') for x in splitted[1:-1]])
### end of configuration

import os, sys

from MoinMoin import wikiutil
from MoinMoin.request import RequestCLI
from MoinMoin.PageEditor import PageEditor

def decodeLinewise(text):
    resultList = []

    for line in text.splitlines():
            decoded_line = line.decode("utf-8")
        except UnicodeDecodeError:
            decoded_line = line.decode("iso-8859-1")

    return '\n'.join(resultList)

request = RequestCLI(url=url) #pagename necessary here?

for root, dirs, files in os.walk(local_dir):
    for filename in files[:-1]: # do not push the last file as it is constantly written to
        pagename = base_page + filename_function(filename)
        print "Pushing %r as %r" % (filename, pagename)
        p = PageEditor(request, pagename,
                       do_editor_backup=0, uid_override=author)
        if p.exists():
        fileObj = open(os.path.join(root, filename), 'rb')
            p.saveText("#format plain\n" + decodeLinewise(, 0)
        except PageEditor.SaveError, e:
            print "Got %r" % (e, )

print "Finished."