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 7386 2009-12-17 01:49:35Z kwc $ 
34  # $Author: kwc $ 
35  """ 
36  Utilities for accessing the Parameter Server 
37  """ 
38   
39  import sys 
40  import xmlrpclib 
41   
42  import roslib.rosenv 
43  from roslib.names import REMAP 
44   
45  _param_server = None 
46   
47 -def load_command_line_node_params(argv):
48 """ 49 Load node param mappings (aka private parameters) encoded in 50 command-line arguments, e.g. _foo:=bar. See also roslib.names.load_mappings. 51 @param argv: command-line arguments 52 @param argv: [str] 53 @return: param->value remappings. 54 @rtype: {str: val} 55 """ 56 try: 57 import yaml 58 except ImportError, e: 59 print >> sys.stderr, "Cannot import yaml. Please make sure the pyyaml system dependency is installed" 60 raise e 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 print >> sys.stderr, "ERROR: Invalid remapping argument '%s'"%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 = xmlrpclib.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