Skip to content

Commit

Permalink
Check for permissions before writing configuration file. Fixes #662
Browse files Browse the repository at this point in the history
  • Loading branch information
chapmanb committed Feb 3, 2016
1 parent 6df9078 commit 4fc85df
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions gemini/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,11 @@ def write_gemini_config(new_config, dirs=None):
fname = _get_config_file(dirs, use_globals=False)
except ValueError:
fname = _find_best_config_file(dirs)
if not os.path.exists(os.path.dirname(fname)):
os.makedirs(os.path.dirname(fname))
with open(fname, "w") as out_handle:
yaml.dump(new_config, out_handle, allow_unicode=False,
default_flow_style=False)
if not os.access(fname, os.W_OK):
print("Warning: unable to write GEMINI configuration file to %s" % fname)
else:
if not os.path.exists(os.path.dirname(fname)):
os.makedirs(os.path.dirname(fname))
with open(fname, "w") as out_handle:
yaml.dump(new_config, out_handle, allow_unicode=False,
default_flow_style=False)

0 comments on commit 4fc85df

Please sign in to comment.