From: Andy Bavier Date: Wed, 1 Jun 2011 20:07:05 +0000 (-0400) Subject: Fixed initialization bug X-Git-Tag: sface-0.1-12~2 X-Git-Url: http://git.onelab.eu/?p=sface.git;a=commitdiff_plain;h=95e0d8d2ac7bc562d011faba71d8c0276cd31264 Fixed initialization bug SFA-36 If ~/.sfi/ is not present, it will be created. A missing ~/.sfi/sfi.config will not cause an error. --- diff --git a/sface/config.py b/sface/config.py index 781d0a8..885e6b6 100644 --- a/sface/config.py +++ b/sface/config.py @@ -70,8 +70,11 @@ class Config: def __init__(self): self.read_config() + def dirname (self): + return os.path.expanduser("~/.sfi/") + def filename (self): - return os.path.expanduser("~/.sfi/sfi_config") + return self.dirname() + "sfi_config" def read_config(self): tmp={} @@ -92,14 +95,21 @@ class Config: print "%-20s: %r"%(k, self.get(k)) def save_config(self): + configdir = self.dirname() + if not os.path.exists(configdir): + os.makedirs(configdir) + configfile = self.filename() + if not os.path.exists(configfile): + open(configfile, "w").close() + tmpfile = configfile + ".tmp" out = open(tmpfile, "w") lineno = 0 written_fields = [] fields = self.fields() - for line in open(configfile): + for line in open(configfile, "r"): lineno += 1 try: sfi, val = line.split('=')