Merge branch 'senslab2' of ssh://git.f-lab.fr/git/sfa into senslab2
[sfa.git] / sfa / storage / record.py
index 0d03bc6..f3aa8ee 100644 (file)
@@ -62,25 +62,27 @@ class Record:
         xml_record.parse_dict (input_dict)
         return xml_record.toxml()
 
-    def dump(self, format=None, dump_parents=False):
+    def dump(self, format=None, dump_parents=False, sort=False):
         if not format:
             format = 'text'
         else:
             format = format.lower()
         if format == 'text':
-            self.dump_text(dump_parents)
+            self.dump_text(dump_parents,sort=sort)
         elif format == 'xml':
-            print self.save_to_string()
+            print self.save_as_xml()
         elif format == 'simple':
             print self.dump_simple()
         else:
             raise Exception, "Invalid format %s" % format
 
-    def dump_text(self, dump_parents=False):
-        print "".join(['=' for i in range(40)])
+    def dump_text(self, dump_parents=False, sort=False):
+        print 40*'='
         print "RECORD"
         # print remaining fields
-        for attrib_name in self.fields():
+        fields=self.fields()
+        if sort: fields.sort()
+        for attrib_name in fields:
             attrib = getattr(self, attrib_name)
             # skip internals
             if attrib_name.startswith('_'):     continue
@@ -93,7 +95,7 @@ class Record:
             elif attrib_name in ['date created', 'last updated']:
                 print "    %s: %s" % (attrib_name, self.date_repr(attrib_name))
             else:
-                print "     %s: %s" % (attrib_name, attrib)
+                print "    %s: %s" % (attrib_name, attrib)
 
     def dump_simple(self):
         return "%s"%self