Commit eb6d5581 authored by Celine Mercier's avatar Celine Mercier

Cython: Progress bar: added a cut option to choose whether to do line

breaks every tenth of the full bar, set to False by default for lighter
printing
parent 343dbc7e
......@@ -51,6 +51,7 @@ cdef class ProgressBar:
cdef int lastlog
cdef bint ontty
cdef int fd
cdef bint cut
cdef bytes _head
cdef char *chead
......
......@@ -6,11 +6,14 @@ Created on 27 mars 2016
@author: coissac
'''
from ..utils cimport str2bytes, bytes2str
from .config cimport getConfiguration
import sys
cdef class ProgressBar:
cdef clock_t clock(self):
cdef clock_t t
cdef timeval tp
......@@ -22,11 +25,14 @@ cdef class ProgressBar:
return t
def __init__(self,
off_t maxi,
dict config={},
str head="",
double seconde=0.1):
double seconde=0.1,
cut=False):
self.starttime = self.clock()
self.lasttime = self.starttime
self.tickcount = <clock_t> (seconde * CLOCKS_PER_SEC)
......@@ -37,17 +43,16 @@ cdef class ProgressBar:
if not config:
config=getConfiguration()
self.ontty = sys.stderr.isatty()
if (maxi<=0):
maxi=1
self.maxi = maxi
self.head = head
self.chead= self._head
self.maxi = maxi
self.head = head
self.chead = self._head
self.cut = cut
self.logger=config[config["__root_config__"]]["logger"]
self.wheel = '|/-\\'
......@@ -61,8 +66,9 @@ cdef class ProgressBar:
'##########' \
'##########' \
'##########'
def __call__(self,object pos):
def __call__(self, object pos):
cdef off_t ipos
cdef clock_t elapsed
cdef clock_t newtime
......@@ -111,7 +117,7 @@ cdef class ProgressBar:
self.arrow=(self.arrow+1) % 4
if days:
<void>fprintf(stderr,b'\r%s %5.1f %% |%.*s%c%.*s] remain : %d days %02d:%02d:%02d',
<void>fprintf(stderr,b'\r%s %5.1f %% |%.*s%c%.*s] remain : %d days %02d:%02d:%02d\t',
self.chead,
percent*100,
fraction,self.diese,
......@@ -119,7 +125,7 @@ cdef class ProgressBar:
50-fraction,self.spaces,
days,hour,minu,sec)
else:
<void>fprintf(stderr,b'\r%s %5.1f %% |%.*s%c%.*s] remain : %02d:%02d:%02d',
<void>fprintf(stderr,b'\r%s %5.1f %% |%.*s%c%.*s] remain : %02d:%02d:%02d\t',
self.chead,
percent*100.,
fraction,self.diese,
......@@ -127,25 +133,25 @@ cdef class ProgressBar:
50-fraction,self.spaces,
hour,minu,sec)
tenth = int(percent * 10)
if tenth != self.lastlog:
if self.ontty:
<void>fputs(b'\n',stderr)
if self.cut:
tenth = int(percent * 10)
if tenth != self.lastlog:
if self.ontty:
<void>fputs(b'\n',stderr)
self.logger.info('%s %5.1f %% remain : %02d:%02d:%02d' % (
bytes2str(self._head),
percent*100.,
hour,minu,sec))
self.lastlog=tenth
self.logger.info('%s %5.1f %% remain : %02d:%02d:%02d' % (
bytes2str(self._head),
percent*100.,
hour,minu,sec))
self.lastlog=tenth
else:
self.cycle+=1
property head:
property head:
def __get__(self):
return self._head
def __set__(self,str value):
self._head=str2bytes(value)
self.chead=self._head
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment