5
def remove_whitespaces(line):
6
return [e for e in line.split(" ") if e]
8
class CodeBrowser(cmd.Cmd):
9
def __init__(self,stat):
10
cmd.Cmd.__init__(self)
12
self.stat = stat.stats
13
self.current_node = self.stat
16
parent = node.get("#parent")
18
return node.get("#name","root")
19
parents_path = self.path(parent)
20
parents_type = parent.get("#type")
21
nodes_type = node.get("#type","?")
22
nodes_name = node.get("#name","?")
24
if nodes_type == "class" :
26
elif nodes_type == "function":
28
elif nodes_type == "module":
30
elif nodes_type in ("#modules","#classes","#functions","#class_code","#module_code"):
32
return ">".join([parents_path,chunk,nodes_name])
34
def change_node(self,dst,error_msg=""):
35
next_node = self.current_node.get(dst)
37
self.current_node = next_node
42
print "this node has no attribute named",dst
46
def do_name(self,line=""):
47
print self.current_node.get("#name")
51
def do_path(self,line=""):
52
print self.path(self.current_node)
54
def do_show(self,line=""):
64
def do_keys(self,line=""):
65
print self.current_node.keys()
67
do_k = do_down = do_keys
69
def do_parent(self,line=""):
70
self.change_node("#parent","this node has no parent")
72
do_up = do_u = do_parent
74
def do_functions(self,line=""):
75
self.change_node("#functions","this node has no functions")
77
def do_methods(self,line=""):
78
self.change_node("#methods","this node has no methods")
80
def do_methods(self,line=""):
81
self.change_node("#methods","this node has no methods")
83
def do_modules(self,line=""):
84
self.change_node("#modules","this node has no modules")
86
def do_loc(self,line=""):
87
loc = self.current_node.get("#loc")
91
print "This node has no #loc key. This is a bug. Please report it"
93
def do_type(self,line=""):
94
print self.current_node.get("#type")
96
def do_select(self,line=""):
97
node = line.split(":")[0]
98
self.change_node(node)
100
def default(self,line=""):
101
if line in self.current_node.keys():
102
x = self.current_node.get(line)
106
self.current_node = x
109
def completenames(self,*args):
110
#print "completenames",args
112
keys = self.current_node.keys()
113
if user_input.startswith("#"):
114
user_input = user_input[1:]
115
return [key for key in self.current_node.keys() if key.startswith(user_input)]
117
def completedefault(self,*args):
118
#print "completedefault",args
120
keys = self.current_node.keys()
121
## if user_input.startswith("#"):
122
## user_input = user_input[1:]
123
return [key[1:] for key in self.current_node.keys() if key.startswith(user_input)]
126
if len(sys.argv) < 2 :
129
file_path = sys.argv[1]
130
st = tahar.SourceStats(file_path)
132
CodeBrowser(st).cmdloop()
136
print sys.argv[0],"file_path"
140
if __name__ == "__main__":