Commit 7e7c2f13 by Eric Coissac

Define a head property allowing to change the header of the progress bar

after creation
parent 678d54be
...@@ -53,7 +53,7 @@ cdef class ProgressBar: ...@@ -53,7 +53,7 @@ cdef class ProgressBar:
cdef bint ontty cdef bint ontty
cdef int fd cdef int fd
cdef bytes head cdef bytes _head
cdef char *chead cdef char *chead
cdef object logger cdef object logger
......
...@@ -8,6 +8,7 @@ Created on 27 mars 2016 ...@@ -8,6 +8,7 @@ Created on 27 mars 2016
import sys import sys
from ..utils import bytes2str,str2bytes from ..utils import bytes2str,str2bytes
from .config cimport getConfiguration
cdef class ProgressBar: cdef class ProgressBar:
...@@ -24,7 +25,7 @@ cdef class ProgressBar: ...@@ -24,7 +25,7 @@ cdef class ProgressBar:
def __init__(self, def __init__(self,
off_t maxi, off_t maxi,
dict config, dict config={},
str head="", str head="",
double seconde=0.1): double seconde=0.1):
self.starttime = self.clock() self.starttime = self.clock()
...@@ -35,14 +36,18 @@ cdef class ProgressBar: ...@@ -35,14 +36,18 @@ cdef class ProgressBar:
self.arrow = 0 self.arrow = 0
self.lastlog = 0 self.lastlog = 0
if not config:
config=getConfiguration()
self.ontty = sys.stderr.isatty() self.ontty = sys.stderr.isatty()
if (maxi<=0): if (maxi<=0):
maxi=1 maxi=1
self.maxi = maxi self.maxi = maxi
self.head = str2bytes(head) self._head = str2bytes(head)
self.chead= self.head self.chead= self._head
self.logger=config[config["__root_config__"]]["logger"] self.logger=config[config["__root_config__"]]["logger"]
...@@ -130,10 +135,18 @@ cdef class ProgressBar: ...@@ -130,10 +135,18 @@ cdef class ProgressBar:
<void>fprintf(stderr,b'\n') <void>fprintf(stderr,b'\n')
self.logger.info('%s %5.1f %% remain : %02d:%02d:%02d' % ( self.logger.info('%s %5.1f %% remain : %02d:%02d:%02d' % (
bytes2str(self.head), bytes2str(self._head),
percent*100., percent*100.,
hour,minu,sec)) hour,minu,sec))
self.lastlog=twentyth self.lastlog=twentyth
else: else:
self.cycle+=1 self.cycle+=1
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