gennodejs_main.py
Go to the documentation of this file.
1 #
2 # Copyright 2016 Rethink Robotics
3 #
4 # Copyright 2016 Chris Smith
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 
17 from __future__ import print_function
18 
19 from optparse import OptionParser
20 
21 import os
22 import sys
23 import traceback
24 import genmsg
25 import genmsg.command_line
26 
27 from genmsg import MsgGenerationException
28 from . generate import generate_msg, generate_srv
29 
30 def usage(progname):
31  print("%(progname)s file(s)"%vars())
32 
33 def genmain(argv, progname):
34  parser = OptionParser("%s file"%(progname))
35  parser.add_option('-p', dest='package')
36  parser.add_option('-o', dest='outdir')
37  parser.add_option('-I', dest='includepath', action='append')
38  options, args = parser.parse_args(argv)
39  try:
40  if len(args) < 2:
41  parser.error("please specify args")
42  if not os.path.exists(options.outdir):
43  # This script can be run multiple times in parallel. We
44  # don't mind if the makedirs call fails because somebody
45  # else snuck in and created the directory before us.
46  try:
47  os.makedirs(options.outdir)
48  except OSError as e:
49  if not os.path.exists(options.outdir):
50  raise
51  search_path = genmsg.command_line.includepath_to_dict(options.includepath)
52  filename = args[1]
53  if filename.endswith('.msg'):
54  retcode = generate_msg(options.package, args[1:], options.outdir, search_path)
55  else:
56  retcode = generate_srv(options.package, args[1:], options.outdir, search_path)
57  except genmsg.InvalidMsgSpec as e:
58  print("ERROR: ", e, file=sys.stderr)
59  retcode = 1
60  except MsgGenerationException as e:
61  print("ERROR: ", e, file=sys.stderr)
62  retcode = 2
63  except Exception as e:
64  traceback.print_exc()
65  print("ERROR: ",e)
66  retcode = 3
67  sys.exit(retcode or 0)
def genmain(argv, progname)
def generate_srv(pkg, files, out_dir, search_path)
Definition: generate.py:768
def generate_msg(pkg, files, out_dir, search_path)
Definition: generate.py:756


gennodejs
Author(s):
autogenerated on Thu Jun 6 2019 19:40:34