Skip to content

Commit e6d9717

Browse files
committed
Language fixes and safe check whether the tools path exists before os.path.abspath()
1 parent 3d28850 commit e6d9717

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

mbed/mbed.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -848,12 +848,12 @@ def get_tools_dir(self):
848848
def post_clone(self):
849849
mbed_os_path = self.get_os_dir()
850850
if not mbed_os_path:
851-
warning("Cannot find the mbed-os directory in \"%s\"" % self.path)
851+
warning("Cannot find the mbed OS directory in \"%s\"" % self.path)
852852
return False
853853

854854
mbed_tools_path = self.get_tools_dir()
855855
if not mbed_tools_path:
856-
warning("Cannot find the mbed-os tools directory in \"%s\"" % mbed_os_path)
856+
warning("Cannot find the mbed OS tools directory in \"%s\"" % mbed_os_path)
857857
return False
858858

859859
if (not os.path.isfile(os.path.join(self.path, 'mbed_settings.py')) and
@@ -953,8 +953,8 @@ def thunk(parsed_args):
953953
@subcommand('new',
954954
dict(name='name', help='Destination name or path'),
955955
dict(name='scm', nargs='?', help='Source control management. Currently supported: %s. Default: git' % ', '.join([s.name for s in scms.values()])),
956-
dict(name='--depth', nargs='?', help='Number of revisions to fetch the mbed-os repository when creating new program. Default: all revisions.'),
957-
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.'),
956+
dict(name='--depth', nargs='?', help='Number of revisions to fetch the mbed OS repository when creating new program. Default: all revisions.'),
957+
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()])))
959959
def new(name, tscm='git', depth=None, protocol=None):
960960
global cwd_root
@@ -984,7 +984,8 @@ def new(name, tscm='git', depth=None, protocol=None):
984984
# This helps sub-commands to display relative paths to the created program
985985
cwd_root = os.path.abspath(d_path)
986986

987-
if len(os.listdir(d_path)) <= 1:
987+
program = Program(d_path)
988+
if not program.get_os_dir():
988989
try:
989990
with cd(d_path):
990991
add(mbed_os_url, depth=depth, protocol=protocol)
@@ -1323,9 +1324,10 @@ def compile(toolchain=None, mcu=None, source=False, build=False, compile_library
13231324

13241325
with cd(program.path):
13251326
mbed_os_path = program.get_os_dir()
1326-
tools_dir = os.path.abspath(program.get_tools_dir())
1327-
if not mbed_os_path or not tools_dir:
1328-
error('The mbed-os codebase or tools were not found in "%s".' % program.path, -1)
1327+
mbed_tools_path = program.get_tools_dir()
1328+
if not mbed_os_path or not mbed_tools_path:
1329+
error('The mbed OS codebase or tools were not found in "%s".' % program.path, -1)
1330+
tools_dir = os.path.abspath(mbed_tools_path)
13291331

13301332
target = mcu if mcu else program.get_cfg('TARGET')
13311333
if target is None:
@@ -1398,7 +1400,7 @@ def test(tlist=False):
13981400
# Change directories to the program root to use mbed OS tools
13991401
with cd(program.path):
14001402
if not program.get_tools_dir():
1401-
error('The mbed-os codebase or tools were not found in "%s".' % program.path, -1)
1403+
error('The mbed OS codebase or tools were not found in "%s".' % program.path, -1)
14021404

14031405
# Prepare environment variables
14041406
env = os.environ.copy()
@@ -1424,7 +1426,7 @@ def export(ide=None, mcu=None):
14241426
# Change directories to the program root to use mbed OS tools
14251427
with cd(program.path):
14261428
if not program.get_tools_dir():
1427-
error('The mbed-os codebase or tools were not found in "%s".' % program.path, -1)
1429+
error('The mbed OS codebase or tools were not found in "%s".' % program.path, -1)
14281430

14291431
target = mcu if mcu else program.get_cfg('TARGET')
14301432
if target is None:

0 commit comments

Comments
 (0)