forked from joac/joac-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrapher.py
58 lines (47 loc) · 1.66 KB
/
grapher.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!-*- coding:utf8 -*-
import random
import os
import sys
import pygraphviz as gv
from MoinMoin import wikiutil, user
from MoinMoin.request.request_cli import Request
from MoinMoin.Page import Page
def int2hex_color(number):
hexa = hex(number)[2:8]
print hexa
longitud = len(hexa)
if longitud < 6:
hexa = ('0'*(6-longitud))+hexa
print hexa
return '#'+hexa
#Agregamos el path al wikiconfig.py de pyar
sys.path.append('/home/www-pyar/moin/share/moin/pyar')
#Path al desposito de Archivos
path ='/home/www-pyar/moin/share/moin/pyar/data/pages'
ignore =[u'ReadWriteGroup',u'AdminGroup',u'BadContent']
#Creamos nuestro request de tipo cliente
request = Request()
#Levantamos todas las paginas existentes en el wiki y las convertimos a wikiname
pages = [wikiutil.unquoteWikiname(page) for page in os.listdir(path)]
pages = [page for page in pages if Page(request, page).exists()]
#borramos algunas paginas que no deberian verse
for entry in ignore:
pages.remove(entry)
#Iniciamos el Grafico
graph = gv.AGraph(directed=True, splines="true", )
print "Rellenando nodos"
for page in pages:
page_utf8 = page.encode('utf8')
graph.add_node(page_utf8, shape ='plaintext', href="http://python.org.ar/pyar/"+page_utf8, tooltip = "Click para ir a la página")
print '.',
for page in pages:
links = Page(request, page).getPageLinks(request)
page = page.encode("utf8")
color = random.randint(0, 0xffffff)
for link in links:
if link in pages:
link = link.encode("utf8")
graph.add_edge(page, link, color=int2hex_color(color))
print '.',
print "Generando Grafico"
graph.draw("grafo.svg", prog='fdp')