This is a quick program that parses the output of a scons --debug=tree run and displays it in a more friendly format, as a tree widget. It uses wxPython, so you'll need to have that installed. It's my first wxPython program, so feel free to point out anything I've done wrong.
1 from wxPython.wx import *
2 import os
3 import sys
4
5 ID_OPEN=102
6
7 class SconsTreeView(wxApp):
8 def OnInit(self):
9 frame = wxFrame(NULL, -1, 'Scons tree view')
10 self.frame=frame
11 frame.Show(true)
12 self.SetTopWindow(frame)
13
14 filemenu = wxMenu()
15 filemenu.Append(ID_OPEN, '&Open')
16 menuBar = wxMenuBar()
17 menuBar.Append(filemenu, '&File')
18 frame.SetMenuBar(menuBar)
19 EVT_MENU(self, ID_OPEN, self.OnOpen)
20
21 self.tree = wxTreeCtrl(frame)
22 sizer = wxBoxSizer(wxHORIZONTAL)
23 sizer.Add(self.tree, 1, wxEXPAND)
24 frame.SetSizer(sizer)
25 frame.SetAutoLayout(1)
26 sizer.Fit(frame)
27 if (len(sys.argv) > 1):
28 f = open(sys.argv[1], 'r')
29 print f
30 self.Parse(f)
31 return true
32
33 def OnOpen(self, evt):
34 dlg = wxFileDialog(self.frame, "Choose a file", "", "", "*.*", wxOPEN)
35 if dlg.ShowModal() == wxID_OK:
36 filename = dlg.GetFilename()
37 dirname = dlg.GetDirectory()
38 f = open(os.path.join(dirname, filename), 'r')
39 self.Parse(f)
40 f.close()
41 dlg.Destroy()
42
43 def Parse(self, f):
44 t = self.tree
45 t.DeleteAllItems()
46 for line in f:
47 if line.startswith('+') and line.find('-') != -1:
48 lastdepth = line.index('-')/2
49 nodes = [ t.AddRoot('.') ]
50 break
51
52 lastnode = nodes[-1]
53 for line in f:
54 if line.find('-') == -1:
55 break
56 depth=line.index('-')/2
57 content = line[line.index('-')+1:]
58 if depth > lastdepth:
59 nodes.append(lastnode)
60 lastnode = t.AppendItem(nodes[-1], content)
61 elif depth < lastdepth:
62 for i in range(depth, lastdepth):
63 nodes.pop()
64 lastnode = t.AppendItem(nodes[-1], content)
65 else:
66 lastnode = t.AppendItem(nodes[-1], content)
67 lastdepth = depth
68
69 app=SconsTreeView(0)
70 app.MainLoop()
I like this script, but in newer version of wxpython the names of some classes/modules have changed. I have attached a patched version of this script SconsTreeView-wx2.8.8.0.py . (John Femiani)
