3 """@namespace IMP.isd.Entry
4 Classes to handle ISD statistics files.
6 from __future__
import print_function
12 """The entry class represents a column in the statistics file.
13 Its components are a title, a format and an additional object.
14 It's what gets written to the statistics file in a column.
15 - title: the title of the column
16 - format: a wisely chosen format string (see below)
17 - something: either something that can be formattable, a string, a number
18 etc. This is a static entry. In that case all remaining arguments are
19 discarded and get_value returns the formatted string :
20 format % something. If something is a function, this is a dynamic
21 entry, and the format string is used on the result of the function call
22 something(*args,**kwargs).
25 def __init__(self, title, fmt, something, *args, **kwargs):
28 self.is_function = isinstance(something, collections.Callable)
30 self.function = something
34 self.value = something
35 self.was_updated_since_last_get =
False
39 return "Entry('%s', '%s', f(...))" % (self.title, self.format)
41 return "Entry('%s', '%s', %s)" % (self.title, self.format,
47 def get_raw_value(self):
49 return self.function(*self.args, **self.kwargs)
51 self.was_updated_since_last_get =
False
56 return self.format % self.get_raw_value()
60 def set_value(self, val):
62 raise RuntimeError(
"Can only set_value on static entries.")
64 self.was_updated_since_last_get =
True
66 def get_was_updated(self):
67 return self.is_function
or self.was_updated_since_last_get