wiki_pages 1.34 KB
Newer Older
1 2
#!/usr/bin/env python
# -*- coding: utf-8 -*-
3

4
FICHIER_MUNIN = '/var/lib/munin/tmp/wiki_pages'
5

6 7
import shutil
import sys
8
import tempfile
9 10 11 12 13 14 15

try :
    arg = sys.argv[1]
except :
    arg = ''

if arg == "config" :
16
        print 'host_name web.wiki'
17 18 19 20 21 22 23 24 25
        print 'graph_category wiki'
        print 'graph_title Nombres de pages'
        print 'graph_args --base 1000 --lower-limit 0'
        print 'graph_vlabel nombre de pages'
        print 'total.label Total'
        print 'total.draw AREA'
        print 'orphelines.label Pages orphelines'
        print 'orphelines.draw AREA'
elif arg == "fichier" :
26 27 28 29
    from MoinMoin.request.request_cli import Request
    sys.path.insert(0, '/etc/moin')

    request = Request(u"wiki.crans.org/")
30
    request.form = request.args = request.setup_args()
31
    
32 33 34 35 36 37 38 39
    pages = request.rootpage.getPageDict(user='')
    orphaned = {}
    orphaned.update(pages)
    for page in pages.values():
        links = page.getPageLinks(request)
        for link in links:
            if link in orphaned:
                del orphaned[link]
40

41 42 43 44
    tmpfile = tempfile.NamedTemporaryFile()
    tmpfile.write("total.value %d\n" % pages.__len__())
    tmpfile.write("orphelines.value %d\n" % orphaned.__len__())
    tmpfile.flush()
45

46 47 48 49 50
    shutil.copy(tmpfile.name, FICHIER_MUNIN)
    
    tmpfile.close()
else:
    sys.stdout.write(open(FICHIER_MUNIN).read())