X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;ds=sidebyside;f=sfa%2Fstorage%2Frecord.py;h=9fcab19f8b81e03f7532e9a3684728a20cab740d;hb=799632c7651ebc441ac5b1588f142f6dbbc0a416;hp=254ca3d5fa31acb03f1afda7e14f4b413aafebae;hpb=b47f422b1d295ae66aaba6932a021055086079f2;p=sfa.git diff --git a/sfa/storage/record.py b/sfa/storage/record.py index 254ca3d5..9fcab19f 100644 --- a/sfa/storage/record.py +++ b/sfa/storage/record.py @@ -33,9 +33,18 @@ class Record: # fallback return "** undef_datetime **" - def todict (self): + # it may be important to exclude relationships, which fortunately + # + def todict (self, exclude_types=None): + if exclude_types is None: exclude_types=[] d=self.__dict__ - keys=[k for k in d.keys() if not k.startswith('_')] + def exclude (k,v): + if k.startswith('_'): return True + if exclude_types: + for exclude_type in exclude_types: + if isinstance (v,exclude_type): return True + return False + keys=[k for (k,v) in d.items() if not exclude(k,v)] return dict ( [ (k,d[k]) for k in keys ] ) def toxml(self): @@ -62,25 +71,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 @@ -89,7 +100,7 @@ class Record: # handle gid if attrib_name == 'gid': print " gid:" - print GID(attrib).dump_string(8, dump_parents) + print GID(string=attrib).dump_string(8, dump_parents) elif attrib_name in ['date created', 'last updated']: print " %s: %s" % (attrib_name, self.date_repr(attrib_name)) else: