Gource und Dokuwiki – Bearbeitungen visualisieren

In Anlehnung an den französischen Blogeintrag von Wolverine will ich hier einmal auf deutsch erklären, wie man die Änderungen aus einem Dokuwiki mit Gource unter Ubuntu visualisiert.

Zunächst installiert man, sofern noch nicht vorhanden, Gource:

sudo aptitude install gource

Anschließend muss das folgende Python-Script in eine Datei verfrachtet werden und ausführbar gemacht werden. Es dient dazu die *.changes$-Dateien vom Dokuwiki in ein für Gource lesbares Format zu bringen.

#!/usr/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:])

Nachdem man nun die Pythondatei (Bsp.name hier: doku2gource.py) hat, führt man folgenden Befehl aus:

python doku2gource.py -d ~/public_html/dokuwiki/ | sort > dokusort.log

Es ensteht die erwähnte für Gource brauchbare Logdatei. Diese wird nun wiederum an Gource weitergegeben und mit ffmpeg eine Videodatei erstellt:

gource --log-format custom dokusort.log --stop-position 1.0 --stop-on-idle --file-idle-time 10000000 --output-ppm-stream - | ffmpeg -y -b 3000K -r 60 -f image2pipe -vcodec ppm -i - -vcodec mpeg4 gource.mp4

Das wars schon. Hier noch mal die mir nützlichen Links:

http://wolverinex02.blogspot.com/2010/05/gource-et-dokuwiki.html

http://code.google.com/p/gource/wiki/Videos