MCPcopy Create free account
hub / github.com/ActiveState/code / getStats

Function getStats

recipes/Python/577933_DistCC_top/recipe-577933.py:37–80  ·  view source on GitHub ↗
(scr)

Source from the content-addressed store, hash-verified

35 #'%-4s %-20s %-15s %-40s%s' % ('Slot', 'Remote Host', 'State', 'Filename', ' '*(maxX-83)), curses.A_BOLD)
36
37def getStats(scr):
38 curses.init_pair(9, curses.COLOR_WHITE, curses.COLOR_BLACK)
39 curses.init_pair(10, curses.COLOR_YELLOW, curses.COLOR_BLACK)
40 curses.init_pair(11, curses.COLOR_RED, curses.COLOR_BLACK)
41 curses.init_pair(12, curses.COLOR_GREEN, curses.COLOR_BLACK)
42 (maxY, maxX) = scr.getmaxyx()
43 while 1:
44 try:
45 display_time(scr)
46 display_loadavg(scr)
47 display_header(scr)
48 #write(scr, 3, 0, '%-4s %-20s %-15s %-40s%s' % ('Slot', 'Remote Host', 'State', 'Filename', ' '*(maxX-83)), curses.A_BOLD)
49 cnt = 5
50 try:
51 for i in os.listdir(DISTCC_DIR+'/state'):
52 data = struct.unpack('@iLL128s128siiP', open(DISTCC_DIR+'/state/'+i).readline().strip())
53 file = data[3].split('\x00')[0] or 'None'
54 host = data[4].split('\x00')[0] or 'None'
55 slot = int(data[5])
56 stte = states[int(data[6])]
57 scr.move(cnt,0)
58 scr.clrtoeol()
59 if 'None' not in (file, host):
60 write(scr, cnt, 0, '%s' % slot, curses.color_pair(9))
61 write(scr, cnt, 5, '%s' % host, curses.color_pair(9))
62 if int(data[6]) in (2,3):
63 write(scr, cnt, 25, '%s ' % (stte), curses.color_pair(10))
64 elif int(data[6]) in (0,1):
65 write(scr, cnt, 25, '%s ' % (stte), curses.color_pair(11))
66 elif int(data[6]) in (4,5):
67 write(scr, cnt, 25, '%s ' % (stte), curses.color_pair(12))
68 elif int(data[6]) in (6,7):
69 write(scr, cnt, 25, '%s ' % (stte), curses.color_pair(12)|curses.A_BOLD)
70 else: write(scr, cnt, 25, '%s ' % (stte))
71 write(scr, cnt, 45, '%s' % file, curses.color_pair(9))
72 cnt += 1
73 except struct.error: pass
74 except IOError: pass
75 scr.refresh()
76 time.sleep(0.75)
77 scr.erase()
78 scr.move(0,0)
79 except KeyboardInterrupt:
80 sys.exit(-1)
81
82if __name__ == '__main__':
83 curses.wrapper(getStats)

Callers

nothing calls this directly

Calls 15

display_timeFunction · 0.85
display_loadavgFunction · 0.85
display_headerFunction · 0.85
writeFunction · 0.70
openFunction · 0.50
listdirMethod · 0.45
unpackMethod · 0.45
stripMethod · 0.45
readlineMethod · 0.45
splitMethod · 0.45
moveMethod · 0.45
refreshMethod · 0.45

Tested by

no test coverage detected