Skip to content

Make set_cfg function return a bool indicating success or failure and… #914

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions mbed/mbed.py
Original file line number Diff line number Diff line change
Expand Up @@ -1905,6 +1905,7 @@ def __init__(self, path):

# Sets config value
def set(self, var, val):
retval = False
if not re.match(r'^([\w+-]+)$', var):
error("%s is invalid config variable name" % var)

Expand All @@ -1926,8 +1927,10 @@ def set(self, var, val):
try:
with open(fl, 'w') as f:
f.write('\n'.join(lines) + '\n')
retval = True
except (IOError, OSError):
warning("Unable to write config file %s" % fl)
return retval

# Gets config value
def get(self, var, default_val=None):
Expand Down Expand Up @@ -3286,11 +3289,11 @@ def config_(var=None, value=None, global_cfg=False, unset=False, list_config=Fal
"Change the current directory to a valid mbed program, set the current directory as an mbed program with \"mbed config root .\", or use the '--global' option to set global configuration." % program.path)
with cd(program.path):
if unset:
program.set_cfg(var, None)
action('Unset default %s in program "%s"' % (name, program.name))
if program.set_cfg(var, None):
action('Unset default %s in program "%s"' % (name, program.name))
elif value:
program.set_cfg(var, value)
action('%s now set as default %s in program "%s"' % (value, name, program.name))
if program.set_cfg(var, value):
action('%s now set as default %s in program "%s"' % (value, name, program.name))
else:
value = program.get_cfg(var)
if value:
Expand Down