Changeset View
Changeset View
Standalone View
Standalone View
swh/graph/backend.py
Show All 10 Lines | |||||
import subprocess | import subprocess | ||||
import sys | import sys | ||||
import tempfile | import tempfile | ||||
from py4j.java_gateway import JavaGateway | from py4j.java_gateway import JavaGateway | ||||
from swh.graph.config import check_config | from swh.graph.config import check_config | ||||
from swh.graph.swhid import NodeToSwhidMap, SwhidToNodeMap | from swh.graph.swhid import NodeToSwhidMap, SwhidToNodeMap | ||||
from swh.model.identifiers import SWHID_TYPES | from swh.model.identifiers import EXTENDED_SWHID_TYPES | ||||
BUF_SIZE = 64 * 1024 | BUF_SIZE = 64 * 1024 | ||||
BIN_FMT = ">q" # 64 bit integer, big endian | BIN_FMT = ">q" # 64 bit integer, big endian | ||||
PATH_SEPARATOR_ID = -1 | PATH_SEPARATOR_ID = -1 | ||||
NODE2SWHID_EXT = "node2swhid.bin" | NODE2SWHID_EXT = "node2swhid.bin" | ||||
SWHID2NODE_EXT = "swhid2node.bin" | SWHID2NODE_EXT = "swhid2node.bin" | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | class Backend: | ||||
async def simple_traversal(self, ttype, direction, edges_fmt, src): | async def simple_traversal(self, ttype, direction, edges_fmt, src): | ||||
assert ttype in ("leaves", "neighbors", "visit_nodes") | assert ttype in ("leaves", "neighbors", "visit_nodes") | ||||
method = getattr(self.stream_proxy, ttype) | method = getattr(self.stream_proxy, ttype) | ||||
async for node_id in method(direction, edges_fmt, src): | async for node_id in method(direction, edges_fmt, src): | ||||
yield node_id | yield node_id | ||||
async def walk(self, direction, edges_fmt, algo, src, dst): | async def walk(self, direction, edges_fmt, algo, src, dst): | ||||
if dst in SWHID_TYPES: | if dst in EXTENDED_SWHID_TYPES: | ||||
it = self.stream_proxy.walk_type(direction, edges_fmt, algo, src, dst) | it = self.stream_proxy.walk_type(direction, edges_fmt, algo, src, dst) | ||||
else: | else: | ||||
it = self.stream_proxy.walk(direction, edges_fmt, algo, src, dst) | it = self.stream_proxy.walk(direction, edges_fmt, algo, src, dst) | ||||
async for node_id in it: | async for node_id in it: | ||||
yield node_id | yield node_id | ||||
async def random_walk(self, direction, edges_fmt, retries, src, dst): | async def random_walk(self, direction, edges_fmt, retries, src, dst): | ||||
if dst in SWHID_TYPES: | if dst in EXTENDED_SWHID_TYPES: | ||||
it = self.stream_proxy.random_walk_type( | it = self.stream_proxy.random_walk_type( | ||||
direction, edges_fmt, retries, src, dst | direction, edges_fmt, retries, src, dst | ||||
) | ) | ||||
else: | else: | ||||
it = self.stream_proxy.random_walk(direction, edges_fmt, retries, src, dst) | it = self.stream_proxy.random_walk(direction, edges_fmt, retries, src, dst) | ||||
async for node_id in it: # TODO return 404 if path is empty | async for node_id in it: # TODO return 404 if path is empty | ||||
yield node_id | yield node_id | ||||
▲ Show 20 Lines • Show All 100 Lines • Show Last 20 Lines |