Affichage des articles dont le libellé est dokuwiki. Afficher tous les articles
Affichage des articles dont le libellé est dokuwiki. Afficher tous les articles

5/19/2010

Gource et Dokuwiki : en couleur

ça y est suite aux différentes demandes, je viens d'ajouter la coloration de la représentation Gource. Vous pouvez donc télécharger la nouvelle version.

#!/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 glob
import os.path
import getopt
import sys
import re

WHITE = "11FFAA"
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):
                listdirectory(i,colormodify(color))
        else:
                readfile(i,color)

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)
                readfile(fichier,GREEN)

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
            else:
                resultat += "|" + colormodify(color)
            print resultat
    myfile.close()


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"
    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 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 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:])

5/15/2010

Gource et Dokuwiki

J'ai découvert comme tout un chacun les superbes vidéos de Gource permettant de faire une représentation des modifications faites sur un système de gestion de version comme GIT ou SVN. Je me suis alors rappelé que mon wiki préféré (DOKUWIKI) est lui aussi un système de gestion de version comme un autre... Il suffit en effet de soulever le capot et d'aller regarder dans l'arborescence des dossiers pour y trouver le dossier "data/meta" dans lequel les fichiers "*.changes" renferment justement les informations recherchées. Par exemple, le fichier "systemes_visualisation.changes" ressemble à :
1263135717 ::1 C informatique:systemes_visualisation Wolverine créée
1263135988 ::1 E informatique:systemes_visualisation Wolverine
1263136423 ::1 E informatique:systemes_visualisation Wolverine

Explication :
  1. Le première colonne est un Unix Timestamp,
  2. la deuxième est l'adresse IP (je suis en localhost ;-) ),
  3. la troisième l'action réalisée (C pour créée, E pour éditée,...),
  4. la quatrième est claire, la cinquième est l'identifiant de la personne ayant modifié la page
  5. et enfin la dernière colonne est le petit texte que vous pouvez remplir quand vous modifiez une page...
Que faire de tout ça pour le faire lire à Gource, rien de plus simple, il suffit de transformer cette arborescence en un fichier de log compréhensible par Gource. Pour ce faire, j'ai développé un petit script python, nommé gourcedoku.py :
#!/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"


#print listdirectory2(sys.argv[1])

if __name__ == "__main__":
main(sys.argv[1:])
Pour le lancer, rien de plus simple : il suffit de se placer dans l'arborescence de son magnifique dokuwiki et la commande magique :
python gourcedoku.py -d ~/Sites/MyDokuwiki/ | sort > dokusort.log
puis visualiser le résultat avec Gource avec la commande suivante :
gource --log-format custom dokusort.log --stop-position 1.0 --stop-on-idle --file-idle-time 10000000
Je vais essayer de mettre ce code sur le site de Gource pour la communauté ;-) N'hésitez pas à me poser des questions ou à améliorer mon script.