diff --git a/tools/migrations/int2pid-csv2bin.py b/tools/migrations/int2pid-csv2bin.py new file mode 100755 index 0000000..bcd3d18 --- /dev/null +++ b/tools/migrations/int2pid-csv2bin.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 + +# 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 + +"""Convert a textual int->PID map (as a simple list of textual PIDs), to the +binary format of :class:`swh.graph.pid.IntToPidMap`. + +""" + +import sys + +from swh.graph.pid import IntToPidMap + + +def main(fname): + with open(fname, 'wb') as f: + for line in sys.stdin: + pid = line.rstrip() + IntToPidMap.write_record(f, pid) + + +if __name__ == '__main__': + main(sys.argv[1]) diff --git a/tools/migrations/pid2int-csv2bin.py b/tools/migrations/pid2int-csv2bin.py new file mode 100755 index 0000000..8f6c475 --- /dev/null +++ b/tools/migrations/pid2int-csv2bin.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 + +# 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 + +"""Convert a textual PID->int map (as a list of space-separated +textual pairs), to the binary format of :class:`swh.graph.pid.PidToIntMap`. + +""" + +import sys + +from swh.graph.pid import PidToIntMap + + +def main(fname): + with open(fname, 'wb') as f: + for line in sys.stdin: + (pid, int_str) = line.rstrip().split(maxsplit=1) + PidToIntMap.write_record(f, pid, int(int_str)) + + +if __name__ == '__main__': + main(sys.argv[1])