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:
- The character replacement isn't complete -- it only replaces space with _20 and ? with _3f. Adding more is trivial.
- the source and destination directories are hard-coded. Change them before you use it.
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)