From: Tony Mack Date: Tue, 3 Feb 2009 22:47:02 +0000 (+0000) Subject: inital checkin of storage class X-Git-Tag: sfa-0.9-0@14641~675 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=36075c32ac5451ba29dd962fc8337cad1d49fac3;p=sfa.git inital checkin of storage class --- diff --git a/geni/util/storage.py b/geni/util/storage.py new file mode 100644 index 00000000..ec220b6f --- /dev/null +++ b/geni/util/storage.py @@ -0,0 +1,25 @@ + +class SimpleStorage(dict): + + db_filename = None + types = ['dict', 'tabbed', 'text', 'shell'] + + def __init__(self, db_filename, db = {}, type = 'dict'): + + if type not in self.types: + raise Exception, "Invalid type %s, must be in %s" % (type, self.types) + self.type = type + dict.__init__(self, db) + self.db_filename = db_filename + + def load(self): + db_file = open(self.db_filename, 'r') + dict.__init__(self, eval(db_file.read())) + + def write(self): + db_file = open(self.db_filename, 'w') + db_file.write(str(self) + db_file.close() + + def sync(self): + self.write()