X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;ds=sidebyside;f=sfa%2Fstorage%2Frecord.py;h=9622268273d11906aa444efc79518bc293d9b337;hb=ecc85e0b923922cf7117d29b380f5284edb88f21;hp=593176513e9bb4dee64688cf87604b940b4c607f;hpb=c7c7ed1178348445dc4ae70ea0fd905625e95421;p=sfa.git
diff --git a/sfa/storage/record.py b/sfa/storage/record.py
index 59317651..96222682 100644
--- a/sfa/storage/record.py
+++ b/sfa/storage/record.py
@@ -1,3 +1,5 @@
+from __future__ import print_function
+
from sfa.util.sfatime import utcparse, datetime_to_string
from types import StringTypes
from datetime import datetime
@@ -16,7 +18,6 @@ class Record:
xml_dict = xml.todict()
self.load_from_dict(xml_dict)
-
def get_field(self, field):
return self.__dict__.get(field, None)
@@ -25,9 +26,10 @@ class Record:
# (and 'last_updated' does not make it at all)
# let's be flexible
def date_repr (self,fields):
- if not isinstance(fields,list): fields=[fields]
+ if not isinstance(fields,list):
+ fields = [fields]
for field in fields:
- value=getattr(self,field,None)
+ value = getattr(self,field,None)
if isinstance (value,datetime):
return datetime_to_string (value)
elif isinstance (value,(int,float)):
@@ -54,9 +56,11 @@ class Record:
def load_from_dict (self, d):
for (k,v) in d.iteritems():
# experimental
- if isinstance(v, StringTypes) and v.lower() in ['true']: v=True
- if isinstance(v, StringTypes) and v.lower() in ['false']: v=False
- setattr(self,k,v)
+ if isinstance(v, StringTypes) and v.lower() in ['true']:
+ v = True
+ if isinstance(v, StringTypes) and v.lower() in ['false']:
+ v = False
+ setattr(self, k, v)
# in addition we provide convenience for converting to and from xml records
# for this purpose only, we need the subclasses to define 'fields' as either
@@ -68,8 +72,8 @@ class Record:
def save_as_xml (self):
# xxx not sure about the scope here
input_dict = dict( [ (key, getattr(self,key)) for key in self.fields() if getattr(self,key,None) ] )
- xml_record=XML("")
- xml_record.parse_dict (input_dict)
+ xml_record = XML("")
+ xml_record.parse_dict(input_dict)
return xml_record.toxml()
def dump(self, format=None, dump_parents=False, sort=False):
@@ -80,17 +84,17 @@ class Record:
if format == 'text':
self.dump_text(dump_parents,sort=sort)
elif format == 'xml':
- print self.save_as_xml()
+ print(self.save_as_xml())
elif format == 'simple':
- print self.dump_simple()
+ print(self.dump_simple())
else:
- raise Exception, "Invalid format %s" % format
+ raise Exception("Invalid format %s" % format)
def dump_text(self, dump_parents=False, sort=False):
- print 40*'='
- print "RECORD"
+ print(40*'=')
+ print("RECORD")
# print remaining fields
- fields=self.fields()
+ fields = self.fields()
if sort: fields.sort()
for attrib_name in fields:
attrib = getattr(self, attrib_name)
@@ -100,12 +104,12 @@ class Record:
if callable (attrib): continue
# handle gid
if attrib_name == 'gid':
- print " gid:"
- print GID(string=attrib).dump_string(8, dump_parents)
+ print(" gid:")
+ 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))
+ 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