]> mj.ucw.cz Git - moe.git/commitdiff
Added status write to string
authorTomas Gavenciak <gavento@ucw.cz>
Sat, 18 Sep 2010 06:58:05 +0000 (08:58 +0200)
committerTomas Gavenciak <gavento@ucw.cz>
Sat, 18 Sep 2010 06:58:05 +0000 (08:58 +0200)
Writing to file still direct, but I would like to rewrite using strings.

t/moe/status.py

index 3d72db476de48df25caf8c566cb1f14a429f922d..518fb1bc5dcb2089f3496c920c354bd707e69221 100644 (file)
@@ -37,6 +37,21 @@ class MoeStatus:
            m[k] = [m[k]]
        return m[k]
 
+    def str_lines(self, indent=""):
+       "Return a list of lines, `indent` is indent prefix."
+       l = []
+        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):
+                   l.append("\t" * indent + k + "(\n")
+                   l.extend(self.str_lines(indent+"  "))
+                   l.append("\t" * indent + ")\n")
+               else:
+                   l.append("\t" * indent + k + ":" + str(w) + "\n")
+       return l
+       
     def write(self, file=None, name=None):
        if file is None:
            if name is not None: