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

Source Code for Module roslib.scriptutil

  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$ 
 34  # $Author$ 
 35   
 36  """ 
 37  Warning: do not use this library.  It is unstable and most of the routines 
 38  here have been superceded by other libraries (e.g. rospkg).  These 
 39  routines will likely be *deleted* in future releases. 
 40  """ 
 41   
 42  import os 
 43  import sys 
 44   
 45  import roslib.names  
 46   
 47  ## caller ID for master calls where caller ID is not vital 
 48  _GLOBAL_CALLER_ID = '/script' 
 49   
 50   
 51  import warnings 
52 -def deprecated(func):
53 """This is a decorator which can be used to mark functions 54 as deprecated. It will result in a warning being emmitted 55 when the function is used.""" 56 def newFunc(*args, **kwargs): 57 warnings.warn("Call to deprecated function %s." % func.__name__, 58 category=DeprecationWarning, stacklevel=2) 59 return func(*args, **kwargs)
60 newFunc.__name__ = func.__name__ 61 newFunc.__doc__ = func.__doc__ 62 newFunc.__dict__.update(func.__dict__) 63 return newFunc 64
65 @deprecated 66 -def script_resolve_name(script_name, name):
67 """ 68 Name resolver for scripts. Supports ROS_NAMESPACE. Does not 69 support remapping arguments. 70 @param name: name to resolve 71 @type name: str 72 @param script_name: name of script. script_name must not 73 contain a namespace. 74 @type script_name: str 75 @return: resolved name 76 @rtype: str 77 """ 78 if not name: #empty string resolves to namespace 79 return roslib.names.get_ros_namespace() 80 #Check for global name: /foo/name resolves to /foo/name 81 if roslib.names.is_global(name): 82 return name 83 #Check for private name: ~name resolves to /caller_id/name 84 elif roslib.names.is_private(name): 85 return ns_join(roslib.names.make_caller_id(script_name), name[1:]) 86 return roslib.names.get_ros_namespace() + name
87
88 @deprecated 89 -def get_master():
90 """ 91 Get an XMLRPC handle to the Master. It is recommended to use the 92 `rosgraph.masterapi` library instead, as it provides many 93 conveniences. 94 95 @return: XML-RPC proxy to ROS master 96 @rtype: xmlrpclib.ServerProxy 97 @raises ValueError if master URI is invalid 98 """ 99 try: 100 import xmlrpc.client as xmlrpcclient #Python 3.x 101 except ImportError: 102 import xmlrpclib as xmlrpcclient #Python 2.x 103 104 # changed this to not look as sys args and remove dependency on roslib.rosenv for cleaner cleanup 105 uri = os.environ['ROS_MASTER_URI'] 106 return xmlrpcclient.ServerProxy(uri)
107
108 @deprecated 109 -def get_param_server():
110 """ 111 @return: ServerProxy XML-RPC proxy to ROS parameter server 112 @rtype: xmlrpclib.ServerProxy 113 """ 114 return get_master()
115