return None
raise
- def get_or_create_config(self, name, default_fn, mode="w"):
+ def get_or_create_config(self, name, default_fn, mode="w", filemode=None):
"""Try to get the (string) contents of a config file, and return it.
Any leading or trailing whitespace will be stripped from the data.
value = default_fn()
fn = os.path.join(self.basedir, name)
try:
- open(fn, mode).write(value)
+ f = open(fn, mode)
+ f.write(value)
+ f.close()
+ if filemode is not None:
+ os.chmod(fn, filemode)
except EnvironmentError, e:
self.log("Unable to write config file '%s'" % fn)
self.log(e)
+ value = value.strip()
return value
def write_config(self, name, value, mode="w"):