return m[k]
def dump(self, prefix=""):
- "Return a list of lines, `prefix` is indent prefix."
+ """
+ Dump status in metafile format.
+ Return a list of lines, `prefix` is indent prefix.
+ """
l = []
for k,v in self.stat.items():
if type(v) == types.ListType: vals = v
l.append(prefix + k + ":" + str(w) + "\n")
return l
- def write(self, file=None, name=None):
- if file is None:
- if name is not None:
- file = open(name, "w")
- else:
- file = sys.stdout
- self.write_nested(file, 0)
-
- def write_nested(self, file, indent):
- for k,v in self.stat.items():
- if type(v) == types.ListType: vals = v
- else: vals = [v]
- for w in vals:
- if isinstance(w, MoeStatus):
- file.write("\t" * indent + k + "(\n")
- w.write_nested(file, indent+1);
- file.write("\t" * indent + ")\n")
- else:
- file.write("\t" * indent + k + ":" + str(w) + "\n")
+ def write(self, f=None, name=None):
+ """
+ Write status (as a metafile) to `f` or file `name` or `stdout`
+ """
+ if not f and name is not None:
+ with open(name, "w") as f:
+ for l in self.dump():
+ f.write(l+"\n")
+ else:
+ if not f:
+ f = sys.stdout
+ for l in self.dump():
+ f.write(l+"\n")
def read(self, file=None, name=None):
if file is None: