/usr/bin/roslocate is in python-rosinstall 0.7.7-6.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | #!/usr/bin/python
# Software License Agreement (BSD License)
#
# Copyright (c) 2010, Willow Garage, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of Willow Garage, Inc. nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
# Author: kwc
"""
Library for locating ROS packages and stacks using the centralized
index at ROS.org.
"""
from __future__ import print_function
NAME = 'roslocate'
import os
import sys
try:
from os import EX_USAGE
except ImportError:
EX_USAGE = 0, 1, 2
from optparse import OptionParser
from rosinstall.locate import get_manifest, \
get_www, get_repo, get_vcs, get_vcs_uri_for_branch,\
get_rosinstall, InvalidData, BRANCH_RELEASE, BRANCH_DEVEL
def options_to_branch(options):
# we don't let the user express the full range of options at the
# command-line, mainly for (1) simplicity and (2) the distro
# branch is not reliable.
if options.dev and options.rel:
sys.exit('only one of --dev and --rel can be used')
if options.dev:
return BRANCH_DEVEL
elif options.rel:
return BRANCH_RELEASE
return None
def cmd_get_rosinstall(name, data, type_, options=None):
branch = options_to_branch(options)
prefix = options.prefix if options is not None and options.prefix else ''
return get_rosinstall(name, data, type_, branch, prefix)
def get_type(name, data, type_, options=None):
return type_
def cmd_get_vcs_uri(name, data, type_, options=None):
return get_vcs_uri_for_branch(data, options_to_branch(options))
def cmd_get_vcs(name, data, type_, options=None):
return get_vcs(name, data, type_)
def cmd_get_www(name, data, type_, options=None):
return get_www(name, data, type_)
def get_description(name, data, type_, options=None):
if type_ == 'package':
return """
Type: package
Stack: %s
Description: %s
URL: %s
""" % (data.get('stack', 'none'), data.get('description', ''), data.get('url', ''))
elif type_ == 'stack':
return """
Type: package
Stack: %s
Description: %s
URL: %s
""" % (data.get('stack', 'none'), data.get('description', ''), data.get('url', ''))
else:
return """
Type: %s
Packages: %s
Description: %s
URL: %s
""" % (type_, ", ".join(data.get('packages', [])), data.get('description', ''), data.get('url', ''))
def cmd_get_repo(name, data, type_, options=None):
return get_repo(name, data, type_)
################################################################################
# Bind library to commandline implementation
def _fullusage(parser, error=EX_USAGE):
parser.print_help(file=sys.stderr)
sys.stderr.write("""
Commands:
info\t\tGet rosinstall info of resource
vcs\t\tGet name of source control system
type\t\tPackage or stack
uri\t\tGet source control URI of resource
www\t\tGet web page of resource
repo\t\tGet repository name of resource
describe\tGet description of resource
""")
sys.exit(error)
_cmds = {
# info/rosinstall are now identical
'info': cmd_get_rosinstall,
'rosinstall': cmd_get_rosinstall, #alias
'vcs': cmd_get_vcs,
'type': get_type,
'uri': cmd_get_vcs_uri,
'repo': cmd_get_repo,
'www': cmd_get_www,
'describe': get_description,
'description': get_description, # alias
}
def roslocate_main():
args = sys.argv
parser = OptionParser(usage="usage: %prog <command> <resource> <options>", prog=NAME)
parser.add_option("--prefix",
dest="prefix", default=False,
metavar="PATH",
help="path prefix for rosinstall")
# TODO: distro-specific return values
parser.add_option("--distro",
dest="distro",
help="fetch information for specific ROS distribution release (default: environment variable ROS_DISTRO if defined)")
# In this implementation, we're optimizing for the use case where
# the user wishes to do a source-based install of a released
# stack. The user also has an efficient flag for specifying that
# they want a development branch instead. We are not exposing
# users to the full range of devel/released/distro branches that
# the rosinstall file encodes, mainly because the distro branch is
# not reliable with DVCS systems like git. Thus, rosinstall
# abstracts the logic for determining what the correct released
# branch to use is.
parser.add_option("--dev",
dest="dev", default=False,
action="store_true",
help="fetch development branch information")
parser.add_option("--rel",
dest="rel", default=False,
action="store_true",
help="fetch release branch information")
# parse command
if '-h' in args or '--help' in args:
# printing commands in OptionParser is a mess
_fullusage(parser, error=0)
if len(args) < 2:
_fullusage(parser)
# noop parse for now. Will matter once we can pass in --distro
options, args = parser.parse_args()
cmd = args[0]
if not cmd in _cmds.keys():
_fullusage(parser)
if cmd not in ['info', 'rosinstall'] and options.prefix:
parser.error('--prefix only allowed with commands info, rosinstall')
if len(args) != 2:
parser.error("please provide a resource name (package or stack)")
name = args[1]
if not options.distro:
distro = os.environ['ROS_DISTRO'] if 'ROS_DISTRO' in os.environ else None
if distro:
print('Using ROS_DISTRO: %s' % distro, file=sys.stderr)
options.distro = distro
else:
parser.error("please provide the distro name with --distro DISTRO_NAME")
try:
data, type_, _ = get_manifest(name, options.distro)
except IOError:
sys.exit('cannot locate information about %s\n' % (name))
try:
print (_cmds[cmd](name, data, type_, options))
sys.stdout.flush() # raises correct error when used in a pipe
except InvalidData as e:
sys.stderr.write("%s\n" % e)
except IOError as ioe:
if ioe.errno == 32:
sys.exit(ioe)
raise
if __name__ == '__main__':
roslocate_main()
|