33 from cStringIO
import StringIO
35 from io
import StringIO
39 from optparse
import OptionParser
42 AUTOGEN=
"# ====== DO NOT MODIFY! AUTOGENERATED FROM AN ACTION DEFINITION ======\n" 48 for l
in text.split(
'\n'):
49 if l.startswith(IODELIM):
50 pieces.append(StringIO())
52 pieces[-1].write(l +
'\n')
53 return [p.getvalue()
for p
in pieces]
56 f = open(filename,
'w')
62 parser = OptionParser(
"Actionlib generator")
63 parser.add_option(
'-o', dest=
'output_dir',
64 help=
'output directory')
66 (options, args) = parser.parse_args(sys.argv)
68 pkg = os.path.abspath(sys.argv[1])
69 filename = sys.argv[2]
71 output_dir = options.output_dir
75 os.makedirs(output_dir)
77 if e.errno == errno.EEXIST:
83 if not action_file.endswith(
'.action'):
84 print(
"The file specified has the wrong extension. It must end in .action")
86 filename = action_file
89 action_spec = f.read()
92 name = os.path.basename(filename)[:-7]
93 print(
"Generating for action %s" % name)
98 goal, result, feedback = pieces
100 action_msg = AUTOGEN +
""" 101 %sActionGoal action_goal 102 %sActionResult action_result 103 %sActionFeedback action_feedback 104 """ % (name, name, name)
106 goal_msg = AUTOGEN + goal
107 action_goal_msg = AUTOGEN +
""" 109 actionlib_msgs/GoalID goal_id 113 result_msg = AUTOGEN + result
114 action_result_msg = AUTOGEN +
""" 116 actionlib_msgs/GoalStatus status 120 feedback_msg = AUTOGEN + feedback
121 action_feedback_msg = AUTOGEN +
""" 123 actionlib_msgs/GoalStatus status 127 write_file(os.path.join(output_dir,
"%sAction.msg"%name), action_msg)
128 write_file(os.path.join(output_dir,
"%sGoal.msg"%name), goal_msg)
129 write_file(os.path.join(output_dir,
"%sActionGoal.msg"%name), action_goal_msg)
130 write_file(os.path.join(output_dir,
"%sResult.msg"%name), result_msg)
131 write_file(os.path.join(output_dir,
"%sActionResult.msg"%name), action_result_msg)
132 write_file(os.path.join(output_dir,
"%sFeedback.msg"%name), feedback_msg)
133 write_file(os.path.join(output_dir,
"%sActionFeedback.msg"%name), action_feedback_msg)
136 if __name__ ==
'__main__':
main()
def parse_action_spec(text, package_context='')
def write_file(filename, text)