mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
* gRPC: Make names more consistent * gRPC: clean up case info and improve Python API for cases * gRPC: much more object oriented Python interface * Python: Make a proper pip-installable package * Update rips Python package to auto generate setup.py with version number * Python: add setup.py to gitignore * Python: Update Python RIPS interface * gRPC: Remove example client from cmake file and unit test * gRPC: Fix up unit test after merge and hide warnings * gRPC: fix up python client code
This commit is contained in:
45
ApplicationCode/GrpcInterface/Python/rips/Project.py
Normal file
45
ApplicationCode/GrpcInterface/Python/rips/Project.py
Normal file
@@ -0,0 +1,45 @@
|
||||
import grpc
|
||||
import os
|
||||
import sys
|
||||
|
||||
from .Case import Case
|
||||
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '../generated'))
|
||||
|
||||
from Empty_pb2 import Empty
|
||||
import Project_pb2
|
||||
import Project_pb2_grpc
|
||||
|
||||
class Project:
|
||||
def __init__(self, channel):
|
||||
self.channel = channel
|
||||
self.project = Project_pb2_grpc.ProjectStub(channel)
|
||||
|
||||
def selectedCases(self):
|
||||
caseInfos = self.project.GetSelectedCases(Empty())
|
||||
cases = []
|
||||
for caseInfo in caseInfos.data:
|
||||
cases.append(Case(self.channel, caseInfo.id))
|
||||
return cases
|
||||
|
||||
def cases(self):
|
||||
try:
|
||||
caseInfos = self.project.GetAllCases(Empty())
|
||||
|
||||
cases = []
|
||||
for caseInfo in caseInfos.data:
|
||||
cases.append(Case(self.channel, caseInfo.id))
|
||||
return cases
|
||||
except grpc.RpcError as e:
|
||||
if e.code() == grpc.StatusCode.NOT_FOUND:
|
||||
return []
|
||||
else:
|
||||
print("ERROR: ", e)
|
||||
return []
|
||||
|
||||
def case(self, id):
|
||||
try:
|
||||
case = Case(self.channel, id)
|
||||
return case
|
||||
except grpc.RpcError as e:
|
||||
return None
|
||||
Reference in New Issue
Block a user