Changeset View
Changeset View
Standalone View
Standalone View
swh/graph/cli.py
Show First 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | |||||
def dump_pid2int(filename): | def dump_pid2int(filename): | ||||
for (pid, int) in PidToIntMap(filename): | for (pid, int) in PidToIntMap(filename): | ||||
print('{}\t{}'.format(pid, int)) | print('{}\t{}'.format(pid, int)) | ||||
def dump_int2pid(filename): | def dump_int2pid(filename): | ||||
for (int, pid) in enumerate(IntToPidMap(filename)): | for (int, pid) in IntToPidMap(filename): | ||||
print('{}\t{}'.format(int, pid)) | print('{}\t{}'.format(int, pid)) | ||||
def restore_pid2int(filename): | def restore_pid2int(filename): | ||||
"""read a textual PID->int map from stdin and write its binary version to | """read a textual PID->int map from stdin and write its binary version to | ||||
filename | filename | ||||
""" | """ | ||||
Show All 28 Lines | def dump_map(ctx, map_type, filename): | ||||
elif map_type == 'int2pid': | elif map_type == 'int2pid': | ||||
dump_int2pid(filename) | dump_int2pid(filename) | ||||
else: | else: | ||||
raise ValueError('invalid map type: ' + map_type) | raise ValueError('invalid map type: ' + map_type) | ||||
pass | pass | ||||
@map.command('restore') | @map.command('restore') | ||||
@click.option('--type', '-t', 'map_type', required=True, | @click.option('--type', '-t', 'map_type', required=True, | ||||
type=click.Choice(['pid2int', 'int2pid']), | type=click.Choice(['pid2int', 'int2pid']), | ||||
help='type of map to dump') | help='type of map to dump') | ||||
douardda: This is not part of the diff, but I tend to find weird to use //required// **options** in a cli… | |||||
Done Inline ActionsThat's a fair point. But when you start having multiple positional argument, it's a pain to remember which one goes where if there isn't an obvious order (e.g., cp's src/dst). So I'd rather keep it like this for now. zack: That's a fair point. But when you start having multiple positional argument, it's a pain to… | |||||
@click.argument('filename', required=True, type=click.Path()) | @click.argument('filename', required=True, type=click.Path()) | ||||
@click.pass_context | @click.pass_context | ||||
def restore_map(ctx, map_type, filename): | def restore_map(ctx, map_type, filename): | ||||
"""restore a binary PID<->int map from textual format""" | """restore a binary PID<->int map from textual format""" | ||||
if map_type == 'pid2int': | if map_type == 'pid2int': | ||||
restore_pid2int(filename) | restore_pid2int(filename) | ||||
elif map_type == 'int2pid': | elif map_type == 'int2pid': | ||||
restore_int2pid(filename) | restore_int2pid(filename) | ||||
Show All 10 Lines |
This is not part of the diff, but I tend to find weird to use required options in a cli tool...
This should be an argument IMHO. Or at least let the option have a default value.