3 """@namespace IMP.isd.Entry
4 Classes to handle ISD statistics files.
10 """The entry class represents a column in the statistics file.
11 Its components are a title, a format and an additional object.
12 It's what gets written to the statistics file in a column.
13 - title: the title of the column
14 - format: a wisely chosen format string (see below)
15 - something: either something that can be formattable, a string, a number
16 etc. This is a static entry. In that case all remaining arguments are
17 discarded and get_value returns the formatted string : format % something.
18 If something is a function, this is a dynamic entry, and the format
19 string is used on the result of the function call
20 something(*args,**kwargs).
23 def __init__(self, title, fmt, something, *args, **kwargs):
26 self.is_function = callable(something)
28 self.function = something
32 self.value = something
33 self.was_updated_since_last_get =
False
37 return "Entry('%s', '%s', f(...))" % (self.title, self.format)
39 return "Entry('%s', '%s', %s)" % (self.title, self.format,
45 def get_raw_value(self):
47 return self.function(*self.args, **self.kwargs)
49 self.was_updated_since_last_get =
False
54 return self.format % self.get_raw_value()
58 def set_value(self, val):
60 raise RuntimeError(
"Can only set_value on static entries.")
62 self.was_updated_since_last_get =
True
64 def get_was_updated(self):
65 return self.is_function
or self.was_updated_since_last_get