Package roslib :: Module params
[frames] | no frames]

Source Code for Module roslib.params

 1  # Software License Agreement (BSD License) 
 2  # 
 3  # Copyright (c) 2008, Willow Garage, Inc. 
 4  # All rights reserved. 
 5  # 
 6  # Redistribution and use in source and binary forms, with or without 
 7  # modification, are permitted provided that the following conditions 
 8  # are met: 
 9  # 
10  #  * Redistributions of source code must retain the above copyright 
11  #    notice, this list of conditions and the following disclaimer. 
12  #  * Redistributions in binary form must reproduce the above 
13  #    copyright notice, this list of conditions and the following 
14  #    disclaimer in the documentation and/or other materials provided 
15  #    with the distribution. 
16  #  * Neither the name of Willow Garage, Inc. nor the names of its 
17  #    contributors may be used to endorse or promote products derived 
18  #    from this software without specific prior written permission. 
19  # 
20  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
21  # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
22  # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
23  # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
24  # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
25  # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
26  # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
27  # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
28  # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
29  # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
30  # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
31  # POSSIBILITY OF SUCH DAMAGE. 
32  # 
33  # Revision $Id: params.py 14580 2011-08-05 17:32:59Z kwc $ 
34  # $Author: kwc $ 
35  """ 
36  Utilities for accessing the Parameter Server 
37  """ 
38   
39  import sys 
40  import yaml 
41   
42  try: 
43      import xmlrpc.client as xmlrpcclient #Python 3.x 
44  except ImportError: 
45      import xmlrpclib as xmlrpcclient #Python 2.x 
46   
47  import roslib.rosenv 
48  from roslib.names import REMAP 
49   
50  _param_server = None 
51   
52 -def load_command_line_node_params(argv):
53 """ 54 Load node param mappings (aka private parameters) encoded in 55 command-line arguments, e.g. _foo:=bar. See also roslib.names.load_mappings. 56 @param argv: command-line arguments 57 @param argv: [str] 58 @return: param->value remappings. 59 @rtype: {str: val} 60 """ 61 mappings = {} 62 for arg in argv: 63 if REMAP in arg: 64 try: 65 src, dst = [x.strip() for x in arg.split(REMAP)] 66 if src and dst: 67 if len(src) > 1 and src[0] == '_' and src[1] != '_': 68 mappings[src[1:]] = yaml.load(dst) 69 except: 70 sys.stderr.write("ERROR: Invalid remapping argument '%s'\n"%arg) 71 return mappings
72
73 -def get_param(key):
74 """ 75 Retrieve parameter value from the Parameter Server. Each call to this 76 routine results in an actual network call to the Parameter Server. 77 Client must be an actual ROS node in order to implement a parameter cache. 78 79 @param key: name of parameter to fetch 80 @type key: str 81 @raise KeyError: if parameter is not set 82 """ 83 global _param_server 84 if _param_server is None: 85 _param_server = xmlrpcclient.ServerProxy(roslib.rosenv.get_master_uri()) 86 code, status, value = _param_server.getParam('/roslib', key) 87 if code != 1: #unwrap value with Python semantics 88 raise KeyError(key) 89 return value
90