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

Source Code for Module roslib.rospack

  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: rospack.py 11488 2010-10-12 19:28:00Z kwc $ 
 34  # $Author: kwc $ 
 35   
 36  """ 
 37  Wrappers for calling an processing return values from rospack and rosstack 
 38  """ 
 39   
 40  import os 
 41  import subprocess 
 42  import roslib.exceptions 
 43  import roslib.rosenv 
 44   
45 -def rospackexec(args):
46 """ 47 @return: result of executing rospack command (via subprocess). string will be strip()ed. 48 @rtype: str 49 @raise roslib.exceptions.ROSLibException: if rospack command fails 50 """ 51 rospack_bin = os.path.join(roslib.rosenv.get_ros_root(), 'bin', 'rospack') 52 val = (subprocess.Popen([rospack_bin] + args, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0] or '').strip() 53 if val.startswith('rospack:'): #rospack error message 54 raise roslib.exceptions.ROSLibException(val) 55 return val
56
57 -def rospack_depends_on_1(pkg):
58 """ 59 @param pkg: package name 60 @type pkg: str 61 @return: A list of the names of the packages which depend directly on pkg 62 @rtype: list 63 """ 64 return rospackexec(['depends-on1', pkg]).split()
65
66 -def rospack_depends_on(pkg):
67 """ 68 @param pkg: package name 69 @type pkg: str 70 @return: A list of the names of the packages which depend on pkg 71 @rtype: list 72 """ 73 return rospackexec(['depends-on', pkg]).split()
74
75 -def rospack_depends_1(pkg):
76 """ 77 @param pkg: package name 78 @type pkg: str 79 @return: A list of the names of the packages which pkg directly depends on 80 @rtype: list 81 """ 82 return rospackexec(['deps1', pkg]).split()
83
84 -def rospack_depends(pkg):
85 """ 86 @param pkg: package name 87 @type pkg: str 88 @return: A list of the names of the packages which pkg depends on 89 @rtype: list 90 """ 91 return rospackexec(['deps', pkg]).split()
92
93 -def rospack_plugins(pkg):
94 """ 95 @param pkg: package name 96 @type pkg: str 97 @return: A list of the names of the packages which provide a plugin for pkg 98 @rtype: list 99 """ 100 val = rospackexec(['plugins', '--attrib=plugin', pkg]) 101 if val: 102 return [tuple(x.split(' ')) for x in val.split('\n')] 103 else: 104 return []
105
106 -def rosstackexec(args):
107 """ 108 @return: result of executing rosstack command (via subprocess). string will be strip()ed. 109 @rtype: str 110 @raise roslib.exceptions.ROSLibException: if rosstack command fails 111 """ 112 rosstack_bin = os.path.join(roslib.rosenv.get_ros_root(), 'bin', 'rosstack') 113 val = (subprocess.Popen([rosstack_bin] + args, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0] or '').strip() 114 if val.startswith('rosstack:'): #rospack error message 115 raise roslib.exceptions.ROSLibException(val) 116 return val
117
118 -def rosstack_depends_on(s):
119 """ 120 @param s: stack name 121 @type s: str 122 @return: A list of the names of the stacks which depend on s 123 @rtype: list 124 """ 125 return rosstackexec(['depends-on', s]).split()
126
127 -def rosstack_depends_on_1(s):
128 """ 129 @param s: stack name 130 @type s: str 131 @return: A list of the names of the stacks which depend directly on s 132 @rtype: list 133 """ 134 return rosstackexec(['depends-on1', s]).split()
135
136 -def rosstack_depends(s):
137 """ 138 @param s: stack name 139 @type s: str 140 @return: A list of the names of the stacks which s depends on 141 @rtype: list 142 """ 143 return rosstackexec(['depends', s]).split()
144
145 -def rosstack_depends_1(s):
146 """ 147 @param s: stack name 148 @type s: str 149 @return: A list of the names of the stacks which s depends on directly 150 @rtype: list 151 """ 152 return rosstackexec(['depends1', s]).split()
153