1263135717 ::1 C informatique:systemes_visualisation Wolverine créée 1263135717:: 1 C computer: Wolverine created systemes_visualisation
1263135988 ::1 E informatique:systemes_visualisation Wolverine 1263135988:: 1 E it: Wolverine systemes_visualisation
1263136423 ::1 E informatique:systemes_visualisation Wolverine 1263136423:: E a computer: Wolverine systemes_visualisation
Explanation :
- the first column is a Unix Timestamp ,
- the second is the IP address (I'm working on localhost ;-))
- the third is the action performed (C created, E edited ,...)
- the fourth is straightforward,
- the fifth is the ID of the person who modified the page
- and the last column is the smallest text you can perform when you edit a page ...
To start it, nothing more simple, launch the script in yout dokuwiki directory :
#!/bin/python
"""
This program parse logs of a dokuwiki
and tranform them for gource (a log viewer)
http://code.google.com/p/gource/
developped by WolverineX02
site : http://wolverinex02.blogspot.com
"""
import os.path
import getopt
import sys
import re
def listdirectory2(path):
"""list all the files like *.changes,
read them and output them in gource's log syntax
"""
for root, dirs, files in os.walk(path):
for i in files:
if (re.search('\.changes$', i)):
fichier = os.path.join(root, i)
myfile = open(fichier, 'r')
for line in myfile.readlines():
mots = line.split()
if len(mots)>=5:
resultat = mots[0] + "|"
resultat += mots[4] + "|"
resultat += translate(mots[2]) + "|"
resultat += fichier
print resultat
elif len(mots)==4:
resultat = mots[0] + "|Anonymous|"
resultat += translate(mots[2]) + "|"
resultat += fichier
print resultat
myfile.close()
def translate(mot):
"""translate the dokuwiki vocabulary to the gource one
C -> A
E -> M
other -> M
"""
if mot == "C":
return "A"
elif mot == "E":
return "M"
else:
return "M"
def main(argv):
"""principal function
"""
try:
opts, args = getopt.getopt(argv, "hd:", ["help", "dokuwiki="])
except getopt.GetoptError:
usage()
sys.exit(2)
for opt, arg in opts:
if opt in ("-h","--help"):
usage()
sys.exit()
elif opt in ("-d","--dokuwiki"):
print listdirectory2(arg)
def usage():
"""this function will display how to use this script
"""
print "This script will output change logs of a dokuwiki"
print "in a friendly way for gource"
print "how to use it :"
print "python gourcedoku.py -d ~/Sites/MyDokuwiki/ | sort > dokusort.log"
print "and then :"
print "gource --log-format custom dokusort.log --stop-position 1.0 \ "
print "--stop-on-idle --file-idle-time 10000000"
print "---"
print "-h : help "
print "-d : meta directory of your dokuwiki"
if __name__ == "__main__":
main(sys.argv[1:])
python gourcedoku.py -d ~/Sites/MyDokuwiki/ | sort > dokusort.logthen view the result with Gource with the following command:
gource --log-format custom dokusort.log --stop-position 1.0 --stop-on-idle --file-idle-time 10000000
I will try to put this code on the site Gource site ;-) Feel free to ask me questions or to improve my script.
No comments:
Post a Comment