Skip to content

Commit b39323d

Browse files
committed
Fixed handling of missing tools (was using incorrect errno.EPERM)
Fixed status() being passed instead of var status to sys.exit() Fixed 'scm' param to new() Fixed user interrupt handling during new()
1 parent 325e96b commit b39323d

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

mbed/mbed.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def popen(command, stdin=None, **kwargs):
136136
try:
137137
proc = subprocess.Popen(command, **kwargs)
138138
except OSError as e:
139-
if e[0] == errno.EPERM:
139+
if e[0] == errno.ENOENT:
140140
error(
141141
"Could not execute \"%s\".\n"
142142
"Please verify that it's installed and accessible from your current path by executing \"%s\".\n" % (command[0], command[0]), e[0])
@@ -151,7 +151,7 @@ def pquery(command, stdin=None, **kwargs):
151151
try:
152152
proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, **kwargs)
153153
except OSError as e:
154-
if e[0] == errno.EPERM:
154+
if e[0] == errno.ENOENT:
155155
error(
156156
"Could not execute \"%s\".\n"
157157
"Please verify that it's installed and accessible from your current path by executing \"%s\".\n" % (command[0], command[0]), e[0])
@@ -956,7 +956,7 @@ def thunk(parsed_args):
956956
dict(name='--depth', nargs='?', help='Number of revisions to fetch the mbed OS repository when creating new program. Default: all revisions.'),
957957
dict(name='--protocol', nargs='?', help='Transport protocol when fetching the mbed OS repository when creating new program. Supported: https, http, ssh, git. Default: inferred from URL.'),
958958
help='Create a new program based on the specified source control management. Will create a new library when called from inside a local program. Supported SCMs: %s.' % (', '.join([s.name for s in scms.values()])))
959-
def new(name, tscm='git', depth=None, protocol=None):
959+
def new(name, scm='git', depth=None, protocol=None):
960960
global cwd_root
961961

962962
d_path = name or os.getcwd()
@@ -969,7 +969,7 @@ def new(name, tscm='git', depth=None, protocol=None):
969969
# Find parent repository before the new one is created
970970
p_path = Repo.findrepo(d_path)
971971

972-
repo_scm = [s for s in scms.values() if s.name == tscm.lower()]
972+
repo_scm = [s for s in scms.values() if s.name == scm.lower()]
973973
if not repo_scm:
974974
error("Please specify one of the following source control management systems: %s" % ', '.join([s.name for s in scms.values()]), 1)
975975

@@ -989,9 +989,10 @@ def new(name, tscm='git', depth=None, protocol=None):
989989
try:
990990
with cd(d_path):
991991
add(mbed_os_url, depth=depth, protocol=protocol)
992-
except:
993-
rmtree_readonly(os.path.join(d_path, 'mbed-os'))
994-
raise
992+
except Exception as e:
993+
if os.path.isdir(os.path.join(d_path, 'mbed-os')):
994+
rmtree_readonly(os.path.join(d_path, 'mbed-os'))
995+
raise e
995996
if d_path:
996997
os.chdir(d_path)
997998

@@ -1291,7 +1292,7 @@ def list_(all=False, prefix='', p_path=None, ignore=False):
12911292
@subcommand('status',
12921293
dict(name=['-I', '--ignore'], action='store_true', help='Ignore errors regarding missing libraries.'),
12931294
help='Show status of the current %s and its dependencies.' % cwd_type)
1294-
def status(ignore=False):
1295+
def status_(ignore=False):
12951296
repo = Repo.fromrepo()
12961297
if repo.scm.dirty():
12971298
action("Status for \"%s\":" % repo.name)
@@ -1484,6 +1485,7 @@ def toolchain_(name=None):
14841485
sys.exit(1)
14851486

14861487
args, remainder = parser.parse_known_args()
1488+
status = 1
14871489

14881490
try:
14891491
verbose = args.verbose
@@ -1492,7 +1494,7 @@ def toolchain_(name=None):
14921494
except ProcessException as e:
14931495
error('Subrocess exit with error code %d' % e[0], e[0])
14941496
except OSError as e:
1495-
if e[0] == errno.EPERM:
1497+
if e[0] == errno.ENOENT:
14961498
error(
14971499
"Could not detect one of the command-line tools.\n"
14981500
"You could retry the last command with \"-v\" flag for verbose output\n", e[0])

0 commit comments

Comments
 (0)