-
Notifications
You must be signed in to change notification settings - Fork 45
/
event_handler.py
40 lines (32 loc) · 1.17 KB
/
event_handler.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
import sys
import logger
from humble_api.events import Events
__author__ = "Brian Schkerke"
__copyright__ = "Copyright 2016 Brian Schkerke"
__license__ = "MIT"
class EventHandler(object):
@staticmethod
def initialize():
Events.on(Events.EVENT_MD5_START, EventHandler.print_md5_start)
Events.on(Events.EVENT_MD5_END, EventHandler.print_md5_end)
Events.on(Events.EVENT_DOWNLOAD_START, EventHandler.print_download_start)
Events.on(Events.EVENT_DOWNLOAD_END, EventHandler.print_download_end)
Events.on(Events.EVENT_PROGRESS, EventHandler.print_progress)
@staticmethod
def print_md5_start(filename):
logger.display_message(False, "Checksum", "%s: " % filename, False)
sys.stdout.flush()
@staticmethod
def print_md5_end(filename):
print ""
@staticmethod
def print_download_start(filename):
logger.display_message(False, "Download", "%s: " % filename, False)
sys.stdout.flush()
@staticmethod
def print_download_end(filename):
print ""
@staticmethod
def print_progress(percentage):
sys.stdout.write("{0:.0f}% ".format(percentage))
sys.stdout.flush()