create_action_executor.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 import roslib
00003 from Cheetah.Template import Template
00004 import sys
00005 import os
00006 import string
00007 
00008 # UpperCamelCase -> [upper, camel, case]
00009 def split_lower_case(name):
00010     index = [i for i in range(len(name)) if name[i] in string.uppercase]
00011     parts = []
00012     for i in range(len(index)):
00013         if i == len(index) - 1: # last
00014             parts.append(name[index[i]:].lower())
00015         else:
00016             parts.append(name[index[i]:index[i+1]].lower())
00017     return parts
00018 
00019 # name in UpperCamelCase -> under_scored
00020 def make_underscore(name):
00021     parts = split_lower_case(name)
00022     return '_'.join(parts)
00023 
00024 # name in UpperCamelCase -> CAPS_NAME
00025 def make_caps(name):
00026     parts = split_lower_case(name)
00027     return '_'.join([x.upper() for x in parts])
00028 
00029 if __name__=="__main__":
00030     if len(sys.argv) < 3:
00031         print "Usage %s action namespace [s]" % sys.argv[0], "(if 's' is given at the end a service action executor is created"
00032         sys.exit(1)
00033     action_pkg, action_name = sys.argv[1].split("/")
00034     namespace = sys.argv[2]
00035     action_underscored = make_underscore(action_name)
00036     action_caps = make_caps(action_name)
00037     #print action_pkg
00038     #print action_name
00039     #print action_underscored
00040     #print action_caps
00041     #print namespace
00042 
00043     tmpl_dir = roslib.packages.get_pkg_subdir("continual_planning_executive", "scripts", False)
00044     if not tmpl_dir:
00045         print "Could not find package://continual_planning_executive/scripts directory"
00046         sys.exit(1)
00047 
00048     header_tmpl_name = "actionExecutor.h.tmpl"
00049     cpp_tmpl_name = "actionExecutor.cpp.tmpl"
00050     if len(sys.argv) >= 4 and sys.argv[3] == "s":
00051         header_tmpl_name = "actionExecutorService.h.tmpl"
00052         cpp_tmpl_name = "actionExecutorService.cpp.tmpl"
00053 
00054     header_template = Template(file=os.path.join(tmpl_dir, header_tmpl_name),
00055             searchList=[{'PACKAGE'  : action_pkg,
00056                          'ACTION'   : action_name,
00057                          'ACTION_CAPS'   : action_caps,
00058                          'ACTION_UNDERSCORED'   : action_underscored,
00059                          'NAMESPACE' : namespace}])
00060     f = file("actionExecutor%s.h" % action_name, 'w')
00061     f.write(str(header_template))
00062     f.close()
00063 
00064     cpp_template = Template(file=os.path.join(tmpl_dir, cpp_tmpl_name),
00065             searchList=[{'PACKAGE'  : action_pkg,
00066                          'ACTION'   : action_name,
00067                          'ACTION_CAPS'   : action_caps,
00068                          'ACTION_UNDERSCORED'   : action_underscored,
00069                          'NAMESPACE' : namespace}])
00070     f = file("actionExecutor%s.cpp" % action_name, 'w')
00071     f.write(str(cpp_template))
00072     f.close()
00073 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines


continual_planning_executive
Author(s): Christian Dornhege
autogenerated on Tue Jan 22 2013 12:24:43