Skip to content

Commit 4636d84

Browse files
Shane Snovermadchutney
authored andcommitted
Make set_cfg function return a bool indicating success or failure and use that to inform additional logging (#914)
1 parent 61891bd commit 4636d84

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

mbed/mbed.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1905,6 +1905,7 @@ def __init__(self, path):
19051905

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

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

19321935
# Gets config value
19331936
def get(self, var, default_val=None):
@@ -3286,11 +3289,11 @@ def config_(var=None, value=None, global_cfg=False, unset=False, list_config=Fal
32863289
"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)
32873290
with cd(program.path):
32883291
if unset:
3289-
program.set_cfg(var, None)
3290-
action('Unset default %s in program "%s"' % (name, program.name))
3292+
if program.set_cfg(var, None):
3293+
action('Unset default %s in program "%s"' % (name, program.name))
32913294
elif value:
3292-
program.set_cfg(var, value)
3293-
action('%s now set as default %s in program "%s"' % (value, name, program.name))
3295+
if program.set_cfg(var, value):
3296+
action('%s now set as default %s in program "%s"' % (value, name, program.name))
32943297
else:
32953298
value = program.get_cfg(var)
32963299
if value:

0 commit comments

Comments
 (0)