Changeset View
Changeset View
Standalone View
Standalone View
swh/graph/dump_map.py
- This file was added.
# Copyright (C) 2019 The Software Heritage developers | |||||
# See the AUTHORS file at the top-level directory of this distribution | |||||
# License: GNU General Public License version 3, or any later version | |||||
# See top-level LICENSE file for more information | |||||
import click | |||||
from swh.graph.pid import PidToIntMap, IntToPidMap | |||||
def dump_pid2int(filename): | |||||
for (pid, int) in PidToIntMap(filename): | |||||
print('{}\t{}'.format(pid, int)) | |||||
def dump_int2pid(filename): | |||||
for (int, pid) in enumerate(IntToPidMap(filename)): | |||||
print('{}\t{}'.format(int, pid)) | |||||
@click.command() | |||||
@click.option('--type', '-t', 'map_type', required=True, | |||||
type=click.Choice(['pid2int', 'int2pid']), | |||||
help='type of map to dump') | |||||
@click.argument('filename', required=True, type=click.Path(exists=True)) | |||||
vlorentz: these should be two different commands instead. | |||||
Done Inline ActionsI'm not sure I agree. We're going to have a bunch of maps (we already have a 3rd one, although it's not supported here yet). One command per map type would not be convenient. Also, while currently the type has to be specified, it's possible in the future it will be auto-detected, which would make a single dump command more convenient. zack: I'm not sure I agree. We're going to have a bunch of maps (we already have a 3rd one, although… | |||||
def dump(map_type, filename): | |||||
if map_type == 'pid2int': | |||||
dump_pid2int(filename) | |||||
elif map_type == 'int2pid': | |||||
dump_int2pid(filename) | |||||
else: | |||||
raise ValueError('invalid map type: ' + map_type) | |||||
if __name__ == '__main__': | |||||
dump() |
these should be two different commands instead.