34 from __future__
import print_function
36 from optparse
import OptionParser
42 import genmsg.command_line
43 from catkin
import terminal_color
45 from catkin_pkg
import package, packages, workspaces, topological_order
47 from genmsg
import MsgGenerationException
48 from . generate
import generate_msg, generate_srv
51 print(
"%(progname)s file(s)"%vars())
55 for ws
in workspaces.get_spaces():
56 pkgs = packages.find_packages(ws)
57 for pkg
in pkgs.values():
61 if pkg.name
not in pkg_map:
62 pkg_map[pkg.name] = pkg
67 """Get dependencies written as run_depend in package.xml"""
71 pkg_obj = pkg_map[pkg]
72 pkg_xml_path = pkg_obj.filename
73 depends = [x.name
for x
in package.parse_package(pkg_xml_path).exec_depends]
74 depends = list(set(depends))
83 for d
in depends_impl:
86 p_path = os.path.dirname(pkg_obj.filename)
87 if (os.path.exists(os.path.join(p_path,
"msg"))
or
88 os.path.exists(os.path.join(p_path,
"srv"))):
90 except Exception
as e:
91 print(terminal_color.fmt(
92 '@{yellow}[WARNING] path to %s is not found') % (pkg))
94 return [p.name
for n,p
in topological_order.topological_order_packages(depends)]
102 if not pkg
in pkg_map:
103 print(terminal_color.fmt(
104 '@{yellow}[WARNING] %s is not found in workspace') % (pkg))
106 ros_depends = [x
for x
in get_depends(pkg)
if x
in pkg_map]
107 tmp_depends = [x
for x
in ros_depends
if x
not in depends]
108 depends.extend(tmp_depends)
109 for p
in tmp_depends:
114 parser = OptionParser(
"%s file"%(progname))
115 parser.add_option(
'-p', dest=
'package')
116 parser.add_option(
'-o', dest=
'outdir')
117 parser.add_option(
'-I', dest=
'includepath', action=
'append')
118 parser.add_option(
'-m', dest=
'manifest', action=
'store_true')
119 options, args = parser.parse_args(argv)
122 parser.error(
"please specify args")
123 if not os.path.exists(options.outdir):
128 os.makedirs(options.outdir)
130 if not os.path.exists(options.outdir):
138 f = open(options.outdir+
'/manifest.l',
'w+')
140 f.write(
";; DO NOT EDIT THIS FILE\n")
142 pkg_filename =
'unknown'
143 pkg_version =
'unknown'
144 if 'geneus' in pkg_map:
145 pkg_filename = pkg_map[
'geneus'].filename
146 pkg_version = pkg_map[
'geneus'].version
150 f.write(
";; THIS FILE IS AUTOMATICALLY GENERATED\n")
153 f.write(
";; FROM %s (%s)\n"%(pkg_map[pkg].filename, pkg_map[pkg].version))
154 f.write(
";; USING %s %s (%s)\n"%(__file__,pkg_filename,pkg_version))
159 for p
in pkg_dependences:
160 f.write(
"(ros::load-ros-package \"%s\")\n"%p)
161 f.write(
"(ros::load-ros-package \"%s\")\n"%pkg)
165 search_path = genmsg.command_line.includepath_to_dict(options.includepath)
167 if filename.endswith(
'.msg'):
168 retcode =
generate_msg(options.package, args[1:], options.outdir, search_path)
170 retcode =
generate_srv(options.package, args[1:], options.outdir, search_path)
171 except genmsg.InvalidMsgSpec
as e:
172 print(
"ERROR: ", e, file=sys.stderr)
174 except MsgGenerationException
as e:
175 print(
"ERROR: ", e, file=sys.stderr)
177 except Exception
as e:
178 traceback.print_exc()
181 sys.exit(retcode
or 0)