diff --git a/tools/roslaunch/src/roslaunch/loader.py b/tools/roslaunch/src/roslaunch/loader.py index dac9ac413d..8b884b6bd9 100644 --- a/tools/roslaunch/src/roslaunch/loader.py +++ b/tools/roslaunch/src/roslaunch/loader.py @@ -39,12 +39,13 @@ import os from copy import deepcopy +import yaml + from roslaunch.core import Param, RosbinExecutable, RLException, PHASE_SETUP from rosgraph.names import make_global_ns, ns_join, PRIV_NAME, load_mappings, is_legal_name, canonicalize_name #lazy-import global for yaml and rosparam -yaml = None rosparam = None class LoadException(RLException): @@ -88,12 +89,17 @@ def convert_value(value, type_): elif type_ == 'double': return float(value) elif type_ == 'bool' or type_ == 'boolean': - value = value.lower() + value = value.lower().strip() if value == 'true' or value == '1': return True elif value == 'false' or value == '0': return False raise ValueError("%s is not a '%s' type"%(value, type_)) + elif type_ == 'yaml': + try: + return yaml.load(value) + except yaml.parser.ParserError as e: + raise ValueError(e) else: raise ValueError("Unknown type '%s'"%type_) @@ -395,10 +401,6 @@ def load_rosparam(self, context, ros_config, cmd, param, file_, text, verbose=Tr text = f.read() # parse YAML text - # - lazy import - global yaml - if yaml is None: - import yaml # - lazy import: we have to import rosparam in oder to to configure the YAML constructors global rosparam if rosparam is None: @@ -468,7 +470,7 @@ def param_value(self, verbose, name, ptype, value, textfile, binfile, command): return convert_value(value.strip(), ptype) elif textfile is not None: with open(textfile, 'r') as f: - return f.read() + return convert_value(f.read(), ptype) elif binfile is not None: try: from xmlrpc.client import Binary @@ -498,7 +500,7 @@ def param_value(self, verbose, name, ptype, value, textfile, binfile, command): raise if c_value is None: raise ValueError("parameter: unable to get output of command [%s]"%command) - return c_value + return convert_value(c_value, ptype) else: #_param_tag prevalidates, so this should not be reachable raise ValueError("unable to determine parameter value") diff --git a/tools/roslaunch/test/xml/test-params-valid.xml b/tools/roslaunch/test/xml/test-params-valid.xml index 428a9b4c88..7ae940c90b 100644 --- a/tools/roslaunch/test/xml/test-params-valid.xml +++ b/tools/roslaunch/test/xml/test-params-valid.xml @@ -17,6 +17,9 @@ + + + @@ -32,6 +35,12 @@ + + + + + +