-
Notifications
You must be signed in to change notification settings - Fork 914
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[roslaunch] Add yaml type for <param> tag #1045
Changes from 6 commits
b44af6c
242cfcd
7c80460
0112b87
ea65411
b746f71
5b8718c
2d8ae09
6e3e0b0
412d56e
c907f36
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,30 +70,36 @@ def convert_value(value, type_): | |
#attempt numeric conversion | ||
try: | ||
if '.' in value: | ||
return float(value) | ||
return float(value.strip()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not necessary. Same below. |
||
else: | ||
return int(value) | ||
return int(value.strip()) | ||
except ValueError as e: | ||
pass | ||
#bool | ||
lval = value.lower() | ||
lval = value.strip().lower() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In which case do you expect the strings |
||
if lval == 'true' or lval == 'false': | ||
return convert_value(value, 'bool') | ||
#string | ||
return value | ||
elif type_ == 'str' or type_ == 'string': | ||
return value | ||
elif type_ == 'int': | ||
return int(value) | ||
return int(value.strip()) | ||
elif type_ == 'double': | ||
return float(value) | ||
return float(value.strip()) | ||
elif type_ == 'bool' or type_ == 'boolean': | ||
value = value.lower() | ||
value = value.strip().lower() | ||
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': | ||
# - lazy import | ||
global yaml | ||
if yaml is None: | ||
import yaml | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please move the import to the top of the file and avoid the conditional block. |
||
return yaml.load(value) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How is that represented on the parameter server? Does this store a complex type (e.g. a nested dictionary) under a single There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is set like this:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should any yaml specific exceptions be catched here and a |
||
else: | ||
raise ValueError("Unknown type '%s'"%type_) | ||
|
||
|
@@ -465,10 +471,10 @@ def param_value(self, verbose, name, ptype, value, textfile, binfile, command): | |
@raise ValueError: if parameters are invalid | ||
""" | ||
if value is not None: | ||
return convert_value(value.strip(), ptype) | ||
return convert_value(value, 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 +504,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") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this necessary? I don't see any part in the patch which requires it.