|
| 1 | +# Software License Agreement (BSD License) |
| 2 | +# |
| 3 | +# Copyright (c) 2014, Daniel Stonier. |
| 4 | +# All rights reserved. |
| 5 | +# |
| 6 | +# Redistribution and use in source and binary forms, with or without |
| 7 | +# modification, are permitted provided that the following conditions |
| 8 | +# are met: |
| 9 | +# |
| 10 | +# * Redistributions of source code must retain the above copyright |
| 11 | +# notice, this list of conditions and the following disclaimer. |
| 12 | +# * Redistributions in binary form must reproduce the above |
| 13 | +# copyright notice, this list of conditions and the following |
| 14 | +# disclaimer in the documentation and/or other materials provided |
| 15 | +# with the distribution. |
| 16 | +# * Neither the name of Willow Garage, Inc. nor the names of its |
| 17 | +# contributors may be used to endorse or promote products derived |
| 18 | +# from this software without specific prior written permission. |
| 19 | +# |
| 20 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 | +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 23 | +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 24 | +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 25 | +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 26 | +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 27 | +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 28 | +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 29 | +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
| 30 | +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 31 | +# POSSIBILITY OF SUCH DAMAGE. |
| 32 | + |
| 33 | +############################################################################## |
| 34 | +# Imports |
| 35 | +############################################################################## |
| 36 | + |
| 37 | +from __future__ import print_function |
| 38 | +import argparse |
| 39 | +import os |
| 40 | +#import sys |
| 41 | +#import traceback |
| 42 | +#import genmsg |
| 43 | +import genmsg.command_line |
| 44 | + |
| 45 | +#from genmsg import MsgGenerationException |
| 46 | +#from . generate_initpy import write_modules |
| 47 | + |
| 48 | +############################################################################## |
| 49 | +# Methods |
| 50 | +############################################################################## |
| 51 | + |
| 52 | + |
| 53 | +def parse_arguments(): |
| 54 | + ''' |
| 55 | + The include path has a special format, e.g. |
| 56 | + -Ifoo_msgs:/mnt/zaphod/ros/rosjava/hydro/src/foo_msgs/msg;-Istd_msgs:/opt/ros/hydro/share/std_msgs/cmake/../msg |
| 57 | + ''' |
| 58 | + parser = argparse.ArgumentParser(description='Generate java code for a single ros message.') |
| 59 | + parser.add_argument('-m', '--message', action='store', help='the message file') |
| 60 | + parser.add_argument('-p', '--package', action='store', help='package to find the message file') |
| 61 | + parser.add_argument('-o', '--output-dir', action='store', help='output directory for the java code (e.g. build/foo_msgs)') |
| 62 | + parser.add_argument('-I', '--include-path', action='append', help="include paths to the package and deps msg files") |
| 63 | + #myargs = rospy.myargv(argv=sys.argv) |
| 64 | + #return parser.parse_args(args=myargs[1:]) |
| 65 | + return parser.parse_args() |
| 66 | + |
| 67 | +############################################################################## |
| 68 | +# Main |
| 69 | +############################################################################## |
| 70 | + |
| 71 | +def genmain(argv, progname): # , gen): |
| 72 | + args = parse_arguments() |
| 73 | + print("genjava %s/%s" % (args.package, args.message)) |
| 74 | + print(" output dir..........%s" % args.output_dir) |
| 75 | + search_path = genmsg.command_line.includepath_to_dict(args.include_path) |
| 76 | + print(" search path.......%s" % search_path) |
| 77 | + gradle_project_dir = os.path.join(args.output_dir, 'gradle') |
| 78 | + os.mkdir(gradle_project_dir) |
| 79 | + |
| 80 | +# try: |
| 81 | +# if options.initpy: |
| 82 | +# if options.outdir: |
| 83 | +# retcode = write_modules(options.outdir) |
| 84 | +# else: |
| 85 | +# parser.error("Missing args") |
| 86 | +# else: |
| 87 | +# if len(args) < 2: |
| 88 | +# parser.error("please specify args") |
| 89 | +# if not os.path.exists(options.outdir): |
| 90 | +# # This script can be run multiple times in parallel. We |
| 91 | +# # don't mind if the makedirs call fails because somebody |
| 92 | +# # else snuck in and created the directory before us. |
| 93 | +# try: |
| 94 | +# os.makedirs(options.outdir) |
| 95 | +# except OSError as e: |
| 96 | +# if not os.path.exists(options.outdir): |
| 97 | +# raise |
| 98 | +# search_path = genmsg.command_line.includepath_to_dict(options.includepath) |
| 99 | +# retcode = gen.generate_messages(options.package, args[1:], options.outdir, search_path) |
| 100 | +# except genmsg.InvalidMsgSpec as e: |
| 101 | +# print("ERROR: ", e, file=sys.stderr) |
| 102 | +# retcode = 1 |
| 103 | +# except MsgGenerationException as e: |
| 104 | +# print("ERROR: ", e, file=sys.stderr) |
| 105 | +# retcode = 2 |
| 106 | +# except Exception as e: |
| 107 | +# traceback.print_exc() |
| 108 | +# print("ERROR: ",e) |
| 109 | +# retcode = 3 |
| 110 | +# sys.exit(retcode or 0) |
0 commit comments