Changeset View
Changeset View
Standalone View
Standalone View
swh/graph/backend.py
Show All 29 Lines | def _get_pipe_stderr(): | ||||
try: | try: | ||||
sys.stderr.fileno() | sys.stderr.fileno() | ||||
except io.UnsupportedOperation: | except io.UnsupportedOperation: | ||||
return subprocess.STDOUT | return subprocess.STDOUT | ||||
else: | else: | ||||
return sys.stderr | return sys.stderr | ||||
class Backend: | class Backend: | ||||
ardumont: Not per say related to this diff but still worth the remark and since you are modifying it... | |||||
Done Inline Actionstbh I'm not sure vlorentz: tbh I'm not sure | |||||
def __init__(self, graph_path, config=None): | def __init__(self, graph_path, config=None): | ||||
self.gateway = None | self.gateway = None | ||||
self.entry = None | self.entry = None | ||||
self.graph_path = graph_path | self.graph_path = graph_path | ||||
self.config = check_config(config or {}) | self.config = check_config(config or {}) | ||||
def __enter__(self): | def start_gateway(self): | ||||
self.gateway = JavaGateway.launch_gateway( | self.gateway = JavaGateway.launch_gateway( | ||||
java_path=None, | java_path=None, | ||||
javaopts=self.config["java_tool_options"].split(), | javaopts=self.config["java_tool_options"].split(), | ||||
classpath=self.config["classpath"], | classpath=self.config["classpath"], | ||||
die_on_exit=True, | die_on_exit=True, | ||||
redirect_stdout=sys.stdout, | redirect_stdout=sys.stdout, | ||||
redirect_stderr=_get_pipe_stderr(), | redirect_stderr=_get_pipe_stderr(), | ||||
) | ) | ||||
self.entry = self.gateway.jvm.org.softwareheritage.graph.Entry() | self.entry = self.gateway.jvm.org.softwareheritage.graph.Entry() | ||||
self.entry.load_graph(self.graph_path) | self.entry.load_graph(self.graph_path) | ||||
self.node2swhid = NodeToSwhidMap(self.graph_path + "." + NODE2SWHID_EXT) | self.node2swhid = NodeToSwhidMap(self.graph_path + "." + NODE2SWHID_EXT) | ||||
self.swhid2node = SwhidToNodeMap(self.graph_path + "." + SWHID2NODE_EXT) | self.swhid2node = SwhidToNodeMap(self.graph_path + "." + SWHID2NODE_EXT) | ||||
self.stream_proxy = JavaStreamProxy(self.entry) | self.stream_proxy = JavaStreamProxy(self.entry) | ||||
def stop_gateway(self): | |||||
self.gateway.shutdown() | |||||
def __enter__(self): | |||||
self.start_gateway() | |||||
return self | return self | ||||
def __exit__(self, exc_type, exc_value, tb): | def __exit__(self, exc_type, exc_value, tb): | ||||
self.gateway.shutdown() | self.stop_gateway() | ||||
def stats(self): | def stats(self): | ||||
return self.entry.stats() | return self.entry.stats() | ||||
def count(self, ttype, direction, edges_fmt, src): | def count(self, ttype, direction, edges_fmt, src): | ||||
method = getattr(self.entry, "count_" + ttype) | method = getattr(self.entry, "count_" + ttype) | ||||
return method(direction, edges_fmt, src) | return method(direction, edges_fmt, src) | ||||
▲ Show 20 Lines • Show All 130 Lines • Show Last 20 Lines |
Not per say related to this diff but still worth the remark and since you are modifying it...
Could you please add a docstring on this class to explain rapidly a bit what is its job?
Is it some kind of proxy forwarding requests to the actual java graph service or something?