Skip to content

Commit 91bdb81

Browse files
authored
Merge pull request #332 from screamerbg/development
mbed CLI 0.9.x fixes and minor enhancements
2 parents 70e1e51 + c4280be commit 91bdb81

File tree

3 files changed

+41
-14
lines changed

3 files changed

+41
-14
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ mbed CLI is supported on Windows, Linux and Mac OS X. We're keen to learn about
5454

5555
### Requirements
5656

57-
* **Python** - mbed CLI is a Python script, so you'll need Python in order to use it. mbed CLI was tested with [version 2.7 of Python](https://www.python.org/download/releases/2.7/).
57+
* **Python** - mbed CLI is a Python script, so you'll need Python in order to use it. mbed CLI was tested with [version 2.7.9 of Python](https://www.python.org/download/releases/2.7/).
5858

5959
* **Git and Mercurial** - mbed CLI supports both Git and Mercurial repositories, so you'll need to install both:
6060
* [Git](https://git-scm.com/).

mbed/mbed.py

+39-12
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636

3737
# Application version
38-
ver = '0.9.1'
38+
ver = '0.9.5'
3939

4040
# Default paths to Mercurial and Git
4141
hg_cmd = 'hg'
@@ -409,7 +409,7 @@ def discard():
409409
popen([hg_cmd, 'update', '-C'] + (['-v'] if very_verbose else ([] if verbose else ['-q'])))
410410

411411
def checkout(rev, clean=False, clean_files=False):
412-
info("Checkout \"%s\" in %s to %s" % (rev, os.path.basename(os.getcwd()), rev))
412+
info("Checkout \"%s\" in %s" % (rev if rev else "latest", os.path.basename(os.getcwd())))
413413
if clean_files:
414414
files = pquery([hg_cmd, 'status', '--no-status', '-ui']).splitlines()
415415
for f in files:
@@ -449,7 +449,7 @@ def geturl():
449449
lines = f.read().splitlines()
450450
if tagpaths in lines:
451451
idx = lines.index(tagpaths)
452-
m = re.match(r'^([\w_]+)\s*=\s*(.*)?$', lines[idx+1])
452+
m = re.match(r'^([\w_]+)\s*=\s*(.*)$', lines[idx+1])
453453
if m:
454454
if m.group(1) == 'default':
455455
default_url = m.group(2)
@@ -598,7 +598,7 @@ def merge(dest):
598598
def checkout(rev, clean=False):
599599
if not rev:
600600
return
601-
info("Checkout \"%s\" in %s to %s" % (rev, os.path.basename(os.getcwd()), rev))
601+
info("Checkout \"%s\" in %s" % (rev, os.path.basename(os.getcwd())))
602602
popen([git_cmd, 'checkout', rev] + (['-f'] if clean else []) + ([] if very_verbose else ['-q']))
603603
if Git.isdetached(): # try to find associated refs to avoid detached state
604604
refs = Git.getrefs(rev)
@@ -1286,6 +1286,20 @@ def add_tools(self, path):
12861286
rmtree_readonly(tools_dir)
12871287
error("An error occurred while cloning the mbed SDK tools from \"%s\"" % mbed_sdk_tools_url)
12881288

1289+
def update_tools(self, path):
1290+
if not os.path.exists(path):
1291+
os.mkdir(path)
1292+
with cd(path):
1293+
tools_dir = 'tools'
1294+
if os.path.exists(tools_dir):
1295+
with cd(tools_dir):
1296+
try:
1297+
action("Updating the mbed 2.0 SDK tools...")
1298+
repo = Repo.fromrepo()
1299+
repo.update()
1300+
except Exception:
1301+
error("An error occurred while update the mbed SDK tools from \"%s\"" % mbed_sdk_tools_url)
1302+
12891303
def get_tools(self):
12901304
mbed_tools_path = self.get_tools_dir()
12911305
if not mbed_tools_path:
@@ -1366,7 +1380,7 @@ def set(self, var, val):
13661380
lines = []
13671381

13681382
for line in lines:
1369-
m = re.match(r'^([\w+-]+)\=(.*)?$', line)
1383+
m = re.match(r'^([\w+-]+)\=(.*)$', line)
13701384
if m and m.group(1) == var:
13711385
lines.remove(line)
13721386

@@ -1390,7 +1404,7 @@ def get(self, var, default_val=None):
13901404
lines = []
13911405

13921406
for line in lines:
1393-
m = re.match(r'^([\w+-]+)\=(.*)?$', line)
1407+
m = re.match(r'^([\w+-]+)\=(.*)$', line)
13941408
if m and m.group(1) == var:
13951409
return m.group(2)
13961410
return default_val
@@ -1406,7 +1420,7 @@ def list(self):
14061420

14071421
vars = {}
14081422
for line in lines:
1409-
m = re.match(r'^([\w+-]+)\=(.*)?$', line)
1423+
m = re.match(r'^([\w+-]+)\=(.*)$', line)
14101424
if m and m.group(1) and m.group(1) != 'ROOT':
14111425
vars[m.group(1)] = m.group(2)
14121426
return vars
@@ -1554,11 +1568,15 @@ def new(name, scm='git', program=False, library=False, mbedlib=False, create_onl
15541568
p.set_root()
15551569
if not create_only and not p.get_os_dir() and not p.get_mbedlib_dir():
15561570
url = mbed_lib_url if mbedlib else mbed_os_url
1571+
d = 'mbed' if mbedlib else 'mbed-os'
15571572
try:
15581573
with cd(d_path):
15591574
add(url, depth=depth, protocol=protocol, top=False)
1575+
if not mbedlib:
1576+
with cd(d):
1577+
repo = Repo.fromrepo()
1578+
repo.checkout('latest')
15601579
except Exception as e:
1561-
d = 'mbed' if mbedlib else 'mbed-os'
15621580
if os.path.isdir(os.path.join(d_path, d)):
15631581
rmtree_readonly(os.path.join(d_path, d))
15641582
raise e
@@ -1707,8 +1725,10 @@ def deploy(ignore=False, depth=None, protocol=None, top=True):
17071725
repo.ignore(relpath(repo.path, lib.path))
17081726

17091727
if top:
1710-
Program(repo.path).post_action()
1711-
1728+
program = Program(repo.path)
1729+
program.post_action()
1730+
if program.is_classic:
1731+
program.update_tools('.temp')
17121732

17131733
# Publish command
17141734
@subcommand('publish',
@@ -1869,6 +1889,8 @@ def update(rev=None, clean=False, clean_files=False, clean_deps=False, ignore=Fa
18691889
program = Program(repo.path)
18701890
program.set_root()
18711891
program.post_action()
1892+
if program.is_classic:
1893+
program.update_tools('.temp')
18721894

18731895

18741896
# Synch command
@@ -2157,7 +2179,7 @@ def test_(toolchain=None, target=None, compile_list=False, run_list=False, compi
21572179

21582180
# Export command
21592181
@subcommand('export',
2160-
dict(name=['-i', '--ide'], help='IDE to create project files for. Example: UVISION4, UVISION5, GCC_ARM, IAR, COIDE', required=True),
2182+
dict(name=['-i', '--ide'], help='IDE to create project files for. Example: UVISION4, UVISION5, GCC_ARM, IAR, COIDE'),
21612183
dict(name=['-m', '--target'], help='Export for target MCU. Example: K64F, NUCLEO_F401RE, NRF51822...'),
21622184
dict(name='--source', action='append', help='Source directory. Default: . (current dir)'),
21632185
dict(name=['-c', '--clean'], action='store_true', help='Clean the build directory before compiling'),
@@ -2194,7 +2216,7 @@ def export(ide=None, target=None, source=False, clean=False, supported=False):
21942216

21952217
popen(['python', '-u', os.path.join(tools_dir, 'project.py')]
21962218
+ list(chain.from_iterable(izip(repeat('-D'), macros)))
2197-
+ ['-i', ide.lower(), '-m', target]
2219+
+ (['-i', ide.lower(), '-m', target] if ide else [])
21982220
+ (['-c'] if clean else [])
21992221
+ list(chain.from_iterable(izip(repeat('--source'), source)))
22002222
+ args,
@@ -2335,6 +2357,11 @@ def main():
23352357

23362358
# Help messages adapt based on current dir
23372359
cwd_root = os.getcwd()
2360+
2361+
if sys.version_info[0] != 2 or sys.version_info[1] < 7:
2362+
error(
2363+
"mbed CLI is compatible with Python version >= 2.7 and < 3.0\n"
2364+
"Please refer to the online guide available at https://github.com/ARMmbed/mbed-cli")
23382365

23392366
# Parse/run command
23402367
if len(sys.argv) <= 1:

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
setup(
2020
name="mbed-cli",
21-
version="0.9.1",
21+
version="0.9.5",
2222
description="ARM mbed command line tool for repositories version control, publishing and updating code from remotely hosted repositories (GitHub, GitLab and mbed.org), and invoking mbed OS own build system and export functions, among other operations",
2323
long_description=LONG_DESC,
2424
url='http://github.com/ARMmbed/mbed-cli',

0 commit comments

Comments
 (0)