Skip to content

Commit

Permalink
Merge branch '0.6.2' of github.com:MikeDacre/fyrd into 0.6.2
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeDacre committed Feb 7, 2018
2 parents db2d74e + 1acd390 commit 9ef18fd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
18 changes: 10 additions & 8 deletions fyrd/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,11 +555,13 @@ def create_config_interactive(prompt=True):
print("We store job profile information in a small config file.")
file_path = _os.path.expanduser(
_run.get_input('Where would you like that file to go? [{}]'
.format(config.get('jobs', 'profile_file')))
.format(
_run.exp_file(config.get('jobs', 'profile_file'))
))
).strip(' ').lower()

file_path = file_path if file_path else cnf['jobs']['profile_file']
cnf['jobs']['profile_file'] = _os.path.expanduser(file_path)
cnf['jobs']['profile_file'] = _run.exp_file(file_path)


# Temp file directory
Expand Down Expand Up @@ -949,8 +951,8 @@ def create_profiles(profs=None):
allow_no_value=True,
)

if _os.path.exists(config.get('jobs', 'profile_file')):
_os.remove(config.get('jobs', 'profile_file'))
if _os.path.exists(_run.exp_file(config.get('jobs', 'profile_file'))):
_os.remove(_run.exp_file(config.get('jobs', 'profile_file')))

init_conf = {}
if not profs or not isinstance(profs, dict):
Expand All @@ -965,7 +967,7 @@ def create_profiles(profs=None):

_config_from_dict(profiles, init_conf)

with open(config.get('jobs', 'profile_file'), 'w') as fout:
with open(_run.exp_file(config.get('jobs', 'profile_file')), 'w') as fout:
profiles.write(fout)


Expand All @@ -977,9 +979,9 @@ def load_profiles():
ConfigParser
profiles
"""
if not _os.path.isfile(config.get('jobs', 'profile_file')):
if not _os.path.isfile(_run.exp_file(config.get('jobs', 'profile_file'))):
create_profiles()
profiles.read(config.get('jobs', 'profile_file'))
profiles.read(_run.exp_file(config.get('jobs', 'profile_file')))

# Recreate DEFAULT if necessary.
def_prof = _config_to_dict(profiles)['DEFAULT']
Expand All @@ -1002,7 +1004,7 @@ def write_profiles():
ConfigParser
profiles
"""
with open(config.get('jobs', 'profile_file'), 'w') as fout:
with open(_run.exp_file(config.get('jobs', 'profile_file')), 'w') as fout:
profiles.write(fout)
return load_profiles()

Expand Down
9 changes: 9 additions & 0 deletions fyrd/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,15 @@ def open_zipped(infile, mode='r'):
return open(infile, mode)


def exp_file(infile):
"""Return an expanded path to a file."""
return _os.path.expandvars(
_re.sub(
'~', '$HOME', infile
)
)


def cmd_or_file(string):
"""If string is a file, return the contents, else return the string.
Expand Down

0 comments on commit 9ef18fd

Please sign in to comment.