From 36075c32ac5451ba29dd962fc8337cad1d49fac3 Mon Sep 17 00:00:00 2001 From: Tony Mack Date: Tue, 3 Feb 2009 22:47:02 +0000 Subject: [PATCH] inital checkin of storage class --- geni/util/storage.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 geni/util/storage.py 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() -- 2.43.0