Skip to content
This repository was archived by the owner on Jan 15, 2021. It is now read-only.

Commit 28bb1f4

Browse files
committed
Merge pull request #599 from autopulated/link-invalid
Improve validation when `yotta link`ing
2 parents 1193ac8 + 1b763cd commit 28bb1f4

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

yotta/lib/validate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def componentNameValidationError(component_name):
4949

5050
def targetNameValidationError(target_name):
5151
if not re.match(Target_Name_Regex, target_name):
52-
return 'Module name "%s" is invalid - must contain only lowercase a-z, 0-9 and hyphen, with no spaces.' % target_name
52+
return 'Target name "%s" is invalid - must contain only lowercase a-z, 0-9, + and hyphen, with no spaces.' % target_name
5353
return None
5454

5555
def componentNameCoerced(component_name):

yotta/link.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2014 ARM Limited
1+
# Copyright 2014-2015 ARM Limited
22
#
33
# Licensed under the Apache License, Version 2.0
44
# See LICENSE file for details.
@@ -29,6 +29,10 @@ def execCommand(args, following_args):
2929
if not c:
3030
return 1
3131
if args.component:
32+
err = validate.componentNameValidationError(args.component)
33+
if err:
34+
logging.error(err)
35+
return 1
3236
fsutils.mkDirP(os.path.join(os.getcwd(), 'yotta_modules'))
3337
src = os.path.join(folders.globalInstallDirectory(), args.component)
3438
dst = os.path.join(os.getcwd(), 'yotta_modules', args.component)

yotta/link_target.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2014 ARM Limited
1+
# Copyright 2014-2015 ARM Limited
22
#
33
# Licensed under the Apache License, Version 2.0
44
# See LICENSE file for details.
@@ -10,10 +10,10 @@
1010
# colorama, BSD 3-Clause license, color terminal output, pip install colorama
1111
import colorama
1212

13-
# Target, , represents an installed target, internal
14-
from .lib import target
1513
# fsutils, , misc filesystem utils, internal
1614
from .lib import fsutils
15+
# validate, , validate things, internal
16+
from .lib import validate
1717
# folders, , get places to install things, internal
1818
from .lib import folders
1919

@@ -26,20 +26,25 @@ def addOptions(parser):
2626

2727
def execCommand(args, following_args):
2828
if args.target:
29+
c = validate.currentDirectoryModule()
30+
if not c:
31+
return 1
32+
err = validate.targetNameValidationError(args.target)
33+
if err:
34+
logging.error(err)
35+
return 1
2936
fsutils.mkDirP(os.path.join(os.getcwd(), 'yotta_targets'))
3037
src = os.path.join(folders.globalTargetInstallDirectory(), args.target)
3138
dst = os.path.join(os.getcwd(), 'yotta_targets', args.target)
3239
# if the target is already installed, rm it
3340
fsutils.rmRf(dst)
3441
else:
35-
c = target.Target(os.getcwd())
36-
if not c:
37-
logging.debug(str(c.error))
38-
logging.error('The current directory does not contain a valid target.')
42+
t = validate.currentDirectoryTarget()
43+
if not t:
3944
return 1
4045
fsutils.mkDirP(folders.globalTargetInstallDirectory())
4146
src = os.getcwd()
42-
dst = os.path.join(folders.globalTargetInstallDirectory(), c.getName())
47+
dst = os.path.join(folders.globalTargetInstallDirectory(), t.getName())
4348

4449
if args.target:
4550
realsrc = fsutils.realpath(src)

0 commit comments

Comments
 (0)