rtps: generation scripts: make indexing of lists possible in both Python 2 and 3

This commit is contained in:
TSC21 2019-08-04 18:54:04 +01:00 committed by Nuno Marques
parent e69398c09f
commit 47f5b23419
3 changed files with 75 additions and 29 deletions

View File

@ -62,9 +62,20 @@ def check_rtps_id_uniqueness(classifier):
repeated_ids = dict()
full_send_list = dict(list(msg for msg in classifier.msgs_to_send.items()) + list(msg[0].items()[0] for msg in classifier.alias_msgs_to_send))
full_receive_list = dict(list(msg for msg in classifier.msgs_to_receive.items()) + list(msg[0].items()[0] for msg in classifier.alias_msgs_to_receive))
full_ignore_list = dict(list(msg for msg in classifier.msgs_to_ignore.items()) + list(msg[0].items()[0] for msg in classifier.alias_msgs_to_ignore))
if sys.version_info[0] < 3:
full_send_list = dict(list(msg for msg in classifier.msgs_to_send.items(
)) + list(msg[0].items()[0] for msg in classifier.alias_msgs_to_send))
full_receive_list = dict(list(msg for msg in classifier.msgs_to_receive.items(
)) + list(msg[0].items()[0] for msg in classifier.alias_msgs_to_receive))
full_ignore_list = dict(list(msg for msg in classifier.msgs_to_ignore.items(
)) + list(msg[0].items()[0] for msg in classifier.alias_msgs_to_ignore))
else:
full_send_list = dict(list(msg for msg in classifier.msgs_to_send.items(
)) + list(list(msg[0].items())[0] for msg in classifier.alias_msgs_to_send))
full_receive_list = dict(list(msg for msg in classifier.msgs_to_receive.items(
)) + list(list(msg[0].items())[0] for msg in classifier.alias_msgs_to_receive))
full_ignore_list = dict(list(msg for msg in classifier.msgs_to_ignore.items(
)) + list(list(msg[0].items())[0] for msg in classifier.alias_msgs_to_ignore))
# check if there are repeated ID's on the messages to send
for key, value in full_send_list.items():
@ -298,7 +309,10 @@ def generate_agent(out_dir):
if classifier.alias_msgs_to_send:
for msg_file in classifier.alias_msgs_to_send:
if sys.version_info[0] < 3:
msg_alias = msg_file[0].keys()[0]
else:
msg_alias = list(msg_file[0].keys())[0]
msg_name = msg_file[1]
if gen_idl:
if out_dir != agent_out_dir:
@ -328,7 +342,10 @@ def generate_agent(out_dir):
if classifier.alias_msgs_to_receive:
for msg_file in classifier.alias_msgs_to_receive:
if sys.version_info[0] < 3:
msg_alias = msg_file[0].keys()[0]
else:
msg_alias = list(msg_file[0].keys())[0]
msg_name = msg_file[1]
if gen_idl:
if out_dir != agent_out_dir:

View File

