Patch a bug in the printing of the progress bar leading to a bus error
when compiled with some C compilers and Cython >= 0.24
This commit is contained in:
@ -7,7 +7,9 @@ Created on 27 mars 2016
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
from ..utils cimport bytes2str
|
from ..utils import bytes2str,str2bytes
|
||||||
|
from .config cimport getConfiguration
|
||||||
|
|
||||||
|
|
||||||
cdef class ProgressBar:
|
cdef class ProgressBar:
|
||||||
cdef clock_t clock(self):
|
cdef clock_t clock(self):
|
||||||
@ -23,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()
|
||||||
@ -34,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"]
|
||||||
@ -104,35 +110,43 @@ cdef class ProgressBar:
|
|||||||
if self.ontty:
|
if self.ontty:
|
||||||
fraction=<int>(percent * 50.)
|
fraction=<int>(percent * 50.)
|
||||||
self.arrow=(self.arrow+1) % 4
|
self.arrow=(self.arrow+1) % 4
|
||||||
self.diese[fraction]=0
|
|
||||||
self.spaces[50 - fraction]=0
|
|
||||||
|
|
||||||
if days:
|
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',
|
||||||
self.chead,
|
self.chead,
|
||||||
percent*100,
|
percent*100,
|
||||||
self.diese,self.wheel[self.arrow],self.spaces,
|
fraction,self.diese,
|
||||||
|
self.wheel[self.arrow],
|
||||||
|
50-fraction,self.spaces,
|
||||||
days,hour,minu,sec)
|
days,hour,minu,sec)
|
||||||
else:
|
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',
|
||||||
self.chead,
|
self.chead,
|
||||||
percent*100.,
|
percent*100.,
|
||||||
self.diese,self.wheel[self.arrow],self.spaces,
|
fraction,self.diese,
|
||||||
|
self.wheel[self.arrow],
|
||||||
|
50-fraction,self.spaces,
|
||||||
hour,minu,sec)
|
hour,minu,sec)
|
||||||
self.diese[fraction]=b'#'
|
|
||||||
self.spaces[50 - fraction]=b' '
|
|
||||||
|
|
||||||
twentyth = int(percent * 20)
|
tenth = int(percent * 10)
|
||||||
if twentyth != self.lastlog:
|
if tenth != self.lastlog:
|
||||||
|
|
||||||
if self.ontty:
|
if self.ontty:
|
||||||
<void>fputs(b'\n',stderr)
|
<void>fputs(b'\n',stderr)
|
||||||
|
|
||||||
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=tenth
|
||||||
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
|
||||||
|
Reference in New Issue
Block a user