def selected_cases(self): """Get a list of all grid cases selected in the project tree Returns: A list of :class:`rips.generated.generated_classes.Case` """ case_infos = self._project_stub.GetSelectedCases(Empty()) cases = [] for case_info in case_infos.data: cases.append(self.case(case_info.id)) return cases
def __is_valid_port(port): location = "localhost:" + str(port) channel = grpc.insecure_channel(location, options=[('grpc.enable_http_proxy', False)]) app = App_pb2_grpc.AppStub(channel) try: app.GetVersion(Empty(), timeout=1) except grpc.RpcError: return False return True
def selectedCases(self): """Get a list of all cases selected in the project tree Returns: A list of rips Case objects """ caseInfos = self.project.GetSelectedCases(Empty()) cases = [] for caseInfo in caseInfos.data: cases.append(Case(self.channel, caseInfo.id)) return cases
def __init__(self, port=50051, launched=False): """Attempts to connect to ResInsight at aa specific port on localhost Args: port(int): port number """ logging.basicConfig() location = "localhost:" + str(port) self.channel = grpc.insecure_channel(location, options=[ ("grpc.enable_http_proxy", False) ]) self.launched = launched self.commands = Commands_pb2_grpc.CommandsStub(self.channel) # Main version check package self.app = App_pb2_grpc.AppStub(self.channel) self._check_connection_and_version(self.channel, launched, location) # Intercept UNAVAILABLE errors and retry on failures interceptors = (RetryOnRpcErrorClientInterceptor( retry_policy=ExponentialBackoffRetryPolicy(min_backoff=100, max_backoff=5000, max_num_retries=20), status_for_retry=(grpc.StatusCode.UNAVAILABLE, ), ), ) intercepted_channel = grpc.intercept_channel(self.channel, *interceptors) # Recreate command stubs with the retry policy self.commands = Commands_pb2_grpc.CommandsStub(intercepted_channel) # Service packages self.project = Project.create(intercepted_channel) # Command Router object used as entry point for independent processing functions self.command_router = CommandRouter(self.app.GetPdmObject(Empty()), intercepted_channel) path = os.getcwd() self.set_start_dir(path=path)
def cases(self): """Get a list of all cases in the project Returns: A list of rips Case objects """ 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 is_gui(self): """Returns true if the connected ResInsight instance is a GUI app""" return self.app.GetRuntimeInfo( Empty()).app_type == App_pb2.ApplicationTypeEnum.Value( 'GUI_APPLICATION')
def exit(self): """Tell ResInsight instance to quit""" print("Telling ResInsight to Exit") return self.app.Exit(Empty())
def __version_message(self): return self.app.GetVersion(Empty())
def is_console(self): """Returns true if the connected ResInsight instance is a console app""" return self.app.GetRuntimeInfo( Empty()).app_type == App_pb2.ApplicationTypeEnum.Value( "CONSOLE_APPLICATION")
def __init__(self, channel): self.channel = channel self.project = Project_pb2_grpc.ProjectStub(channel) PdmObject.__init__(self, self.project.GetPdmObject(Empty()), self.channel)
def closeProject(self): """Close the current project (and reopen empty one)""" return self.__execute(closeProject=Empty())
def close(self): """Close the current project (and open new blank project)""" self._execute_command(closeProject=Empty())
def create(channel): project_stub = Project_pb2_grpc.ProjectStub(channel) pb2_object = project_stub.GetPdmObject(Empty()) return Project(pb2_object, channel)