Revision 42ace959 image_creator/util.py

b/image_creator/util.py
34 34
import sys
35 35
import pbs
36 36
import hashlib
37
from clint.textui import colored
37
from colors import red, green, yellow
38 38
from progress.bar import Bar
39 39

  
40 40

  
......
61 61

  
62 62
def error(msg, new_line=True):
63 63
    nl = "\n" if new_line else ''
64
    sys.stderr.write(colored.red('Error: %s' % msg) + nl)
64
    sys.stderr.write(red('Error: %s' % msg) + nl)
65 65

  
66 66

  
67 67
def warn(msg, new_line=True):
68 68
    if not silent:
69 69
        nl = "\n" if new_line else ''
70
        sys.stderr.write(colored.yellow("Warning: %s" % msg) + nl)
70
        sys.stderr.write(yellow("Warning: %s" % msg) + nl)
71 71

  
72 72

  
73 73
def success(msg, new_line=True):
74 74
    if not silent:
75 75
        nl = "\n" if new_line else ''
76
        sys.stdout.write(colored.green(msg) + nl)
76
        sys.stdout.write(green(msg) + nl)
77 77
        if not nl:
78 78
            sys.stdout.flush()
79 79

  
......
89 89
def progress(message='', bar_type="default"):
90 90

  
91 91
    MESSAGE_LENGTH = 30
92
    
93
    suffix={'default':'%(index)d/%(max)d',
94
        'percent':'%(percent)d%%',
95
        'b':'%(index)d/%(max)d B',
96
        'kb':'%(index)d/%(max)d KB',
97
        'mb':'%(index)d/%(max)d MB'}
98 92

  
99
    return Bar(message=message.ljust(MESSAGE_LENGTH), fill='#', \
100
                                                    suffix=suffix[bar_type])
93
    suffix = {
94
        'default': '%(index)d/%(max)d',
95
        'percent': '%(percent)d%%',
96
        'b': '%(index)d/%(max)d B',
97
        'kb': '%(index)d/%(max)d KB',
98
        'mb': '%(index)d/%(max)d MB'
99
    }
100

  
101
    bar = Bar()
102
    bar.message = message.ljust(MESSAGE_LENGTH)
103
    bar.fill = '#'
104
    bar.suffix = suffix[bar_type]
105
    bar.bar_prefix = ' ['
106
    bar.bar_suffix = '] '
107

  
108
    return bar
109

  
101 110

  
102 111
def md5(filename, size):
103 112

  
......
114 123
            md5.update(data)
115 124
            left -= length
116 125
            progressbar.goto((size - left) // (2 ** 20))
117
    
126

  
118 127
    checksum = md5.hexdigest()
119 128
    output("\rCalculating md5sum...\033[K", False)
120 129
    success(checksum)

Also available in: Unified diff