@ -178,7 +178,7 @@ def generate_idl_file(filename_msg, msg_dir, alias, outputdir, templatedir, pack
if (alias != ""):
em_globals = get_em_globals(
msg, alias , package, includepath, ids, MsgScope.NONE)
msg, alias, package, includepath, ids, MsgScope.NONE)
spec_short_name = alias
else:
em_globals = get_em_globals(
@ -201,10 +201,24 @@ def generate_uRTPS_general(filename_send_msgs, filename_alias_send_msgs, filenam
"""
Generates source file by msg content
"""
send_msgs = list(os.path.join(msg_dir, msg + ".msg") for msg in filename_send_msgs)
alias_send_msgs = list([os.path.join(msg_dir, msg[1] + ".msg"), msg[0].keys()[0]] for msg in filename_alias_send_msgs)
receive_msgs = list(os.path.join(msg_dir, msg + ".msg") for msg in filename_receive_msgs)
alias_receive_msgs = list([os.path.join(msg_dir, msg[1] + ".msg"), msg[0].keys()[0]] for msg in filename_alias_receive_msgs)
send_msgs = list(os.path.join(msg_dir, msg + ".msg")
for msg in filename_send_msgs)
receive_msgs = list(os.path.join(msg_dir, msg + ".msg")
for msg in filename_receive_msgs)
if sys.version_info[0] < 3:
alias_send_msgs = list([os.path.join(
msg_dir, msg[1] + ".msg"), msg[0].keys()[0]] for msg in filename_alias_send_msgs)
else:
alias_send_msgs = list([os.path.join(msg_dir, msg[1] + ".msg"),
list(msg[0].keys())[0]] for msg in filename_alias_send_msgs)
if sys.version_info[0] < 3:
alias_receive_msgs = list([os.path.join(
msg_dir, msg[1] + ".msg"), msg[0].keys()[0]] for msg in filename_alias_receive_msgs)
else:
alias_receive_msgs = list([os.path.join(
msg_dir, msg[1] + ".msg"), list(msg[0].keys())[0]] for msg in filename_alias_receive_msgs)
em_globals_list = []
if send_msgs:

View File

@ -124,7 +124,7 @@ class Classifier():
none_listed_msgs = []
for msg in self.all_msgs_list:
result = not any(
dict.values()[0] == msg for dict in self.msg_id_map['rtps'])
dict['msg'] == msg for dict in self.msg_id_map['rtps'])
if result:
none_listed_msgs.append(msg)
@ -136,7 +136,7 @@ class Classifier():
raise AssertionError(
"\n%s %s: " % (error_msg, yaml_file) + ", ".join('%s' % msg for msg in none_listed_msgs) +
"\n\nPlease add them to the yaml file with the respective ID and, if applicable, mark them" +
"\n\nPlease add them to the yaml file with the respective ID and, if applicable, mark them " +
"to be sent or received by the micro-RTPS bridge.\n"
"NOTE: If the message has multi-topics (#TOPICS), these should be added as well.\n")
@ -210,9 +210,14 @@ if __name__ == "__main__":
for msg_file in classifier.msgs_files_send) + '\n')
else:
if args.alias:
if sys.version_info[0] < 3:
print (', '.join(str(msg)
for msg in classifier.msgs_to_send.keys()) + (' alias ' + ', '.join(str(msg[0].keys()[0])
for msg in classifier.alias_msgs_to_send) if len(classifier.alias_msgs_to_send) > 0 else '') + '\n')
else:
print (', '.join(str(msg)
for msg in classifier.msgs_to_send.keys()) + (' alias ' + ', '.join(str(list(msg[0].keys())[0])
for msg in classifier.alias_msgs_to_send) if len(classifier.alias_msgs_to_send) > 0 else '') + '\n')
else:
print (', '.join(str(msg)
for msg in classifier.msgs_to_send.keys()))
@ -222,9 +227,14 @@ if __name__ == "__main__":
for msg_file in classifier.msgs_files_receive) + '\n')
else:
if args.alias:
if sys.version_info[0] < 3:
print (', '.join(str(msg)
for msg in classifier.msgs_to_receive.keys()) + (' alias ' + ', '.join(str(msg[0].keys()[0])
for msg in classifier.alias_msgs_to_receive) if len(classifier.alias_msgs_to_receive) > 0 else '') + '\n')
else:
print (', '.join(str(msg)
for msg in classifier.msgs_to_receive.keys()) + (' alias ' + ', '.join(str(list(msg[0].keys())[0])
for msg in classifier.alias_msgs_to_receive) if len(classifier.alias_msgs_to_receive) > 0 else '') + '\n')
else:
print (', '.join(str(msg)
for msg in classifier.msgs_to_receive.keys()))
@ -234,9 +244,14 @@ if __name__ == "__main__":
for msg_file in classifier.msgs_files_ignore) + '\n')
else:
if args.alias:
if sys.version_info[0] < 3:
print (', '.join(str(msg)
for msg in classifier.msgs_to_ignore.keys()) + (' alias ' + ', '.join(str(msg[0].keys()[0])
for msg in classifier.alias_msgs_to_ignore) if len(classifier.alias_msgs_to_ignore) > 0 else '') + '\n')
else:
print (', '.join(str(msg)
for msg in classifier.msgs_to_ignore.keys()) + (' alias ' + ', '.join(str(list(msg[0].keys())[0])
for msg in classifier.alias_msgs_to_ignore) if len(classifier.alias_msgs_to_ignore) > 0 else '') + '\n')
else:
print (', '.join(str(msg)
for msg in classifier.msgs_to_ignore.keys()))