3 class SimpleStorage(dict):
6 types = ['dict', 'tabbed', 'text', 'shell']
8 def __init__(self, db_filename, db = {}, type = 'dict'):
10 if type not in self.types:
11 raise Exception, "Invalid type %s, must be in %s" % (type, self.types)
13 dict.__init__(self, db)
14 self.db_filename = db_filename
17 if os.path.exists(self.db_filename) and os.path.isfile(self.db_filename):
18 db_file = open(self.db_filename, 'r')
19 dict.__init__(self, eval(db_file.read()))
20 elif os.path.exists(self.db_filename) and not os.path.isfile(self.db_filename):
21 raise IOError, '%s exists but is not a file. please remove it and try again' \
27 db_file = open(self.db_filename, 'w')
28 db_file.write(str(self))