Skip to content

Commit a8ef55b

Browse files
committed
Add check whether SCM is missing (OSError with error code 2)
1 parent b8202ea commit a8ef55b

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

mbed/mbed.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,30 @@ class ProcessException(Exception):
132132
def popen(command, stdin=None, **kwargs):
133133
# print for debugging
134134
log('"'+' '.join(command)+'"')
135-
proc = subprocess.Popen(command, **kwargs)
136-
135+
try:
136+
proc = subprocess.Popen(command, **kwargs)
137+
except OSError as e:
138+
if e[0] == 2:
139+
error(
140+
"Could not execute \"%s\".\n"
141+
"Please verify that it's installed and accessible from your current path by executing \"%s\".\n" % (command[0], command[0]), e[0])
142+
else:
143+
raise
144+
137145
if proc.wait() != 0:
138146
raise ProcessException(proc.returncode)
139147

140148
def pquery(command, stdin=None, **kwargs):
141149
#log("Query "+' '.join(command)+" in "+os.getcwd())
142-
proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, **kwargs)
150+
try:
151+
proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, **kwargs)
152+
except OSError as e:
153+
if e[0] == 2:
154+
error(
155+
"Could not execute \"%s\".\n"
156+
"Please verify that it's installed and accessible from your current path by executing \"%s\".\n" % (command[0], command[0]), e[0])
157+
else:
158+
raise
143159
stdout, _ = proc.communicate(stdin)
144160

145161
if proc.returncode != 0:
@@ -1426,8 +1442,7 @@ def toolchain(name=None):
14261442
if e[0] == 2:
14271443
error(
14281444
"Could not detect one of the command-line tools.\n"
1429-
"Please verify that you have Git and Mercurial installed and accessible from your current path by executing commands \"git\" and \"hg\".\n"
1430-
"Hint: check the last executed command above.", e[0])
1445+
"You could retry the last command with \"-v\" flag for verbose output\n", e[0])
14311446
else:
14321447
error('OS Error: %s' % e[1], e[0])
14331448
except KeyboardInterrupt as e:

0 commit comments

Comments
 (0)