예제 #1
0
파일: cli.py 프로젝트: k13n/swh-graph
def restore_pid2node(filename):
    """read a textual PID->int map from stdin and write its binary version to
    filename

    """
    with open(filename, "wb") as dst:
        for line in sys.stdin:
            (str_pid, str_int) = line.split()
            PidToNodeMap.write_record(dst, str_pid, int(str_int))
예제 #2
0
파일: test_pid.py 프로젝트: k13n/swh-graph
    def setUpClass(cls):
        """create reasonably sized (~2 MB) PID->int map to test on-disk DB

        """
        cls.tmpdir = tempfile.mkdtemp(prefix="swh.graph.test.")
        cls.fname = os.path.join(cls.tmpdir, "pid2int.bin")
        with open(cls.fname, "wb") as f:
            for (pid, i) in gen_records(length=10000):
                PidToNodeMap.write_record(f, pid, i)
예제 #3
0
파일: cli.py 프로젝트: k13n/swh-graph
def write(ctx, map_type, filename):
    """Write a map to disk sequentially.

    read from stdin a textual PID->node mapping (for pid2node, or a simple
    sequence of PIDs for node2pid) and write it to disk in the requested binary
    map format

    note that no sorting is applied, so the input should already be sorted as
    required by the chosen map type (by PID for pid2node, by int for node2pid)

    """
    with open(filename, "wb") as f:
        if map_type == "pid2node":
            for line in sys.stdin:
                (pid, int_str) = line.rstrip().split(maxsplit=1)
                PidToNodeMap.write_record(f, pid, int(int_str))
        elif map_type == "node2pid":
            for line in sys.stdin:
                pid = line.rstrip()
                NodeToPidMap.write_record(f, pid)
        else:
            raise ValueError("invalid map type: " + map_type)