#4462 Python Fix examples to run well with either install module or without

This commit is contained in:
Gaute Lindkvist
2019-06-03 21:11:27 +02:00
parent 17821ade6c
commit fe2d352f84
14 changed files with 102 additions and 49 deletions

View File

@@ -41,13 +41,13 @@ class Case:
def cellCount(self, porosityModel='MATRIX_MODEL'):
porosityModelEnum = Case_pb2.PorosityModelType.Value(porosityModel)
request = Case_pb2.CellInfoRequest(request_case=self.request,
request = Case_pb2.CellInfoRequest(case_request=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,
request = Case_pb2.CellInfoRequest(case_request=self.request,
porosity_model=porosityModel)
return self.stub.GetCellInfoForActiveCells(request)

View File

@@ -7,37 +7,81 @@ import Commands_pb2_grpc as CmdRpc
class Commands:
def __init__(self, channel):
self.channel = channel
self.commands = CmdRpc.CommandsStub(channel)
def execute(self, commandParams):
def execute(self, **commandParams):
try:
return self.commands.Execute(commandParams)
return self.commands.Execute(Cmd.CommandParams(**commandParams))
except grpc.RpcError as e:
if e.code() == grpc.StatusCode.NOT_FOUND:
print("Command not found")
print("Command not found", commandParams.keys())
else:
print("Other error")
print("Other error", e)
def setTimeStep(self, caseId, timeStep):
return self.execute(Cmd.CommandParams(setTimeStep=Cmd.SetTimeStepParams(caseId=caseId, timeStep=timeStep)))
def setMainWindowSize(self, width, height):
return self.execute(Cmd.CommandParams(setMainWindowSize=Cmd.SetMainWindowSizeParams(width=width, height=height)))
########################
# Case Control Commands
########################
def openProject(self, path):
return self.execute(Cmd.CommandParams(openProject=Cmd.FilePathRequest(path=path)))
return self.execute(openProject=Cmd.FilePathRequest(path=path))
def closeProject(self):
return self.execute(closeProject=Empty())
def setStartDir(self, path):
return self.execute(setStartDir=Cmd.FilePathRequest(path=path))
def loadCase(self, path):
commandReply = self.execute(Cmd.CommandParams(loadCase=Cmd.FilePathRequest(path=path)))
commandReply = self.execute(loadCase=Cmd.FilePathRequest(path=path))
assert commandReply.HasField("loadCaseResult")
return commandReply.loadCaseResult.id
def closeProject(self):
return self.execute(Cmd.CommandParams(closeProject=Empty()))
def replaceCase(self, path, caseId=0):
return self.execute(replaceCase=Cmd.ReplaceCaseRequest(newGridFile=path,
caseId=caseId))
def replaceSourceCases(self, gridListFile, caseGroupId=0):
return self.execute(replaceSourceCases=Cmd.ReplaceSourceCasesRequest(gridListFile=gridListFile,
caseGroupId=caseGroupId))
##################
# Export Commands
##################
def exportSnapshots(self, type = 'ALL', prefix=''):
return self.execute(exportSnapshots=Cmd.ExportSnapshotsRequest(type=type,
prefix=prefix))
def exportWellPaths(self, wellPaths=[], mdStepSize=5.0):
if isinstance(wellPaths, str):
wellPathArray = [str]
elif isinstance(wellPaths, list):
wellPathArray = wellPaths
return self.execute(Cmd.CommandParams(exportWellPaths=Cmd.ExportWellPathRequest(wellPathNames=wellPathArray, mdStepSize=mdStepSize)))
return self.execute(exportWellPaths=Cmd.ExportWellPathRequest(wellPathNames=wellPathArray, mdStepSize=mdStepSize))
def exportVisibleCells(self, caseId, viewName, exportKeyword='FLUXNUM', visibleActiveCellsValue=1, hiddenActiveCellsValue=0, inactiveCellsValue=0):
return self.execute(exportVisibleCells=Cmd.ExportVisibleCellsRequest(caseId=caseId,
viewName=viewName,
exportKeyword=exportKeyword,
visibleActiveCellsValue=visibleActiveCellsValue,
hiddenActiveCellsValue=hiddenActiveCellsValue,
inactiveCellsValue=inactiveCellsValue))
def setExportFolder(self, type, path, createFolder=False):
return self.execute(setExportFolder=Cmd.SetExportFolderRequest(type=type,
path=path,
createFolder=createFolder))
def runOctaveScript(self, path, cases):
caseIds = []
for case in cases:
caseIds.append(case.id)
return self.execute(runOctaveScript=Cmd.RunOctaveScriptRequest(path=path,
caseIds=caseIds))
def setMainWindowSize(self, width, height):
return self.execute(setMainWindowSize=Cmd.SetMainWindowSizeParams(width=width, height=height))
def setTimeStep(self, caseId, timeStep):
return self.execute(setTimeStep=Cmd.SetTimeStepParams(caseId=caseId, timeStep=timeStep))

View File

@@ -3,6 +3,7 @@ import os
import sys
from .Case import Case
from .Commands import Commands
sys.path.insert(1, os.path.join(sys.path[0], '../generated'))