Skip to content

Commit c0c9cac

Browse files
committed
Use errno module to detect OSError error codes rather than cryptic numbers
1 parent 82bd218 commit c0c9cac

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

mbed/mbed.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import contextlib
1111
import shutil
1212
import stat
13+
import errno
1314
from itertools import chain, izip, repeat
1415

1516

@@ -135,7 +136,7 @@ def popen(command, stdin=None, **kwargs):
135136
try:
136137
proc = subprocess.Popen(command, **kwargs)
137138
except OSError as e:
138-
if e[0] == 2:
139+
if e[0] == errno.EPERM:
139140
error(
140141
"Could not execute \"%s\".\n"
141142
"Please verify that it's installed and accessible from your current path by executing \"%s\".\n" % (command[0], command[0]), e[0])
@@ -150,7 +151,7 @@ def pquery(command, stdin=None, **kwargs):
150151
try:
151152
proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, **kwargs)
152153
except OSError as e:
153-
if e[0] == 2:
154+
if e[0] == errno.EPERM:
154155
error(
155156
"Could not execute \"%s\".\n"
156157
"Please verify that it's installed and accessible from your current path by executing \"%s\".\n" % (command[0], command[0]), e[0])
@@ -1439,7 +1440,7 @@ def toolchain(name=None):
14391440
except ProcessException as e:
14401441
error('Subrocess exit with error code %d' % e[0], e[0])
14411442
except OSError as e:
1442-
if e[0] == 2:
1443+
if e[0] == errno.EPERM:
14431444
error(
14441445
"Could not detect one of the command-line tools.\n"
14451446
"You could retry the last command with \"-v\" flag for verbose output\n", e[0])

0 commit comments

Comments
 (0)