1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | import sys |
---|
4 | import curses |
---|
5 | #import pprint |
---|
6 | |
---|
7 | # line below is to include "smon" package in the search path |
---|
8 | sys.path.append("/home/jripsl/snapshot/Monitoring") |
---|
9 | |
---|
10 | from smon import repo_io |
---|
11 | import smon.types |
---|
12 | |
---|
13 | |
---|
14 | # init |
---|
15 | |
---|
16 | # set pad height/width |
---|
17 | padhlines = 4 |
---|
18 | padwcols = 30 |
---|
19 | |
---|
20 | # add margin |
---|
21 | padhlines += 2 |
---|
22 | padwcols += 2 |
---|
23 | |
---|
24 | |
---|
25 | |
---|
26 | |
---|
27 | repo_io.init() # open DB connection |
---|
28 | |
---|
29 | repo_io.populate_tables_with_sample() |
---|
30 | |
---|
31 | simulations=repo_io.retrieve_simulations() |
---|
32 | |
---|
33 | |
---|
34 | |
---|
35 | def display_simulation_list(mydata): |
---|
36 | |
---|
37 | hlines = begin_y = begin_x = 5 |
---|
38 | |
---|
39 | # stuff |
---|
40 | mypad.scrollok(1) |
---|
41 | mypad.idlok(1) |
---|
42 | |
---|
43 | mypad.border(0) # clear border |
---|
44 | |
---|
45 | y=padhlines-1 |
---|
46 | |
---|
47 | # write strings |
---|
48 | for line in mydata: |
---|
49 | mypad.addstr(y,1, line) |
---|
50 | mypad.scroll(1) |
---|
51 | |
---|
52 | |
---|
53 | mypad.border(0) # clear border |
---|
54 | |
---|
55 | |
---|
56 | |
---|
57 | # refresh the pads |
---|
58 | mypad.refresh(0,0, begin_y,begin_x, begin_y+hlines, begin_x+padwcols) |
---|
59 | |
---|
60 | |
---|
61 | mypad.touchwin() # pretend the all stuff has been changed |
---|
62 | |
---|
63 | |
---|
64 | # better way |
---|
65 | |
---|
66 | def main(stdscr): |
---|
67 | |
---|
68 | """ |
---|
69 | window test |
---|
70 | |
---|
71 | begin_x = 20 ; begin_y = 7 |
---|
72 | height = 5 ; width = 40 |
---|
73 | win = curses.newwin(height, width, begin_y, begin_x) |
---|
74 | """ |
---|
75 | |
---|
76 | # create pad |
---|
77 | global mypad |
---|
78 | mypad=curses.newpad(padhlines, padwcols) |
---|
79 | |
---|
80 | # what to display |
---|
81 | data = [s.name+" "+s.status for s in simulations] |
---|
82 | |
---|
83 | |
---|
84 | display_simulation_list(data) |
---|
85 | |
---|
86 | |
---|
87 | |
---|
88 | |
---|
89 | |
---|
90 | |
---|
91 | while True: |
---|
92 | c = mypad.getch() # even THIS command erases newpad! |
---|
93 | #stdscr.getch() |
---|
94 | |
---|
95 | if c in (curses.KEY_ENTER,): |
---|
96 | # => doesn't work... |
---|
97 | |
---|
98 | break |
---|
99 | elif c in (ord('q'),ord('Q')): |
---|
100 | # => works... |
---|
101 | |
---|
102 | break |
---|
103 | |
---|
104 | elif c in (ord('r'),ord('R')): |
---|
105 | |
---|
106 | # debug |
---|
107 | #stdscr.addstr() |
---|
108 | |
---|
109 | mypad.erase() |
---|
110 | |
---|
111 | display_simulation_list(data) |
---|
112 | |
---|
113 | # pretend the all stuff has been changed |
---|
114 | # no real effect here |
---|
115 | #stdscr.touchwin() |
---|
116 | |
---|
117 | stdscr.refresh() # refresh parent first, to render the texts on top |
---|
118 | |
---|
119 | |
---|
120 | |
---|
121 | |
---|
122 | |
---|
123 | |
---|
124 | |
---|
125 | |
---|
126 | |
---|
127 | |
---|
128 | |
---|
129 | |
---|
130 | curses.wrapper(main) |
---|
131 | |
---|
132 | repo_io.free() # close DB connection |
---|