Newer
Older
def validate(self, setup):
pass
# obscure stuff --------------------------------------------------------------
Andreas Klöckner
committed
def enumerate_basic_directions(dimensions):
coordinate_list = [[0], [1], [-1]]
return reduce(cartesian_product_sum, [coordinate_list] * dimensions)[1:]
Andreas Klöckner
committed
def typedump(val):
try:
len(val)
except TypeError:
return val.__class__.__name__
else:
l = len(val)
if len(val) > 5:
return "%s(%s,...)" % (
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]))
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
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