Newer
Older
val.__class__.__name__,
",".join(typedump(x) for x in val[:5]))
else:
return "%s(%s)" % (
val.__class__.__name__,
",".join(typedump(x) for x in val[:5]))
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
class ProgressBar:
def __init__(self, descr, total, initial=0, length=40):
import time
self.Description = descr
self.Total = total
self.Done = initial
self.Length = length
self.LastSquares = -1
self.StartTime = time.time()
self.LastUpdate = self.StartTime
def draw(self):
import time
now = time.time()
squares = int(self.Done/self.Total*self.Length)
if squares != self.LastSquares or now-self.LastUpdate > 0.5:
elapsed = now-self.StartTime
if self.Done:
time_per_step = elapsed/self.Done
total_time = self.Total * time_per_step
eta_str = "%6.1fs" % max(0, total_time-elapsed)
else:
eta_str = "?"
import sys
sys.stderr.write("%-20s [%s] ETA %s\r" % (
self.Description,
squares*"#"+(self.Length-squares)*" ",
eta_str))
self.LastSquares = squares
self.LastUpdate = now
def progress(self, steps=1):
self.set_progress(self.Done + steps)
def set_progress(self, done):
self.Done = done
self.draw()
def finished(self):
import sys
self.set_progress(self.Total)
sys.stderr.write("\n")
# file system related ---------------------------------------------------------
def assert_not_a_file(name):
import os
if os.access(name, os.F_OK):
raise IOError, "file `%s' already exists" % name