-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexplore.py
More file actions
102 lines (87 loc) · 2.72 KB
/
explore.py
File metadata and controls
102 lines (87 loc) · 2.72 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/bin/env python
import os
from gui import Tree
from Tkinter import *
# Recursive search to display the include chain for a particular source.
def displayIncludeChain(aNode):
currentNode = aNode
if currentNode.name() == searchFile:
# Found
print "* %s" % currentNode.name()
return 1
found = 0
if currentNode.children():
for child in currentNode.children():
if currentNode != child: # This was the case with SKEConfig.h
found = displayIncludeChain(child)
if found == 1:
print "< %s" % currentNode.name()
return 1
# Not found
return found
def formatNodeText(node):
return "%s, lines(%d), total_lines(%d), nested_included(%d)" % (node.name(),
node.lines(), node.totalLines(), len(node.children()))
class get:
def __init__(self, dependTree):
self.dependTree = dependTree
def findChild(self, children, id):
for child in children:
if id == child.file():
return child
return None
def getCurrent(self, node):
currentNode = self.dependTree
for id in node.full_id()[1:]:
if currentNode is not None:
currentNode = self.findChild(currentNode.children(), id)
return currentNode
def __call__(self, node):
currentNode = self.getCurrent(node)
if currentNode is None: return
children = currentNode.children()
children.sort(key=lambda k:k.totalLines())
for child in currentNode.children():
flag = 0
if len(child.children()) == 0:
flag = 0
else:
flag = 1
t.add_node(name=formatNodeText(child), id=child.file(), flag=flag)
root=Tk()
root.title(os.path.basename(sys.argv[0]))
import sys
from depend import Depend
file = sys.argv[1]
lines = open(file).xreadlines()
depend = Depend()
depend.feed(lines)
dependTree = depend.getTree()
searchFile = None
if len(sys.argv) > 2:
searchFile = sys.argv[2]
if dependTree is None:
print "Error reading dependancy information from %s" % file
sys.exit(0)
if searchFile is not None:
displayIncludeChain(dependTree)
# create the control
t=Tree.Tree(master=root,
root_id=dependTree.file(),
root_label=formatNodeText(dependTree),
get_contents_callback=get(dependTree),
width=300)
t.grid(row=0, column=0, sticky='nsew')
root.grid_rowconfigure(0, weight=1)
root.grid_columnconfigure(0, weight=1)
sb=Scrollbar(root)
sb.grid(row=0, column=1, sticky='ns')
t.configure(yscrollcommand=sb.set)
sb.configure(command=t.yview)
sb=Scrollbar(root, orient=HORIZONTAL)
sb.grid(row=1, column=0, sticky='ew')
t.configure(xscrollcommand=sb.set)
sb.configure(command=t.xview)
t.focus_set()
t.root.expand()
root.mainloop()