forked from MayeulC/hb-downloader
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathevent_handler.py
44 lines (36 loc) · 1.37 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
41
42
43
44
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
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", "{0}: {1:7.2f}% ".format(filename, 0), False)
sys.stdout.flush()
@staticmethod
def print_md5_end(filename):
print("")
@staticmethod
def print_download_start(filename):
logger.display_message(False, "Download", "{0}: {1:7.2f}% ".format(filename, 0), False)
sys.stdout.flush()
@staticmethod
def print_download_end(filename):
sys.stdout.write(" \b\b\b\b\b\b\b\b\b\bfinished.\n")
sys.stdout.flush()
@staticmethod
def print_progress(percentage):
sys.stdout.write(" \b\b\b\b\b\b\b\b\b\b{0:7.2f}% ".format(percentage))
sys.stdout.flush()