Skip to content

Commit 569ade3

Browse files
committed
Handle OSError due to permissions when trying to write config file
1 parent ad83e15 commit 569ade3

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

mbed/mbed.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,7 +1305,10 @@ class Global(object):
13051305
def __init__(self):
13061306
self.path = os.path.join(os.path.expanduser("~"), '.mbed')
13071307
if not os.path.exists(self.path):
1308-
os.mkdir(self.path)
1308+
try:
1309+
os.mkdir(self.path)
1310+
except (IOError, OSError):
1311+
pass
13091312

13101313
def get_cfg(self, *args, **kwargs):
13111314
return Cfg(self.path).get(*args, **kwargs)
@@ -1327,7 +1330,7 @@ def set(self, var, val):
13271330
try:
13281331
with open(fl) as f:
13291332
lines = f.read().splitlines()
1330-
except IOError:
1333+
except (IOError, OSError):
13311334
lines = []
13321335

13331336
for line in lines:
@@ -1338,16 +1341,20 @@ def set(self, var, val):
13381341
if not val is None:
13391342
lines += [var+"="+val]
13401343

1341-
with open(fl, 'w') as f:
1342-
f.write('\n'.join(lines) + '\n')
1344+
try:
1345+
with open(fl, 'w') as f:
1346+
f.write('\n'.join(lines) + '\n')
1347+
except (IOError, OSError):
1348+
warning("Unable to write config file %s" % fl)
1349+
pass
13431350

13441351
# Gets config value
13451352
def get(self, var, default_val=None):
13461353
fl = os.path.join(self.path, self.file)
13471354
try:
13481355
with open(fl) as f:
13491356
lines = f.read().splitlines()
1350-
except IOError:
1357+
except (IOError, OSError):
13511358
lines = []
13521359

13531360
for line in lines:

0 commit comments

Comments
 (0)