-
Notifications
You must be signed in to change notification settings - Fork 15
/
monitor.py
136 lines (94 loc) · 2.3 KB
/
monitor.py
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
"""
"""
# Native
import random
import time
import curses
from curses import wrapper
# # 3rd-Party
# # Proprietary
from db import session
class Monitor(object):
"""
"""
SEPERATOR = 145 * '-'
def __init__(self, screen, interval=1):
"""
"""
self.screen = screen
self.interval = float(interval)
# How long the monitor has been running for in seconds
self.running = 0
return
def setup(self):
"""
"""
self.increment = Inc()
return
def run(self):
"""
"""
self.setup()
# Clear screen
self.screen.clear()
#
curses.start_color()
curses.init_pair(1, curses.COLOR_CYAN, curses.COLOR_BLACK)
curses.init_pair(2, curses.COLOR_GREEN, curses.COLOR_BLACK)
curses.init_pair(3, curses.COLOR_MAGENTA, curses.COLOR_BLACK)
curses.init_pair(4, curses.COLOR_YELLOW, curses.COLOR_BLACK)
curses.init_pair(5, curses.COLOR_RED, curses.COLOR_BLACK)
curses.init_pair(6, curses.COLOR_WHITE, curses.COLOR_BLACK)
while True:
#
session.expire_all()
# TODO: Add some standard header to the top? (like interval time etc)
#
self.render()
#
self.increment.reset()
#
self.screen.refresh()
#
time.sleep(self.interval)
self.running += self.interval
return
def render(self):
"""
"""
raise Exception("Abstract")
@property
def line(self):
"""
"""
return self.increment.inc()
def fixed(self, value, length, padding=' '):
"""
"""
diff = length - len(str(value))
return '%s%s' % (value, padding * diff)
# Bleh.. all because we can't do num++
class Inc(object):
"""
"""
def __init__(self, start=0, step=1):
"""
"""
self.num = start
self.step = step
return
def inc(self):
"""
"""
self.num += self.step
return self.num
def dec(self):
"""
"""
self.num -= self.step
return self.num
def reset(self):
"""
"""
self.num = 0
return self