generate_relay_factory.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # Software License Agreement (BSD)
3 #
4 # @author Paul Bovbel <pbovbel@clearpath.ai>
5 # @copyright (c) 2016, Clearpath Robotics, Inc., All rights reserved.
6 #
7 # Redistribution and use in source and binary forms, with or without modification, are permitted provided that
8 # the following conditions are met:
9 # * Redistributions of source code must retain the above copyright notice, this list of conditions and the
10 # following disclaimer.
11 # * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
12 # following disclaimer in the documentation and/or other materials provided with the distribution.
13 # * Neither the name of Clearpath Robotics nor the names of its contributors may be used to endorse or
14 # promote products derived from this software without specific prior written permission.
15 #
16 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
17 # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
18 # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
19 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
20 # TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22 # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
23 # POSSIBILITY OF SUCH DAMAGE.
24 from Cheetah.Template import Template
25 import argparse
26 import pprint
27 
28 if __name__ == "__main__":
29 
30  parser = argparse.ArgumentParser(description='Generate topic relay factory source.')
31  parser.add_argument('--msg-srv-names', metavar='msg_srv_names', nargs='*', help='Message/Service Names')
32  parser.add_argument('--cpp-tmpl', metavar='*.cpp.tmpl', help='Input template', required=True)
33  parser.add_argument('--cpp-out', metavar='*.cpp', help='Output source file', required=True)
34 
35  args = parser.parse_args()
36 
37  template_namespace = {}
38 
39  template_namespace['msg_srv_names'] = args.msg_srv_names
40  template_namespace['pkg_names'] = set(s.rsplit('/', 1)[0] for s in args.msg_srv_names)
41 
42  # For debug, print definitions to console
43  # pp = pprint.PrettyPrinter(indent=1)
44  # pp.pprint(template_namespace)
45 
46  with open(args.cpp_tmpl, 'r') as f:
47  source_template = Template(f.read(), searchList=[template_namespace])
48 
49  # print(template_namespace)
50  with open(args.cpp_out, 'w') as f:
51  f.write(str(source_template))


message_relay
Author(s):
autogenerated on Wed Jul 17 2019 03:27:53