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$ 
 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 subprocess 
 43  import sys 
 44  import warnings 
 45   
 46  import roslib.exceptions 
 47   
 48  import rospkg  # noqa: F401 
 49   
 50  if sys.hexversion > 0x03000000:  # Python3 
 51      python3 = True 
 52  else: 
 53      python3 = False 
 54   
 55   
 56  warnings.warn('roslib.rospack is deprecated, please use rospkg', stacklevel=2) 
 57   
 58   
59 -def rospackexec(args):
60 """ 61 @return: result of executing rospack command (via subprocess). string will be strip()ed. 62 @rtype: str 63 @raise roslib.exceptions.ROSLibException: if rospack command fails 64 """ 65 rospack_bin = 'rospack' 66 if python3: 67 val = subprocess.Popen([rospack_bin] + args, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0] 68 val = val.decode().strip() 69 else: 70 val = (subprocess.Popen([rospack_bin] + args, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0] or '').strip() 71 if val.startswith('rospack:'): # rospack error message 72 raise roslib.exceptions.ROSLibException(val) 73 return val
74 75
76 -def rospack_depends_on_1(pkg):
77 """ 78 @param pkg: package name 79 @type pkg: str 80 @return: A list of the names of the packages which depend directly on pkg 81 @rtype: list 82 """ 83 return rospackexec(['depends-on1', pkg]).split()
84 85
86 -def rospack_depends_on(pkg):
87 """ 88 @param pkg: package name 89 @type pkg: str 90 @return: A list of the names of the packages which depend on pkg 91 @rtype: list 92 """ 93 return rospackexec(['depends-on', pkg]).split()
94 95
96 -def rospack_depends_1(pkg):
97 """ 98 @param pkg: package name 99 @type pkg: str 100 @return: A list of the names of the packages which pkg directly depends on 101 @rtype: list 102 """ 103 return rospackexec(['deps1', pkg]).split()
104 105
106 -def rospack_depends(pkg):
107 """ 108 @param pkg: package name 109 @type pkg: str 110 @return: A list of the names of the packages which pkg depends on 111 @rtype: list 112 """ 113 return rospackexec(['deps', pkg]).split()
114 115
116 -def rospack_plugins(pkg):
117 """ 118 @param pkg: package name 119 @type pkg: str 120 @return: A list of the names of the packages which provide a plugin for pkg 121 @rtype: list 122 """ 123 val = rospackexec(['plugins', '--attrib=plugin', pkg]) 124 if val: 125 return [tuple(x.split(' ')) for x in val.split('\n')] 126 else: 127 return []
128 129
130 -def rosstackexec(args):
131 """ 132 @return: result of executing rosstack command (via subprocess). string will be strip()ed. 133 @rtype: str 134 @raise roslib.exceptions.ROSLibException: if rosstack command fails 135 """ 136 rosstack_bin = 'rosstack' 137 if python3: 138 val = subprocess.Popen([rosstack_bin] + args, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0] 139 val = val.decode().strip() 140 else: 141 val = (subprocess.Popen([rosstack_bin] + args, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0] or '').strip() 142 if val.startswith('rosstack:'): # rospack error message 143 raise roslib.exceptions.ROSLibException(val) 144 return val
145 146
147 -def rosstack_depends_on(s):
148 """ 149 @param s: stack name 150 @type s: str 151 @return: A list of the names of the stacks which depend on s 152 @rtype: list 153 """ 154 return rosstackexec(['depends-on', s]).split()
155 156
157 -def rosstack_depends_on_1(s):
158 """ 159 @param s: stack name 160 @type s: str 161 @return: A list of the names of the stacks which depend directly on s 162 @rtype: list 163 """ 164 return rosstackexec(['depends-on1', s]).split()
165 166
167 -def rosstack_depends(s):
168 """ 169 @param s: stack name 170 @type s: str 171 @return: A list of the names of the stacks which s depends on 172 @rtype: list 173 """ 174 return rosstackexec(['depends', s]).split()
175 176
177 -def rosstack_depends_1(s):
178 """ 179 @param s: stack name 180 @type s: str 181 @return: A list of the names of the stacks which s depends on directly 182 @rtype: list 183 """ 184 return rosstackexec(['depends1', s]).split()
185