Helge Joao
unread,Sep 5, 2008, 8:22:13 AM9/5/08Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to wikidpad-devel
Just in case somebody might be interested in future, here blurbs of my
further migration. Works only smoothly for headings up to five pluses.
Above that it looks a little ugly, but otherwise is fine.
Python-script to convert an original-sqlite-wiki to the reversed
heading syntax:
#!/usr/bin/python
# -*- coding: iso-8859-15 -*-
import os, os.path, string, re
filenameEndingDefault=".wiki"
startDirDefault=r"C:/Ho/vv/IriKopie/" # Put the directory here where
your *.wiki-files are. Slash at the end!!! (no backslash, not even on
MS Windows!)
def replaceStrings(s):
s=re.compile(r"^\+{2}(?!\+)").sub("²²²²²",s)
s=re.compile(r"^\+{3}(?!\+)").sub("²²²²",s)
s=re.compile(r"^\+{4}(?!\+)").sub("²²²",s)
s=re.compile(r"^\+{5}(?!\+)").sub("²²",s)
s=re.compile(r"^\+{6}(?!\+)").sub("²²( +heading)",s) # These should
not be needed. Just in case make it transparant.
s=re.compile(r"^\+{7}(?!\+)").sub("²²( 0+heading)",s)
s=re.compile(r"^\+{8}(?!\+)").sub("²²(-1+heading)",s)
s=re.compile(r"^\+{9}(?!\+)").sub("²²(-2+heading)",s)
s=re.compile(r"^\+{10}(?!\+)").sub("²²(-3+heading)",s)
s=string.replace(s,r"²",r"+")
return s
def replace(file):
temp = os.path.splitext(file)[0] + ".tmp"
try:
# remove old temp file, if any
os.remove(temp)
except os.error:
pass
fi = open(file)
fo = open(temp, "w")
for s in fi.readlines():
fo.write(replaceStrings(s))
fi.close()
fo.close()
os.remove(file)
os.rename(temp, file)
def
doit(startDir=startDirDefault,filenameEnding=filenameEndingDefault):
directories = [startDir]
while len(directories)>0:
directory = directories.pop()
for name in os.listdir(directory):
fullpath = os.path.join(directory,name)
if fullpath.endswith(filenameEnding) and
os.path.isfile(fullpath):
print fullpath # That's a file. Do
something with it.
replace(fullpath)
elif os.path.isdir(fullpath):
directories.append(fullpath) # It's a directory, store
it.
if __name__ == '__main__':
import sys
if len(sys.argv[1:])>0:
raise SystemExit, "Error: The target dir must be set inside the
python source. Command line args are forbidden."
doit()
print "replacer has finished"