1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-01-26 07:11:25 +00:00

Generate message type constant into message modules

This commit is contained in:
slush0 2016-05-05 21:30:24 +02:00 committed by Pavol Rusnak
parent 561b82a5be
commit bc95e83aea
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D

View File

@ -99,13 +99,27 @@ def process_enum(t, cls):
return out
def find_msg_type(msg_types, t):
for k, v in msg_types:
msg_name = k.replace('MessageType_', '')
if msg_name == t:
return v
def process_module(mod, genpath):
print("Processing module %s" % mod.__name__)
types = dict([(name, cls) for name, cls in mod.__dict__.items() if isinstance(cls, type)])
msg_types = __import__('pb2', globals(), locals(), ['messages_pb2', ]).messages_pb2.MessageType.items()
for t, cls in types.iteritems():
out = process_type(t, cls)
# Find message type for given class
msg_id = find_msg_type(msg_types, t)
if msg_id is not None:
out.append('TYPE = const(%d)' % msg_id)
write_to_file(genpath, t, out)
enums = dict([(name, cls) for name, cls in mod.__dict__.items() if isinstance(cls, EnumTypeWrapper)])