genlisp_main.py
Go to the documentation of this file.
1 # Software License Agreement (BSD License)
2 #
3 # Copyright (c) 2009, Willow Garage, Inc.
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 from __future__ import print_function
35 
36 from optparse import OptionParser
37 
38 import os
39 import sys
40 import traceback
41 import genmsg
42 import genmsg.command_line
43 
44 from genmsg import MsgGenerationException
45 from . generate import generate_msg, generate_srv
46 
47 def usage(progname):
48  print("%(progname)s file(s)"%vars())
49 
50 def genmain(argv, progname):
51  parser = OptionParser("%s file"%(progname))
52  parser.add_option('-p', dest='package')
53  parser.add_option('-o', dest='outdir')
54  parser.add_option('-I', dest='includepath', action='append')
55  options, args = parser.parse_args(argv)
56  try:
57  if len(args) < 2:
58  parser.error("please specify args")
59  if not os.path.exists(options.outdir):
60  # This script can be run multiple times in parallel. We
61  # don't mind if the makedirs call fails because somebody
62  # else snuck in and created the directory before us.
63  try:
64  os.makedirs(options.outdir)
65  except OSError as e:
66  if not os.path.exists(options.outdir):
67  raise
68  search_path = genmsg.command_line.includepath_to_dict(options.includepath)
69  filename = args[1]
70  if filename.endswith('.msg'):
71  retcode = generate_msg(options.package, args[1:], options.outdir, search_path)
72  else:
73  retcode = generate_srv(options.package, args[1:], options.outdir, search_path)
74  except genmsg.InvalidMsgSpec as e:
75  print("ERROR: ", e, file=sys.stderr)
76  retcode = 1
77  except MsgGenerationException as e:
78  print("ERROR: ", e, file=sys.stderr)
79  retcode = 2
80  except Exception as e:
81  traceback.print_exc()
82  print("ERROR: ",e)
83  retcode = 3
84  sys.exit(retcode or 0)
def generate_msg(pkg, files, out_dir, search_path)
Definition: generate.py:720
def generate_srv(pkg, files, out_dir, search_path)
Definition: generate.py:732
def usage(progname)
Definition: genlisp_main.py:47
def genmain(argv, progname)
Definition: genlisp_main.py:50


genlisp
Author(s): Bhaskara Marti
autogenerated on Mon Feb 28 2022 22:21:34