From 6925f361fd6f889562cbfa9ba1fab6fbf67d6b48 Mon Sep 17 00:00:00 2001 From: Tony Mack Date: Wed, 4 Feb 2009 16:28:12 +0000 Subject: [PATCH] fixed bug in load(), If db_file doesnt exist create it and load an empty dict --- geni/util/storage.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/geni/util/storage.py b/geni/util/storage.py index 1fb2c9af..9dd094ea 100644 --- a/geni/util/storage.py +++ b/geni/util/storage.py @@ -1,3 +1,4 @@ +import os class SimpleStorage(dict): @@ -13,8 +14,16 @@ class SimpleStorage(dict): self.db_filename = db_filename def load(self): - db_file = open(self.db_filename, 'r') - dict.__init__(self, eval(db_file.read())) + if os.path.exists(self.db_filename) and os.path.isfile(self.db_filename): + 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 + else: + db_file = open(self.db_filename, 'w') + db_file.write('{}') + db_file.close() def write(self): db_file = open(self.db_filename, 'w') -- 2.43.0