Changeset View
Changeset View
Standalone View
Standalone View
contrib/devtools/check-rpc-mappings.py
Show First 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | with open(fname, "r") as f: | ||||
name = parse_string(m.group(2)) | name = parse_string(m.group(2)) | ||||
args_str = m.group(4).strip() | args_str = m.group(4).strip() | ||||
if args_str: | if args_str: | ||||
args = [RPCArgument(parse_string(x.strip()).split( | args = [RPCArgument(parse_string(x.strip()).split( | ||||
'|'), idx) for idx, x in enumerate(args_str.split(','))] | '|'), idx) for idx, x in enumerate(args_str.split(','))] | ||||
else: | else: | ||||
args = [] | args = [] | ||||
cmds.append(RPCCommand(name, args)) | cmds.append(RPCCommand(name, args)) | ||||
assert not in_rpcs, "Something went wrong with parsing the C++ file: update the regexps" | assert not in_rpcs and cmds, "Something went wrong with parsing the C++ file: update the regexps" | ||||
return cmds | return cmds | ||||
def process_mapping(fname): | def process_mapping(fname): | ||||
"""Find and parse conversion table in implementation file `fname`.""" | """Find and parse conversion table in implementation file `fname`.""" | ||||
cmds = [] | cmds = [] | ||||
in_rpcs = False | in_rpcs = False | ||||
with open(fname, "r") as f: | with open(fname, "r") as f: | ||||
for line in f: | for line in f: | ||||
line = line.rstrip() | line = line.rstrip() | ||||
if not in_rpcs: | if not in_rpcs: | ||||
if line == 'static const CRPCConvertParam vRPCConvertParams[] = {': | if line == 'static const CRPCConvertParam vRPCConvertParams[] = {': | ||||
in_rpcs = True | in_rpcs = True | ||||
else: | else: | ||||
if line.startswith('};'): | if line.startswith('};'): | ||||
in_rpcs = False | in_rpcs = False | ||||
elif '{' in line and '"' in line: | elif '{' in line and '"' in line: | ||||
m = re.search( | m = re.search( | ||||
'{ *("[^"]*"), *([0-9]+) *, *("[^"]*") *},', line) | '{ *("[^"]*"), *([0-9]+) *, *("[^"]*") *},', line) | ||||
assert m, 'No match to table expression: {}'.format(line) | assert m, 'No match to table expression: {}'.format(line) | ||||
name = parse_string(m.group(1)) | name = parse_string(m.group(1)) | ||||
idx = int(m.group(2)) | idx = int(m.group(2)) | ||||
argname = parse_string(m.group(3)) | argname = parse_string(m.group(3)) | ||||
cmds.append((name, idx, argname)) | cmds.append((name, idx, argname)) | ||||
assert not in_rpcs | assert not in_rpcs and cmds | ||||
return cmds | return cmds | ||||
def main(): | def main(): | ||||
root = sys.argv[1] | root = sys.argv[1] | ||||
# Get all commands from dispatch tables | # Get all commands from dispatch tables | ||||
cmds = [] | cmds = [] | ||||
▲ Show 20 Lines • Show All 65 Lines • Show Last 20 Lines |