Coverage for /usr/local/lib/python3.11/dist-packages/pyrocko/dummy_progressbar.py: 85%

34 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2023-10-06 09:48 +0000

1# http://pyrocko.org - GPLv3 

2# 

3# The Pyrocko Developers, 21st Century 

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

5 

6''' 

7Progressbar replacement class which just outputs progress to log. 

8''' 

9 

10import time 

11import logging 

12 

13 

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

15 

16 

17class ProgressBar(object): 

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

19 self._widgets = widgets 

20 self._maxval = maxval 

21 self._val = 0 

22 self._time = time.time() 

23 

24 def label(self): 

25 for widget in self._widgets: 

26 if isinstance(widget, str): 

27 return widget 

28 

29 def start(self): 

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

31 return self 

32 

33 def update(self, val): 

34 self._val = val 

35 t = time.time() 

36 if t - self._time > 5.0: 

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

38 self.label(), 

39 self._val, 

40 self._maxval, 

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

42 

43 self._time = t 

44 

45 def finish(self): 

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

47 

48 

49class Bar(object): 

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

51 pass 

52 

53 

54class Percentage(object): 

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

56 pass 

57 

58 

59class ETA(object): 

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

61 pass