Merge branch 'geni-v3' of ssh://git.onelab.eu/git/sfa into geni-v3
[sfa.git] / sfa / util / storage.py
index 5d91539..89a2509 100644 (file)
@@ -1,6 +1,5 @@
 import os
-
-from sfa.util.rspec import RecordSpec
+from sfa.util.xml import XML
 
 class SimpleStorage(dict):
     """
@@ -10,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
     
@@ -46,10 +45,9 @@ 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
@@ -58,8 +56,8 @@ class XmlStorage(SimpleStorage):
             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()