#4474 Add command for getting runtime info (i.e. console/gui)

* Also fixed up some tests when running in console
This commit is contained in:
Gaute Lindkvist committed 2019-06-05 15:45:22 +02:00
1 parent eec5569eca
commit 1a337ea0f8
8 files changed
+76 -23

No files matched your search

@@ -23,4 +23,11 @@ class App:
def versionString(self):
return str(self.majorVersion()) + "." + str(self.minorVersion()) + "." + str(self.patchVersion())
def exit(self):
print("Telling ResInsight to Exit")
return self.app.Exit(Empty())
def isConsole(self):
print("RunTimeInfo stuff: ", self.app.GetRuntimeInfo(Empty()).app_type)
return self.app.GetRuntimeInfo(Empty()).app_type == App_pb2.ApplicationTypeEnum.Value('CONSOLE_APPLICATION')
def isGui(self):
print("RunTimeInfo stuff: ", self.app.GetRuntimeInfo(Empty()).app_type)
return self.app.GetRuntimeInfo(Empty()).app_type == App_pb2.ApplicationTypeEnum.Value('GUI_APPLICATION')
@@ -13,6 +13,8 @@ from .Commands import Commands
from .Project import Project
class Instance:
launched = False
@staticmethod
def is_port_in_use(port):
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
@@ -20,7 +22,7 @@ class Instance:
return s.connect_ex(('localhost', port)) == 0
@staticmethod
def launch(resInsightExecutable = ''):
def launch(resInsightExecutable = '', console = False):
port = 50051
portEnv = os.environ.get('RESINSIGHT_GRPC_PORT')
if portEnv:
@@ -38,9 +40,11 @@ class Instance:
print('Port ' + str(port))
print('Trying to launch', resInsightExecutable)
pid = os.spawnl(os.P_NOWAIT, resInsightExecutable, " --grpcserver " + str(port))
print(pid)
return Instance(port)
parameters = " --grpcserver " + str(port)
if console:
parameters += " --console"
pid = os.spawnl(os.P_NOWAIT, resInsightExecutable, parameters)
return Instance(port=port, launched=True)
@staticmethod
def find(startPort = 50051, endPort = 50071):
@@ -56,10 +60,11 @@ class Instance:
print('Error: Could not find any ResInsight instances responding between ports ' + str(startPort) + ' and ' + str(endPort))
return None
def __init__(self, port = 50051):
def __init__(self, port = 50051, launched = False):
logging.basicConfig()
location = "localhost:" + str(port)
self.channel = grpc.insecure_channel(location)
self.launched = launched
# Main version check package
self.app = App(self.channel)
@@ -77,4 +82,10 @@ class Instance:
# Service packages
self.commands = Commands(self.channel)
self.project = Project(self.channel)
path = os.getcwd()
self.commands.setStartDir(path=path)
def __del__(self):
if self.launched:
self.app.exit()