Package rosdep :: Module main'
[frames] | no frames]

Source Code for Module rosdep.main'

  1  #!/usr/bin/env python 
  2  # Copyright (c) 2009, Willow Garage, Inc. 
  3  # All rights reserved. 
  4  #  
  5  # Redistribution and use in source and binary forms, with or without 
  6  # modification, are permitted provided that the following conditions are met: 
  7  #  
  8  #     * Redistributions of source code must retain the above copyright 
  9  #       notice, this list of conditions and the following disclaimer. 
 10  #     * Redistributions in binary form must reproduce the above copyright 
 11  #       notice, this list of conditions and the following disclaimer in the 
 12  #       documentation and/or other materials provided with the distribution. 
 13  #     * Neither the name of the Willow Garage, Inc. nor the names of its 
 14  #       contributors may be used to endorse or promote products derived from 
 15  #       this software without specific prior written permission. 
 16  #  
 17  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 18  # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 19  # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 20  # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 21  # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 22  # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 23  # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
 24  # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 25  # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 26  # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 27  # POSSIBILITY OF SUCH DAMAGE. 
 28   
 29  # Author Tully Foote/tfoote@willowgarage.com 
 30   
 31  #""" 
 32  #Library and command-line tool for calculating rosdeps. 
 33  #""" 
 34   
 35  import roslib; roslib.load_manifest("rosdep") 
 36  import roslib.stacks 
 37   
 38  import sys 
 39  import os 
 40   
 41  import rosdep.core as core 
 42   
 43  ################################################################################ 
 44  # COMMAND LINE PROCESSING 
 45       
 46  _usage = """usage: rosdep [options] <command> <args> 
 47   
 48  Commands: 
 49   
 50  rosdep generate_bash  <packages>... 
 51  rosdep satisfy <packages>... 
 52    will try to generate a bash script which will satisfy the  
 53    dependencies of package(s) on your operating system. 
 54   
 55  rosdep install <packages>... 
 56    will generate a bash script and then execute it. 
 57   
 58  rosdep depdb <packages>... 
 59    will generate the dependency database for package(s) and print 
 60    it to the console (note that the database will change depending 
 61    on which package(s) you query. 
 62   
 63  rosdep what_needs <rosdeps>... 
 64    will print a list of packages that declare a rosdep on (at least 
 65    one of) ROSDEP_NAME[S] 
 66   
 67  rosdep where_defined <rosdeps>... 
 68    will print a list of yaml files that declare a rosdep on (at least 
 69    one of) ROSDEP_NAME[S] 
 70   
 71  rosdep check <packages>... 
 72    will check if the dependencies of package(s) have been met. 
 73  """ 
 74   
 75  _commands = ['generate_bash', 'satisfy', 'install', 'depdb', 'what_needs', 'check', 'where_defined'] 
 76   
77 -def main():
78 from optparse import OptionParser 79 parser = OptionParser(usage=_usage, prog='rosdep') 80 parser.add_option("--verbose", "-v", dest="verbose", default=False, 81 action="store_true", help="verbose display") 82 parser.add_option("--include_duplicates", "-i", dest="include_duplicates", default=False, 83 action="store_true", help="do not deduplicate") 84 parser.add_option("--default-yes", "-y", dest="default_yes", default=False, 85 action="store_true", help="Tell the package manager to default to y or fail when installing") 86 parser.add_option("-r", dest="robust", default=False, 87 action="store_true", help="Continue installing despite errors.") 88 parser.add_option("-a", "--all", dest="rosdep_all", default=False, 89 action="store_true", help="select all packages") 90 91 options, args = parser.parse_args() 92 93 94 if len(args) == 0: 95 parser.error("Please enter a command") 96 command = args[0] 97 if not command in _commands: 98 parser.error("Unsupported command %s."%command) 99 if len(args) < 2 and not options.rosdep_all: 100 parser.error("Please enter arguments for '%s'"%command) 101 rdargs = args[1:] 102 103 verified_packages = [] 104 105 106 if not (command == "what_needs" or command == "where_defined" ): # package mode 107 if options.rosdep_all: 108 rdargs = roslib.packages.list_pkgs() 109 110 (verified_packages, rejected_packages) = roslib.stacks.expand_to_packages(rdargs) 111 valid_stacks = [s for s in roslib.stacks.list_stacks() if s in rdargs] 112 113 if len(rejected_packages) > 0: 114 print "Warning: could not identify %s as a package"%rejected_packages 115 if len(verified_packages) == 0 and len(valid_stacks) == 0: 116 parser.error("No Valid Packages or stacks listed as arguments") 117 118 else: # rosdep as argumets 119 if options.rosdep_all: 120 parser.error("-a, --all is not a valid option for this command") 121 122 ### Find all dependencies 123 try: 124 r = core.Rosdep(verified_packages, robust=options.robust) 125 except roslib.os_detect.OSDetectException, ex: 126 print "rosdep ABORTING. Failed to detect OS: %s"%ex 127 return 1 128 129 except roslib.exceptions.ROSLibException, ex: 130 print "rosdep ABORTING: %s"%ex 131 return 1 132 133 if options.verbose: 134 print "Detected OS: " + r.osi.get_name() 135 print "Detected Version: " + r.osi.get_version() 136 137 try: 138 if command == "generate_bash" or command == "satisfy": 139 print r.generate_script(include_duplicates=options.include_duplicates, default_yes=options.default_yes) 140 return 0 141 elif command == "install": 142 error = r.install(options.include_duplicates, options.default_yes) 143 if error: 144 print >> sys.stderr, "rosdep install ERROR:\n%s"%error 145 return 1 146 else: 147 return 0 148 except core.RosdepException, e: 149 print >> sys.stderr, "ERROR: %s"%e 150 return 1 151 152 try: 153 if command == "depdb": 154 print r.depdb(verified_packages) 155 return 0 156 157 elif command == "what_needs": 158 print '\n'.join(r.what_needs(rdargs)) 159 return 0 160 161 elif command == "where_defined": 162 print r.where_defined(rdargs) 163 return 0 164 165 elif command == "check": 166 return_val = 0 167 (output, scripts) = r.check() 168 if len(rejected_packages) > 0: 169 print >> sys.stderr, "Arguments %s are not packages"%rejected_packages 170 return_val = 1 171 if len(output) != 0: 172 print >> sys.stderr, output 173 return 1 174 if len(scripts)>0: 175 print >> sys.stderr, scripts 176 # not an error condition 177 178 return return_val 179 except core.RosdepException, e: 180 print >> sys.stderr, str(e) 181 return 1
182