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 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
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
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" ):
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:
119 if options.rosdep_all:
120 parser.error("-a, --all is not a valid option for this command")
121
122
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
177
178 return return_val
179 except core.RosdepException, e:
180 print >> sys.stderr, str(e)
181 return 1
182