Copy files from one MoinMoin instance to another:

This is a script that will copy data files from one wiki instance to another, including files that file links to. Caveats:

Here it is:

import re,sys,shutil,os
linkReg = re.compile(r'\["(?P<link>.+?)\"]')
replaceDict = {" ":"_20", "?":"_3f"}
def copyWiki(filename):
    source="/usr/share/moin/wpwiki"
    dest="/usr/share/moin/rgwiki"
    dataDir = "data/text"

    sourcefile = os.path.join(source,dataDir,filename)
    destfile = os.path.join(dest,dataDir,filename)
    if os.path.exists(destfile):
        print "%s already exists" %destfile
        return
    newpages = []
    source = file(sourcefile)
    for line in source:
        match = linkReg.search(line)
        if match:
            page = match.group('link')
            for key in replaceDict:
                page = page.replace(key,replaceDict[key])

            newpages.append(page)
    source.close()
    filestats = os.stat(sourcefile)
    shutil.copy2(sourcefile,destfile)
    os.chown(destfile,filestats.st_uid,filestats.st_gid)
    map(copyWiki,newpages)

startFile = sys.argv[1]
copyWiki(startFile)

MoinMoin: ScriptMarket/CopyBetweenInstances (last edited 2007-10-29 19:14:33 by localhost)