from sfa.util.xml import XML
from sfa.trust.gid import GID
+from sfa.util.sfalogging import logger
+
class Record:
def __init__(self, dict=None, xml=None):
# fallback
return "** undef_datetime **"
- def todict (self):
- d=self.__dict__
- keys=[k for k in d.keys() if not k.startswith('_')]
- return dict ( [ (k,d[k]) for k in keys ] )
+ #
+ # need to filter out results, esp. wrt relationships
+ # exclude_types must be a tuple so we can use isinstance
+ #
+ def todict (self, exclude_types=None):
+ if exclude_types is None:
+ exclude_types = ()
+ d = self.__dict__
+ def exclude (k, v):
+ return k.startswith('_') or isinstance (v, exclude_types)
+ keys = [ k for k, v in d.items() if not exclude(k, v) ]
+ return { k : d[k] for k in keys }
def toxml(self):
return self.save_as_xml()
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_as_xml()
elif format == '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
# 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: