Wednesday, May 19, 2010

Dokuwiki, Gource : color now

In response to various requests, I just added the color to the Dokuwiki representation with Gource. You can now download the new version .


This program parse logs of a dokuwiki
and tranform them for gource (a log viewer)

developped by WolverineX02
site :

import glob
import os.path
import getopt
import sys
import re

GREEN = "00F000"
vector = (1,10,100)
start_page_name = "start"

def RGBToHTMLColor(rgb_tuple):
""" convert an (R, G, B) tuple to #RRGGBB """
hexcolor = '#%02x%02x%02x' % rgb_tuple
# that's it! '%02x' means zero-padded, 2-digit hex values
return hexcolor

def HTMLColorToRGB(colorstring):
""" convert #RRGGBB to an (R, G, B) tuple """
colorstring = colorstring.strip()
if colorstring[0] == '#': colorstring = colorstring[1:]
if len(colorstring) != 6:
raise ValueError, "input #%s is not in #RRGGBB format" % colorstring
r, g, b = colorstring[:2], colorstring[2:4], colorstring[4:]
r, g, b = [int(n, 16) for n in (r, g, b)]
return (r, g, b)

def colormodify(colorstring):
rgb_tuple = HTMLColorToRGB(colorstring)
r, g, b = (rgb_tuple[0]+vector[0]) % 255,(rgb_tuple[1]+vector[1]) % 255,(rgb_tuple[2]+vector[2]) % 255
return RGBToHTMLColor((r, g, b))

def listdirectory(path,color):
l = glob.glob(path+"/*")
for i in l:
if os.path.isdir(i):

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 ('\.changes$', i)):
fichier = os.path.join(root, i)

def readfile(fichier,color):
"""read the file and output for each line of this
file a log line for Gource

myfile = open(fichier, 'r')
for line in myfile.readlines():
mots = line.split('\t')
if len(mots)>=6:
resultat = mots[0] + "|"
if mots[4] == '':
mots[4] = 'Anonymous'
resultat += mots[4] + "|"
resultat += translate(mots[2]) + "|"
resultat += mots[3].replace(':', '/')
if mots[3].rfind(start_page_name) == len(mots[3])-len(start_page_name):
resultat += "|" + color
resultat += "|" + colormodify(color)
print resultat

def translate(mot):
"""translate the dokuwiki vocabulary to the gource one
C (also cc and sc from discussion plugin) ->A
E (also ec from discussion plugin) -> M
D (also dc and hc from discssion plugin) -> D
other -> M
if mot.upper == "C" or mot == 'cc' or mot == 'sc':
return "A"
elif mot.upper == "E" or mot == 'ec':
return "M"
elif mot.upper == "D" or mot == 'dc' or mot == 'hc':
return "D"
return "M"

def main(argv):
"""principal function
opts, args = getopt.getopt(argv, "hd:", ["help", "dokuwiki="])
except getopt.GetoptError:
for opt, arg in opts:
if opt in ("-h","--help"):
elif opt in ("-d","--dokuwiki"):
print listdirectory(arg,WHITE)

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 -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__":

No comments: