X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Futil%2Fstorage.py;h=9033434f6cf8d146df5d147a29a2e147db0b5895;hb=ecc85e0b923922cf7117d29b380f5284edb88f21;hp=f80e2ff879c3d567deede4cce857c209d2762fcb;hpb=b28b70593bb5ac1d3017910736b64d8f3140a90f;p=sfa.git diff --git a/sfa/util/storage.py b/sfa/util/storage.py index f80e2ff8..9033434f 100644 --- a/sfa/util/storage.py +++ b/sfa/util/storage.py @@ -1,4 +1,5 @@ import os +from sfa.util.xml import XML class SimpleStorage(dict): """ @@ -8,8 +9,8 @@ class SimpleStorage(dict): db_filename = None type = 'dict' - def __init__(self, db_filename, db = {}): - + def __init__(self, db_filename, db = None): + if db is None: db={} dict.__init__(self, db) self.db_filename = db_filename @@ -18,8 +19,8 @@ class SimpleStorage(dict): db_file = open(self.db_filename, 'r') dict.__init__(self, eval(db_file.read())) elif os.path.exists(self.db_filename) and not os.path.isfile(self.db_filename): - raise IOError, '%s exists but is not a file. please remove it and try again' \ - % self.db_filename + raise IOError('%s exists but is not a file. please remove it and try again' \ + % self.db_filename) else: self.write() self.load() @@ -44,20 +45,19 @@ class XmlStorage(SimpleStorage): """ Parse an xml file and store it as a dict """ - data = RecordSpec() if os.path.exists(self.db_filename) and os.path.isfile(self.db_filename): - data.parseFile(self.db_filename) - dict.__init__(self, data.toDict()) + xml = XML(self.db_filename) + dict.__init__(self, xml.todict()) elif os.path.exists(self.db_filename) and not os.path.isfile(self.db_filename): - raise IOError, '%s exists but is not a file. please remove it and try again' \ - % self.db_filename + raise IOError('%s exists but is not a file. please remove it and try again' \ + % self.db_filename) else: self.write() self.load() def write(self): - data = RecordSpec() - data.parseDict(self) + xml = XML() + xml.parseDict(self) db_file = open(self.db_filename, 'w') db_file.write(data.toprettyxml()) db_file.close()