13 from cStringIO
import StringIO
15 from io
import StringIO
22 AUTOGEN=
"# ====== DO NOT MODIFY! AUTOGENERATED FROM A SERVICE PAIR DEFINITION ======\n\n" 28 for l
in text.split(
'\n'):
29 if l.startswith(IODELIM):
30 pieces.append(StringIO())
32 pieces[-1].write(l +
'\n')
33 return [p.getvalue()
for p
in pieces]
36 f = open(filename,
'w')
42 parser = argparse.ArgumentParser(description=
'Service pair generator.')
43 parser.add_argument(
'filename', nargs=1, type=str, help=
"filename of the .pair service")
44 parser.add_argument(
'-o',
'--output-dir', action=
'store', default=
'.', help=
'output directory')
45 args = parser.parse_args()
49 os.makedirs(args.output_dir)
51 if e.errno == errno.EEXIST:
56 service_pair_file = args.filename[0]
57 if not service_pair_file.endswith(
'.pair'):
58 print(
"The file specified has the wrong extension. It must end in .pair")
60 filename = service_pair_file
63 service_pair_spec = f.read()
66 name = os.path.basename(filename)[:-7]
67 (name, unused_sep, unused_ext) = os.path.basename(filename).partition(
'.')
72 raise ActionSpecException(
"%s: wrong number of pieces, %d"%(filename,len(pieces)))
73 service_request, service_response = pieces
74 service_pair_msg = AUTOGEN + name +
'PairRequest pair_request\n' + name +
'PairResponse pair_response\n' 75 service_request_msg = AUTOGEN + service_request
76 service_pair_request_msg = AUTOGEN +
'uuid_msgs/UniqueID id\n' + name +
'Request request\n' 77 service_response_msg = AUTOGEN + service_response
78 service_pair_response_msg = AUTOGEN +
'uuid_msgs/UniqueID id\n' + name +
'Response response\n' 80 write_file(os.path.join(args.output_dir,
"%sPair.msg"%name), service_pair_msg)
81 write_file(os.path.join(args.output_dir,
"%sRequest.msg"%name), service_request_msg)
82 write_file(os.path.join(args.output_dir,
"%sPairRequest.msg"%name), service_pair_request_msg)
83 write_file(os.path.join(args.output_dir,
"%sResponse.msg"%name), service_response_msg)
84 write_file(os.path.join(args.output_dir,
"%sPairResponse.msg"%name), service_pair_response_msg)
87 if __name__ ==
'__main__':
main()
def write_file(filename, text)
def parse_service_pair_spec(text, package_context='')