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

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