def get_included_files(self, grpc_path='grpc://localhost:12321', recursive=True, include_args={}, include_pattern=[], search_in_ext=[]): ''' :param str grpc_path: the root path to search for included files :param bool recursive: True for recursive search :param include_args: dictionary with arguments to override while include. :type include_args: {str: str} :param include_pattern: the list with regular expression patterns to find include files. :type include_pattern: [str] :param search_in_ext: file extensions to search in :type search_in_ext: [str] :return: Returns an iterator for tuple with root path, line number, path of included file, file exists or not, file size and dictionary with defined arguments. :rtype: iterator (str, int, str, bool, int, {str: str}) ''' dorequest = False try: for entry in self._cache_file_includes[grpc_path]: do_return = True if not recursive and entry.rec_depth != 0: do_return = False if do_return: rospy.logdebug("get_included_files from cache: %s, include_args: %s" % (entry.inc_path, entry.args)) yield entry except KeyError: dorequest = True if dorequest: current_path = grpc_path try: uri, path = nmdurl.split(current_path) lm, channel = self.get_launch_manager(uri) rospy.logdebug("get_included_files for %s, recursive: %s, include_args: %s, pattern: %s, search_in_ext: %s" % (grpc_path, recursive, include_args, include_pattern, search_in_ext)) reply = lm.get_included_files(path, recursive, include_args, include_pattern, search_in_ext) url, _ = nmdurl.split(grpc_path, with_scheme=True) # initialize requested path in cache if recursive: if grpc_path not in self._cache_file_includes: self._cache_file_includes[grpc_path] = [] for inc_file in reply: entry = inc_file entry.path_or_str = nmdurl.join(url, inc_file.path_or_str) entry.inc_path = nmdurl.join(url, inc_file.inc_path) # initialize and add returned root path to cache, only on recursive if recursive: if current_path not in self._cache_file_includes: self._cache_file_includes[current_path] = [] self._cache_file_includes[current_path].append(entry) yield entry except grpc._channel._Rendezvous as grpc_error: self.clear_cache(grpc_path) self.clear_cache(current_path) if grpc_error.code() == grpc.StatusCode.DEADLINE_EXCEEDED: raise exceptions.GrpcTimeout(grpc_path, grpc_error) raise finally: self.close_channel(channel, uri)
def load_launch(self, grpc_path, masteruri='', host='', package='', launch='', args={}): ''' Loads given file on remote grpc-server. :return: Path of loaded file :rtype: str ''' uri, path = nmdurl.split(grpc_path) lm, channel = self.get_launch_manager(uri) myargs = args request_args = True nexttry = True ok = False launch_file = '' args_res = {} while nexttry: try: rospy.logdebug("load launch file on gRPC server: %s" % (grpc_path)) launch_file, args_res = lm.load_launch(package, launch, path=path, args=myargs, request_args=request_args, masteruri=masteruri, host=host) nexttry = False ok = True except exceptions.LaunchSelectionRequest as lsr: # TODO: selection dialog rospy.logwarn("%s\n ...load the last one!" % lsr) path = lsr.choices[-1] except exceptions.ParamSelectionRequest as psr: rospy.loginfo("Params requered for: %s" % ["%s:=%s" % (name, value) for name, value in psr.choices.items()]) request_args = False myargs = psr.choices # request the args: the dialog must run in the main thread of Qt params = {} for name, value in psr.choices.items(): params[name] = {':value': value, ':type': 'string'} raise LaunchArgsSelectionRequest(grpc_path, params, 'Needs input for args') except exceptions.AlreadyOpenException as aoe: rospy.logwarn(aoe) nexttry = False ok = True launch_file = aoe.path except grpc._channel._Rendezvous as grpc_error: if grpc_error.code() == grpc.StatusCode.DEADLINE_EXCEEDED: raise exceptions.GrpcTimeout(grpc_path, grpc_error) raise finally: self.close_channel(channel, uri) launch_file = nmdurl.join("grpc://%s" % uri, launch_file) rospy.logdebug(" load launch file result - %s: %s" % ('OK' if ok else "ERR", launch_file)) with self._args_lock: rospy.logdebug("add args after load %s: %s" % (launch_file, args_res)) self._launch_args[launch_file] = args_res return launch_file, args_res
def reload_launch(self, grpc_path, masteruri=''): rospy.logdebug("reload launch %s" % grpc_path) uri, path = nmdurl.split(grpc_path) lm, channel = self.get_launch_manager(uri) launch_file = '' try: launch_files, changed_nodes = lm.reload_launch(path, masteruri=masteruri) if launch_files: launch_file = launch_files[0] return launch_file, [node for node in changed_nodes] except grpc._channel._Rendezvous as grpc_error: if grpc_error.code() == grpc.StatusCode.DEADLINE_EXCEEDED: raise exceptions.GrpcTimeout(grpc_path, grpc_error) raise finally: self.close_channel(channel, uri)