2019-09-23 04:50:33 -05:00
|
|
|
# pylint: disable=no-self-use
|
|
|
|
"""
|
|
|
|
The main entry point for ResInsight connections
|
|
|
|
The Instance class contained have static methods launch and find for
|
|
|
|
creating connections to ResInsight
|
|
|
|
"""
|
|
|
|
|
2023-07-12 04:42:17 -05:00
|
|
|
from __future__ import annotations
|
2019-09-23 04:50:33 -05:00
|
|
|
import os
|
|
|
|
import socket
|
|
|
|
import logging
|
|
|
|
import time
|
2022-09-26 07:19:21 -05:00
|
|
|
import tempfile
|
2022-09-29 00:37:31 -05:00
|
|
|
import signal
|
2024-06-05 07:06:49 -05:00
|
|
|
import sys
|
|
|
|
import json
|
2019-09-23 04:50:33 -05:00
|
|
|
|
|
|
|
import grpc
|
|
|
|
|
2020-08-19 00:30:51 -05:00
|
|
|
import App_pb2
|
|
|
|
import App_pb2_grpc
|
|
|
|
import Commands_pb2
|
|
|
|
import Commands_pb2_grpc
|
|
|
|
from Definitions_pb2 import Empty
|
2019-09-23 04:50:33 -05:00
|
|
|
|
2020-08-19 00:30:51 -05:00
|
|
|
import RiaVersionInfo
|
2019-09-23 04:50:33 -05:00
|
|
|
|
2020-08-19 00:30:51 -05:00
|
|
|
from .project import Project
|
2020-12-18 07:27:52 -06:00
|
|
|
from .retry_policy import ExponentialBackoffRetryPolicy
|
2020-12-18 10:20:15 -06:00
|
|
|
from .grpc_retry_interceptor import RetryOnRpcErrorClientInterceptor
|
2021-08-23 04:58:32 -05:00
|
|
|
from .generated.generated_classes import CommandRouter
|
2020-12-18 10:20:15 -06:00
|
|
|
|
2023-07-12 04:42:17 -05:00
|
|
|
from typing import List, Optional, Tuple
|
|
|
|
from typing_extensions import Self
|
2024-06-05 07:06:49 -05:00
|
|
|
from pathlib import Path
|
2023-07-12 04:42:17 -05:00
|
|
|
|
2019-09-23 04:50:33 -05:00
|
|
|
|
|
|
|
class Instance:
|
|
|
|
"""The ResInsight Instance class. Use to launch or find existing ResInsight instances
|
|
|
|
|
|
|
|
Attributes:
|
|
|
|
launched (bool): Tells us whether the application was launched as a new process.
|
|
|
|
If the application was launched we may need to close it when exiting the script.
|
|
|
|
commands (Commands): Command executor. Set when creating an instance.
|
|
|
|
project (Project): Current project in ResInsight.
|
|
|
|
Set when creating an instance and updated when opening/closing projects.
|
|
|
|
"""
|
2021-01-26 13:48:01 -06:00
|
|
|
|
2019-09-23 04:50:33 -05:00
|
|
|
@staticmethod
|
2023-07-12 04:42:17 -05:00
|
|
|
def __is_port_in_use(port: int) -> bool:
|
2019-09-23 04:50:33 -05:00
|
|
|
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as my_socket:
|
|
|
|
my_socket.settimeout(0.2)
|
2021-01-26 13:48:01 -06:00
|
|
|
return my_socket.connect_ex(("localhost", port)) == 0
|
2019-09-23 04:50:33 -05:00
|
|
|
|
2019-10-09 03:30:07 -05:00
|
|
|
@staticmethod
|
2023-07-12 04:42:17 -05:00
|
|
|
def __is_valid_port(port: int) -> bool:
|
2019-10-09 03:30:07 -05:00
|
|
|
location = "localhost:" + str(port)
|
2021-01-26 13:48:01 -06:00
|
|
|
channel = grpc.insecure_channel(
|
|
|
|
location, options=[("grpc.enable_http_proxy", False)]
|
|
|
|
)
|
2019-10-09 03:30:07 -05:00
|
|
|
app = App_pb2_grpc.AppStub(channel)
|
|
|
|
try:
|
|
|
|
app.GetVersion(Empty(), timeout=1)
|
|
|
|
except grpc.RpcError:
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
2022-09-26 07:19:21 -05:00
|
|
|
@staticmethod
|
2024-09-04 11:51:53 -05:00
|
|
|
def __read_port_number_from_file(file_path: str, max_attempts: int) -> int:
|
2022-09-26 07:19:21 -05:00
|
|
|
retry_count = 0
|
2024-09-04 11:51:53 -05:00
|
|
|
while not os.path.exists(file_path) and retry_count < max_attempts:
|
2022-09-26 07:19:21 -05:00
|
|
|
time.sleep(1)
|
|
|
|
retry_count = retry_count + 1
|
|
|
|
|
|
|
|
if os.path.isfile(file_path):
|
|
|
|
with open(file_path) as f:
|
|
|
|
value = f.readline()
|
|
|
|
return int(value)
|
2024-09-04 11:51:53 -05:00
|
|
|
|
|
|
|
if retry_count == max_attempts:
|
|
|
|
print(
|
|
|
|
"Waiting for port number file timed out after {} seconds. File: {}".format(
|
|
|
|
max_attempts, file_path
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
return -1
|
2022-09-26 07:19:21 -05:00
|
|
|
|
2022-09-29 00:37:31 -05:00
|
|
|
@staticmethod
|
2023-07-12 04:42:17 -05:00
|
|
|
def __kill_process(pid: int) -> None:
|
2022-09-29 00:37:31 -05:00
|
|
|
"""
|
|
|
|
Kill the process with a given pid.
|
|
|
|
"""
|
|
|
|
if hasattr(signal, "CTRL_C_EVENT"):
|
|
|
|
# windows does not have kill
|
|
|
|
os.kill(pid, signal.CTRL_C_EVENT)
|
|
|
|
else:
|
|
|
|
# linux/unix
|
|
|
|
os.kill(pid, signal.SIGKILL)
|
|
|
|
|
2019-09-23 04:50:33 -05:00
|
|
|
@staticmethod
|
2021-01-26 13:48:01 -06:00
|
|
|
def launch(
|
2023-07-12 04:42:17 -05:00
|
|
|
resinsight_executable: str = "",
|
|
|
|
console: bool = False,
|
2024-08-20 10:24:31 -05:00
|
|
|
launch_port: int = 0,
|
2024-09-04 11:51:53 -05:00
|
|
|
init_timeout: int = 300,
|
2023-07-12 04:42:17 -05:00
|
|
|
command_line_parameters: List[str] = [],
|
|
|
|
) -> Optional[Instance]:
|
2021-01-26 13:48:01 -06:00
|
|
|
"""Launch a new Instance of ResInsight. This requires the environment variable
|
2019-09-23 04:50:33 -05:00
|
|
|
RESINSIGHT_EXECUTABLE to be set or the parameter resinsight_executable to be provided.
|
|
|
|
The RESINSIGHT_GRPC_PORT environment variable can be set to an alternative port number.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
resinsight_executable (str): Path to a valid ResInsight executable. If set
|
|
|
|
will take precedence over what is provided in the RESINSIGHT_EXECUTABLE
|
|
|
|
environment variable.
|
|
|
|
console (bool): If True, launch as console application, without GUI.
|
2024-08-20 10:24:31 -05:00
|
|
|
launch_port(int): If 0, GRPC will find an available port.
|
|
|
|
If -1, use the default port 50051 or RESINSIGHT_GRPC_PORT
|
|
|
|
If anything else, ResInsight will try to launch with the specified portnumber.
|
2024-09-04 11:51:53 -05:00
|
|
|
init_timeout: Number of seconds to wait for initialization before timing out.
|
2019-09-23 04:50:33 -05:00
|
|
|
command_line_parameters(list): Additional parameters as string entries in the list.
|
|
|
|
Returns:
|
|
|
|
Instance: an instance object if it worked. None if not.
|
|
|
|
"""
|
|
|
|
|
2023-07-12 04:42:17 -05:00
|
|
|
requested_port: int = 50051
|
2021-01-26 13:48:01 -06:00
|
|
|
port_env = os.environ.get("RESINSIGHT_GRPC_PORT")
|
2019-09-23 04:50:33 -05:00
|
|
|
if port_env:
|
2022-09-26 07:19:21 -05:00
|
|
|
requested_port = int(port_env)
|
2021-01-12 04:09:03 -06:00
|
|
|
if launch_port != -1:
|
2022-09-26 07:19:21 -05:00
|
|
|
requested_port = launch_port
|
2019-09-23 04:50:33 -05:00
|
|
|
|
2024-06-05 07:06:49 -05:00
|
|
|
if not resinsight_executable:
|
|
|
|
filename = Path(sys.prefix) / "share" / "rips" / "rips_config.json"
|
|
|
|
if filename.is_file():
|
|
|
|
f = open(filename)
|
|
|
|
data = json.load(f)
|
|
|
|
resinsight_executable = data["resinsight_executable"]
|
|
|
|
if resinsight_executable:
|
|
|
|
print(
|
|
|
|
"In './share/rips/rips_config.json', found resinsight_executable:",
|
|
|
|
resinsight_executable,
|
|
|
|
)
|
|
|
|
|
2019-09-23 04:50:33 -05:00
|
|
|
if not resinsight_executable:
|
2023-07-12 04:42:17 -05:00
|
|
|
resinsight_executable_from_env = os.environ.get("RESINSIGHT_EXECUTABLE")
|
|
|
|
if not resinsight_executable_from_env:
|
2019-09-23 04:50:33 -05:00
|
|
|
print(
|
2021-01-26 13:48:01 -06:00
|
|
|
"ERROR: Could not launch ResInsight because the environment variable"
|
|
|
|
" RESINSIGHT_EXECUTABLE is not set"
|
|
|
|
)
|
2019-09-23 04:50:33 -05:00
|
|
|
return None
|
2023-07-12 04:42:17 -05:00
|
|
|
else:
|
|
|
|
resinsight_executable = resinsight_executable_from_env
|
2019-09-23 04:50:33 -05:00
|
|
|
|
2021-01-26 13:48:01 -06:00
|
|
|
print("Trying to launch", resinsight_executable)
|
2022-09-26 07:19:21 -05:00
|
|
|
with tempfile.TemporaryDirectory() as tmp_dir_path:
|
|
|
|
port_number_file = tmp_dir_path + "/portnumber.txt"
|
2023-07-12 04:42:17 -05:00
|
|
|
parameters: List[str] = [
|
2022-09-26 07:19:21 -05:00
|
|
|
"ResInsight",
|
|
|
|
"--server",
|
2023-07-12 04:42:17 -05:00
|
|
|
str(requested_port),
|
2022-09-26 07:19:21 -05:00
|
|
|
"--portnumberfile",
|
2023-07-12 04:42:17 -05:00
|
|
|
str(port_number_file),
|
2022-09-26 07:19:21 -05:00
|
|
|
] + command_line_parameters
|
|
|
|
if console:
|
|
|
|
print("Launching as console app")
|
|
|
|
parameters.append("--console")
|
|
|
|
|
|
|
|
# Stringify all parameters
|
|
|
|
for i in range(0, len(parameters)):
|
|
|
|
parameters[i] = str(parameters[i])
|
|
|
|
|
|
|
|
pid = os.spawnv(os.P_NOWAIT, resinsight_executable, parameters)
|
|
|
|
if pid:
|
2024-09-04 11:51:53 -05:00
|
|
|
port = Instance.__read_port_number_from_file(
|
|
|
|
port_number_file, init_timeout
|
|
|
|
)
|
2022-09-26 07:19:21 -05:00
|
|
|
if port == -1:
|
|
|
|
print("Unable to read port number. Launch failed.")
|
|
|
|
# Need to kill the process using PID since there is no GRPC connection to use.
|
2022-09-29 00:37:31 -05:00
|
|
|
Instance.__kill_process(pid)
|
2022-09-26 07:19:21 -05:00
|
|
|
else:
|
|
|
|
instance = Instance(port=port, launched=True)
|
|
|
|
return instance
|
2019-09-23 04:50:33 -05:00
|
|
|
return None
|
|
|
|
|
|
|
|
@staticmethod
|
2023-07-12 04:42:17 -05:00
|
|
|
def find(start_port: int = 50051, end_port: int = 50071) -> Optional[Instance]:
|
2021-01-26 13:48:01 -06:00
|
|
|
"""Search for an existing Instance of ResInsight by testing ports.
|
2019-09-23 04:50:33 -05:00
|
|
|
|
|
|
|
By default we search from port 50051 to 50071 or if the environment
|
|
|
|
variable RESINSIGHT_GRPC_PORT is set we search
|
|
|
|
RESINSIGHT_GRPC_PORT to RESINSIGHT_GRPC_PORT+20
|
|
|
|
|
|
|
|
Args:
|
|
|
|
start_port (int): start searching from this port
|
|
|
|
end_port (int): search up to but not including this port
|
|
|
|
"""
|
2021-01-26 13:48:01 -06:00
|
|
|
port_env = os.environ.get("RESINSIGHT_GRPC_PORT")
|
2019-09-23 04:50:33 -05:00
|
|
|
if port_env:
|
2019-10-09 03:30:07 -05:00
|
|
|
print("Got port " + port_env + " from environment")
|
2019-09-23 04:50:33 -05:00
|
|
|
start_port = int(port_env)
|
|
|
|
end_port = start_port + 20
|
|
|
|
|
|
|
|
for try_port in range(start_port, end_port):
|
2019-10-09 03:30:07 -05:00
|
|
|
print("Trying port " + str(try_port))
|
2021-01-26 13:48:01 -06:00
|
|
|
if Instance.__is_port_in_use(try_port) and Instance.__is_valid_port(
|
|
|
|
try_port
|
|
|
|
):
|
2019-09-23 04:50:33 -05:00
|
|
|
return Instance(port=try_port)
|
|
|
|
|
|
|
|
print(
|
2021-01-26 13:48:01 -06:00
|
|
|
"Error: Could not find any ResInsight instances responding between ports "
|
|
|
|
+ str(start_port)
|
|
|
|
+ " and "
|
|
|
|
+ str(end_port)
|
|
|
|
)
|
2019-09-23 04:50:33 -05:00
|
|
|
return None
|
|
|
|
|
|
|
|
def __execute_command(self, **command_params):
|
2020-08-19 00:30:51 -05:00
|
|
|
return self.commands.Execute(Commands_pb2.CommandParams(**command_params))
|
2019-09-23 04:50:33 -05:00
|
|
|
|
2023-07-12 04:42:17 -05:00
|
|
|
def __check_version(self) -> Tuple[bool, bool]:
|
2019-09-23 04:50:33 -05:00
|
|
|
try:
|
|
|
|
major_version_ok = self.major_version() == int(
|
2021-01-26 13:48:01 -06:00
|
|
|
RiaVersionInfo.RESINSIGHT_MAJOR_VERSION
|
|
|
|
)
|
2019-09-23 04:50:33 -05:00
|
|
|
minor_version_ok = self.minor_version() == int(
|
2021-01-26 13:48:01 -06:00
|
|
|
RiaVersionInfo.RESINSIGHT_MINOR_VERSION
|
|
|
|
)
|
2019-09-23 04:50:33 -05:00
|
|
|
return True, major_version_ok and minor_version_ok
|
|
|
|
except grpc.RpcError:
|
|
|
|
return False, False
|
|
|
|
|
2023-07-12 04:42:17 -05:00
|
|
|
def __init__(self, port: int = 50051, launched: bool = False) -> None:
|
|
|
|
"""Attempts to connect to ResInsight at a specific port on localhost
|
2019-09-23 04:50:33 -05:00
|
|
|
|
|
|
|
Args:
|
|
|
|
port(int): port number
|
|
|
|
"""
|
|
|
|
logging.basicConfig()
|
2023-07-12 04:42:17 -05:00
|
|
|
self.location: str = "localhost:" + str(port)
|
2019-09-23 04:50:33 -05:00
|
|
|
|
2021-01-26 13:48:01 -06:00
|
|
|
self.channel = grpc.insecure_channel(
|
2022-09-26 07:19:21 -05:00
|
|
|
self.location, options=[("grpc.enable_http_proxy", False)]
|
2021-01-26 13:48:01 -06:00
|
|
|
)
|
2019-09-23 04:50:33 -05:00
|
|
|
self.launched = launched
|
2020-08-19 00:30:51 -05:00
|
|
|
self.commands = Commands_pb2_grpc.CommandsStub(self.channel)
|
2019-09-23 04:50:33 -05:00
|
|
|
|
|
|
|
# Main version check package
|
2019-10-09 03:30:07 -05:00
|
|
|
self.app = App_pb2_grpc.AppStub(self.channel)
|
2019-09-23 04:50:33 -05:00
|
|
|
|
2022-09-26 07:19:21 -05:00
|
|
|
self._check_connection_and_version(self.channel, launched, self.location)
|
2020-12-18 10:44:31 -06:00
|
|
|
|
|
|
|
# Intercept UNAVAILABLE errors and retry on failures
|
|
|
|
interceptors = (
|
|
|
|
RetryOnRpcErrorClientInterceptor(
|
2021-01-26 13:48:01 -06:00
|
|
|
retry_policy=ExponentialBackoffRetryPolicy(
|
|
|
|
min_backoff=100, max_backoff=5000, max_num_retries=20
|
|
|
|
),
|
2020-12-18 10:44:31 -06:00
|
|
|
status_for_retry=(grpc.StatusCode.UNAVAILABLE,),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
intercepted_channel = grpc.intercept_channel(self.channel, *interceptors)
|
|
|
|
|
2021-08-23 04:58:32 -05:00
|
|
|
# Recreate command stubs with the retry policy
|
2020-12-18 10:44:31 -06:00
|
|
|
self.commands = Commands_pb2_grpc.CommandsStub(intercepted_channel)
|
|
|
|
|
|
|
|
# Service packages
|
|
|
|
self.project = Project.create(intercepted_channel)
|
|
|
|
|
2021-08-23 04:58:32 -05:00
|
|
|
# Command Router object used as entry point for independent processing functions
|
|
|
|
self.command_router = CommandRouter(
|
|
|
|
self.app.GetPdmObject(Empty()), intercepted_channel
|
|
|
|
)
|
|
|
|
|
2020-12-18 10:44:31 -06:00
|
|
|
path = os.getcwd()
|
|
|
|
self.set_start_dir(path=path)
|
|
|
|
|
2023-07-12 04:42:17 -05:00
|
|
|
def _check_connection_and_version(
|
|
|
|
self, channel: grpc.Channel, launched: bool, location: str
|
|
|
|
) -> None:
|
2019-09-23 04:50:33 -05:00
|
|
|
connection_ok = False
|
|
|
|
version_ok = False
|
|
|
|
|
2020-12-18 07:27:52 -06:00
|
|
|
retry_policy = ExponentialBackoffRetryPolicy()
|
2019-09-23 04:50:33 -05:00
|
|
|
if self.launched:
|
2020-12-18 06:36:05 -06:00
|
|
|
for num_tries in range(0, retry_policy.num_retries()):
|
2019-09-23 04:50:33 -05:00
|
|
|
connection_ok, version_ok = self.__check_version()
|
|
|
|
if connection_ok:
|
|
|
|
break
|
2020-12-18 06:36:05 -06:00
|
|
|
retry_policy.sleep(num_tries)
|
2019-09-23 04:50:33 -05:00
|
|
|
else:
|
|
|
|
connection_ok, version_ok = self.__check_version()
|
|
|
|
|
|
|
|
if not connection_ok:
|
|
|
|
if self.launched:
|
2021-01-26 13:48:01 -06:00
|
|
|
raise Exception(
|
|
|
|
"Error: Could not connect to resinsight at ",
|
|
|
|
location,
|
|
|
|
".",
|
|
|
|
retry_policy.time_out_message(),
|
|
|
|
)
|
|
|
|
raise Exception("Error: Could not connect to resinsight at ", location)
|
2019-09-23 04:50:33 -05:00
|
|
|
if not version_ok:
|
2021-01-26 13:48:01 -06:00
|
|
|
raise Exception(
|
|
|
|
"Error: Wrong Version of ResInsight at ",
|
|
|
|
location,
|
2024-01-17 03:11:11 -06:00
|
|
|
"Executable : " + self.version_string(),
|
2021-01-26 13:48:01 -06:00
|
|
|
" ",
|
2024-01-17 03:11:11 -06:00
|
|
|
"rips : " + self.client_version_string(),
|
2021-01-26 13:48:01 -06:00
|
|
|
)
|
2019-09-23 04:50:33 -05:00
|
|
|
|
2023-07-12 04:42:17 -05:00
|
|
|
def __version_message(self) -> App_pb2.Version:
|
2019-09-23 04:50:33 -05:00
|
|
|
return self.app.GetVersion(Empty())
|
|
|
|
|
2023-07-12 04:42:17 -05:00
|
|
|
def set_start_dir(self, path: str):
|
2019-09-23 04:50:33 -05:00
|
|
|
"""Set current start directory
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
path (str): path to directory
|
|
|
|
|
|
|
|
"""
|
2021-01-26 13:48:01 -06:00
|
|
|
return self.__execute_command(
|
|
|
|
setStartDir=Commands_pb2.FilePathRequest(path=path)
|
|
|
|
)
|
2019-09-23 04:50:33 -05:00
|
|
|
|
2023-07-12 04:42:17 -05:00
|
|
|
def set_export_folder(
|
|
|
|
self, export_type: str, path: str, create_folder: bool = False
|
|
|
|
):
|
2019-09-23 04:50:33 -05:00
|
|
|
"""
|
|
|
|
Set the export folder used for all export functions
|
|
|
|
|
2020-03-30 07:07:04 -05:00
|
|
|
**Parameters**::
|
2019-09-24 04:06:24 -05:00
|
|
|
|
2020-03-30 07:07:04 -05:00
|
|
|
Parameter | Description | Type
|
|
|
|
---------------- | -------------------------------------------- | -----
|
|
|
|
export_type | String specifying what to export | String
|
|
|
|
path | Path to folder | String
|
|
|
|
create_folder | Create folder if it doesn't exist? | Boolean
|
2019-09-24 04:06:24 -05:00
|
|
|
|
2020-03-30 07:07:04 -05:00
|
|
|
**Enum export_type**::
|
|
|
|
|
|
|
|
Option | Description
|
|
|
|
--------------- | ------------
|
2021-01-26 13:48:01 -06:00
|
|
|
"COMPLETIONS" |
|
2020-03-30 07:07:04 -05:00
|
|
|
"SNAPSHOTS" |
|
2021-01-26 13:48:01 -06:00
|
|
|
"PROPERTIES" |
|
|
|
|
"STATISTICS" |
|
2019-09-24 04:06:24 -05:00
|
|
|
|
2019-09-23 04:50:33 -05:00
|
|
|
"""
|
2021-01-26 13:48:01 -06:00
|
|
|
return self.__execute_command(
|
|
|
|
setExportFolder=Commands_pb2.SetExportFolderRequest(
|
|
|
|
type=export_type, path=path, createFolder=create_folder
|
|
|
|
)
|
|
|
|
)
|
2019-09-23 04:50:33 -05:00
|
|
|
|
2023-07-12 04:42:17 -05:00
|
|
|
def set_main_window_size(self, width: int, height: int):
|
2019-09-23 04:50:33 -05:00
|
|
|
"""
|
|
|
|
Set the main window size in pixels
|
2019-09-24 04:06:24 -05:00
|
|
|
|
2020-03-30 07:07:04 -05:00
|
|
|
**Parameters**::
|
|
|
|
|
|
|
|
Parameter | Description | Type
|
|
|
|
--------- | ---------------- | -----
|
|
|
|
width | Width in pixels | Integer
|
|
|
|
height | Height in pixels | Integer
|
|
|
|
|
2019-09-23 04:50:33 -05:00
|
|
|
"""
|
2021-01-26 13:48:01 -06:00
|
|
|
return self.__execute_command(
|
|
|
|
setMainWindowSize=Commands_pb2.SetWindowSizeParams(
|
|
|
|
width=width, height=height
|
|
|
|
)
|
|
|
|
)
|
2019-10-16 08:46:31 -05:00
|
|
|
|
2023-07-12 04:42:17 -05:00
|
|
|
def set_plot_window_size(self, width: int, height: int):
|
2019-10-16 08:46:31 -05:00
|
|
|
"""
|
|
|
|
Set the plot window size in pixels
|
|
|
|
|
2020-03-30 07:07:04 -05:00
|
|
|
**Parameters**::
|
2020-04-16 09:06:18 -05:00
|
|
|
|
2020-03-30 07:07:04 -05:00
|
|
|
Parameter | Description | Type
|
|
|
|
--------- | ---------------- | -----
|
|
|
|
width | Width in pixels | Integer
|
|
|
|
height | Height in pixels | Integer
|
2019-10-16 08:46:31 -05:00
|
|
|
"""
|
2021-01-26 13:48:01 -06:00
|
|
|
return self.__execute_command(
|
|
|
|
setPlotWindowSize=Commands_pb2.SetWindowSizeParams(
|
|
|
|
width=width, height=height
|
|
|
|
)
|
|
|
|
)
|
2019-09-23 04:50:33 -05:00
|
|
|
|
2023-07-12 04:42:17 -05:00
|
|
|
def major_version(self) -> int:
|
2019-09-23 04:50:33 -05:00
|
|
|
"""Get an integer with the major version number"""
|
2023-07-12 04:42:17 -05:00
|
|
|
return int(self.__version_message().major_version)
|
2019-09-23 04:50:33 -05:00
|
|
|
|
2023-07-12 04:42:17 -05:00
|
|
|
def minor_version(self) -> int:
|
2019-09-23 04:50:33 -05:00
|
|
|
"""Get an integer with the minor version number"""
|
2023-07-12 04:42:17 -05:00
|
|
|
return int(self.__version_message().minor_version)
|
2019-09-23 04:50:33 -05:00
|
|
|
|
2023-07-12 04:42:17 -05:00
|
|
|
def patch_version(self) -> int:
|
2019-09-23 04:50:33 -05:00
|
|
|
"""Get an integer with the patch version number"""
|
2023-07-12 04:42:17 -05:00
|
|
|
return int(self.__version_message().patch_version)
|
2019-09-23 04:50:33 -05:00
|
|
|
|
2023-07-12 04:42:17 -05:00
|
|
|
def version_string(self) -> str:
|
2019-09-23 04:50:33 -05:00
|
|
|
"""Get a full version string, i.e. 2019.04.01"""
|
2021-01-26 13:48:01 -06:00
|
|
|
return (
|
|
|
|
str(self.major_version())
|
|
|
|
+ "."
|
|
|
|
+ str(self.minor_version())
|
|
|
|
+ "."
|
|
|
|
+ str(self.patch_version())
|
|
|
|
)
|
2019-09-23 04:50:33 -05:00
|
|
|
|
2023-07-12 04:42:17 -05:00
|
|
|
def client_version_string(self) -> str:
|
2019-09-23 04:50:33 -05:00
|
|
|
"""Get a full version string, i.e. 2019.04.01"""
|
2023-07-12 04:42:17 -05:00
|
|
|
version_string: str = RiaVersionInfo.RESINSIGHT_MAJOR_VERSION + "."
|
2019-09-23 04:50:33 -05:00
|
|
|
version_string += RiaVersionInfo.RESINSIGHT_MINOR_VERSION + "."
|
|
|
|
version_string += RiaVersionInfo.RESINSIGHT_PATCH_VERSION
|
|
|
|
return version_string
|
|
|
|
|
|
|
|
def exit(self):
|
|
|
|
"""Tell ResInsight instance to quit"""
|
|
|
|
print("Telling ResInsight to Exit")
|
|
|
|
return self.app.Exit(Empty())
|
|
|
|
|
2023-07-12 04:42:17 -05:00
|
|
|
def is_console(self) -> bool:
|
2019-09-23 04:50:33 -05:00
|
|
|
"""Returns true if the connected ResInsight instance is a console app"""
|
2023-07-12 04:42:17 -05:00
|
|
|
return bool(
|
|
|
|
self.app.GetRuntimeInfo(Empty()).app_type
|
|
|
|
== App_pb2.ApplicationTypeEnum.Value("CONSOLE_APPLICATION")
|
|
|
|
)
|
2019-09-23 04:50:33 -05:00
|
|
|
|
2023-07-12 04:42:17 -05:00
|
|
|
def is_gui(self) -> bool:
|
2019-09-23 04:50:33 -05:00
|
|
|
"""Returns true if the connected ResInsight instance is a GUI app"""
|
2023-07-12 04:42:17 -05:00
|
|
|
return bool(
|
|
|
|
self.app.GetRuntimeInfo(Empty()).app_type
|
|
|
|
== App_pb2.ApplicationTypeEnum.Value("GUI_APPLICATION")
|
|
|
|
)
|