ResInsight/ApplicationCode/GrpcInterface/Python/rips/Case.py
Gaute Lindkvist a468532d7f
#4457 Python: clean up grpc api, Python client API and make installable python package (#4456)
* 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
2019-06-03 14:33:16 +02:00

56 lines
1.8 KiB
Python

import grpc
import os
import sys
from .Grid import Grid
from .Properties import Properties
sys.path.insert(1, os.path.join(sys.path[0], '../generated'))
import Case_pb2
import Case_pb2_grpc
class Case:
def __init__(self, channel, id):
self.channel = channel
self.stub = Case_pb2_grpc.CaseStub(channel)
self.id = id
info = self.stub.GetCaseInfo(Case_pb2.CaseRequest(id=self.id))
self.name = info.name
self.groupId = info.group_id
self.type = info.type
self.properties = Properties(self)
self.request = Case_pb2.CaseRequest(id=self.id)
def gridCount(self):
try:
return self.stub.GetGridCount(self.request).count
except grpc.RpcError as e:
if e.code() == grpc.StatusCode.NOT_FOUND:
return 0
print("ERROR: ", e)
return 0
def grid(self, index):
return Grid(index, self)
def grids(self):
gridList = []
for i in range(0, self.gridCount()):
gridList.append(Grid(i, self))
return gridList
def cellCount(self, porosityModel='MATRIX_MODEL'):
porosityModelEnum = Case_pb2.PorosityModelType.Value(porosityModel)
request = Case_pb2.CellInfoRequest(request_case=self.request,
porosity_model=porosityModel)
return self.stub.GetCellCount(request)
def cellInfoForActiveCells(self, porosityModel='MATRIX_MODEL'):
porosityModelEnum = Case_pb2.PorosityModelType.Value(porosityModel)
request = Case_pb2.CellInfoRequest(request_case=self.request,
porosity_model=porosityModel)
return self.stub.GetCellInfoForActiveCells(request)
def timeSteps(self):
return self.stub.GetTimeSteps(self.request)