genlisp_main.py
Go to the documentation of this file.
00001 from __future__ import print_function
00002 
00003 from optparse import OptionParser
00004 
00005 import os
00006 import sys
00007 import traceback
00008 import genmsg
00009 import genmsg.command_line
00010 
00011 from genmsg import MsgGenerationException
00012 from . generate import generate_msg, generate_srv
00013 
00014 def usage(progname):
00015     print("%(progname)s file(s)"%vars())
00016 
00017 def genmain(argv, progname):
00018     parser = OptionParser("%s file"%(progname))
00019     parser.add_option('-p', dest='package')
00020     parser.add_option('-o', dest='outdir')
00021     parser.add_option('-I', dest='includepath', action='append')
00022     options, args = parser.parse_args(argv)
00023     try:
00024         if len(args) < 2:
00025             parser.error("please specify args")
00026         if not os.path.exists(options.outdir):
00027             # This script can be run multiple times in parallel. We
00028             # don't mind if the makedirs call fails because somebody
00029             # else snuck in and created the directory before us.
00030             try:
00031                 os.makedirs(options.outdir)
00032             except OSError as e:
00033                 if not os.path.exists(options.outdir):
00034                     raise
00035         search_path = genmsg.command_line.includepath_to_dict(options.includepath)
00036         filename = args[1]
00037         if filename.endswith('.msg'):
00038             retcode = generate_msg(options.package, args[1:], options.outdir, search_path)
00039         else:
00040             retcode = generate_srv(options.package, args[1:], options.outdir, search_path)
00041     except genmsg.InvalidMsgSpec as e:
00042         print("ERROR: ", e, file=sys.stderr)
00043         retcode = 1
00044     except MsgGenerationException as e:
00045         print("ERROR: ", e, file=sys.stderr)
00046         retcode = 2
00047     except Exception as e:
00048         traceback.print_exc()
00049         print("ERROR: ",e)
00050         retcode = 3
00051     sys.exit(retcode or 0)


genlisp
Author(s): Bhaskara Marti (bhaskara@willowgarage.com)
autogenerated on Sat Dec 28 2013 17:00:57