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

# http://pyrocko.org - GPLv3 

# 

# The Pyrocko Developers, 21st Century 

# ---|P------/S----------~Lg---------- 

import time 

import logging 

 

 

logger = logging.getLogger('pyrocko.progress') 

 

 

class ProgressBar(object): 

def __init__(self, widgets=['progress'], maxval=1, *args, **kwargs): 

self._widgets = widgets 

self._maxval = maxval 

self._val = 0 

self._time = time.time() 

 

def label(self): 

for widget in self._widgets: 

if isinstance(widget, str): 

return widget 

 

def start(self): 

logger.info('%s...' % self.label()) 

return self 

 

def update(self, val): 

self._val = val 

t = time.time() 

if t - self._time > 5.0: 

logger.info('%s: %i/%i %3.0f%%' % ( 

self.label(), 

self._val, 

self._maxval, 

100.*float(self._val) / float(self._maxval))) 

 

self._time = t 

 

def finish(self): 

logger.info('%s: done.' % self.label()) 

 

 

class Bar(object): 

def __init__(self, *args, **kwargs): 

pass 

 

 

class Percentage(object): 

def __init__(self, *args, **kwargs): 

pass 

 

 

class ETA(object): 

def __init__(self, *args, **kwargs): 

pass