-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMessageHandler.py
More file actions
56 lines (44 loc) · 1.36 KB
/
MessageHandler.py
File metadata and controls
56 lines (44 loc) · 1.36 KB
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
import sys
import fcntl
import termios
import threading
import time
import struct
# Progess bar code retrieved from somewhere on the net that I can't remember... sorry
COLS = struct.unpack('hh', fcntl.ioctl(sys.stdout, termios.TIOCGWINSZ, '1234'))[1]
class MessageHandler:
def __init__(self):
pass
def bold(self, messsge):
return u'\033[1m%s\033[0m' % message
def progress(self, current, total, instanceTtype):
prefix = '%d / %d %s' % (current, total, instanceType)
barStart = ' ['
barEnd = '] '
barSize = COLS - len(prefix + barStart + barEnd)
amount = int(current / (total / float(barSize)))
remaining = barSize - amount
bar = '.' * amount + ' ' * remaining
return self.bold(prefix) + barStart + bar + barEnd
def progressBar(self, number, total, interval, type):
number += 1
if (not (number % interval)):
sys.stdout.write(self.progress(number, total, type) + '\r')
sys.stdout.flush()
def end(self):
print ""
def message(self, objectType, location, message):
if (self.level >= 0):
print objectType + "Message: " + message
def debug(self, objectType, location, message):
if (self.level >= 1):
print objectType + " at line " + location + " in " + fileName
print "Message: " + message
def error(self):
pass
def fatal(self):
pass
#mh = MessageHandler()
#for i in range(100):
# mh.progressBar(i, 100, "Histogram")
#print ""