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 = map(
lambda x: x.name,
74 package.parse_package(pkg_xml_path).exec_depends)
75 depends = list(set(depends))
84 for d
in depends_impl:
87 p_path = os.path.dirname(pkg_obj.filename)
88 if (os.path.exists(os.path.join(p_path,
"msg"))
or 89 os.path.exists(os.path.join(p_path,
"srv"))):
91 except Exception
as e:
92 print(terminal_color.fmt(
93 '@{yellow}[WARNING] path to %s is not found') % (pkg))
95 return [p.name
for n,p
in topological_order.topological_order_packages(depends)]
103 if not pkg
in pkg_map:
104 print(terminal_color.fmt(
105 '@{yellow}[WARNING] %s is not found in workspace') % (pkg))
107 ros_depends = filter(
lambda x: x
in pkg_map,
get_depends(pkg))
108 tmp_depends = filter(
lambda x: x
not in depends, ros_depends)
109 depends.extend(tmp_depends)
110 for p
in tmp_depends:
115 parser = OptionParser(
"%s file"%(progname))
116 parser.add_option(
'-p', dest=
'package')
117 parser.add_option(
'-o', dest=
'outdir')
118 parser.add_option(
'-I', dest=
'includepath', action=
'append')
119 parser.add_option(
'-m', dest=
'manifest', action=
'store_true')
120 options, args = parser.parse_args(argv)
123 parser.error(
"please specify args")
124 if not os.path.exists(options.outdir):
129 os.makedirs(options.outdir)
131 if not os.path.exists(options.outdir):
139 f = open(options.outdir+
'/manifest.l',
'w+')
141 f.write(
";; DO NOT EDIT THIS FILE\n")
143 pkg_filename =
'unknown' 144 pkg_version =
'unknown' 145 if 'geneus' in pkg_map:
146 pkg_filename = pkg_map[
'geneus'].filename
147 pkg_version = pkg_map[
'geneus'].version
151 f.write(
";; THIS FILE IS AUTOMATICALLY GENERATED\n")
154 f.write(
";; FROM %s (%s)\n"%(pkg_map[pkg].filename, pkg_map[pkg].version))
155 f.write(
";; USING %s %s (%s)\n"%(__file__,pkg_filename,pkg_version))
160 for p
in pkg_dependences:
161 f.write(
"(ros::load-ros-package \"%s\")\n"%p)
162 f.write(
"(ros::load-ros-package \"%s\")\n"%pkg)
166 search_path = genmsg.command_line.includepath_to_dict(options.includepath)
168 if filename.endswith(
'.msg'):
169 retcode =
generate_msg(options.package, args[1:], options.outdir, search_path)
171 retcode =
generate_srv(options.package, args[1:], options.outdir, search_path)
172 except genmsg.InvalidMsgSpec
as e:
173 print(
"ERROR: ", e, file=sys.stderr)
175 except MsgGenerationException
as e:
176 print(
"ERROR: ", e, file=sys.stderr)
178 except Exception
as e:
179 traceback.print_exc()
182 sys.exit(retcode
or 0)
def generate_msg(pkg, files, out_dir, search_path)
def genmain(argv, progname)
def generate_srv(pkg, files, out_dir, search_path)
def package_depends_impl(pkg, depends=None)