Пример #1
0
 def get_included_files_set(self, grpc_path='grpc://localhost:12321', recursive=True, include_pattern=[], search_in_ext=[]):
     '''
     :param str root: the root path to search for included files
     :param bool recursive: True for recursive search
     :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 a list of included files.
     :rtype: [str]
     '''
     result = []
     try:
         result = self._cache_file_unique_includes[grpc_path]
     except KeyError:
         rospy.logdebug("get_included_files_set for %s, recursive: %s" % (grpc_path, recursive))
         uri, path = nmdurl.split(grpc_path, with_scheme=False)
         lm, channel = self.get_launch_manager(uri)
         url, path = nmdurl.split(grpc_path, with_scheme=True)
         reply = lm.get_included_files_set(path, recursive, {}, include_pattern, search_in_ext)
         for fname in reply:
             result.append(nmdurl.join(url, fname))
         self._cache_file_unique_includes[grpc_path] = result
         self.close_channel(channel, uri)
     return result
Пример #2
0
 def rename(self,
            grpc_path_old='grpc://localhost:12321',
            grpc_path_new='grpc://localhost:12321'):
     uri, old = nmdurl.split(grpc_path_old)
     _, new = nmdurl.split(grpc_path_new)
     rospy.logdebug("rename path on %s" % uri)
     fm = self.get_file_manager(uri)
     return fm.rename(old, new)
Пример #3
0
 def rename(self,
            grpc_path_old='grpc://localhost:12321',
            grpc_path_new='grpc://localhost:12321'):
     uri, old = nmdurl.split(grpc_path_old)
     _, new = nmdurl.split(grpc_path_new)
     rospy.logdebug("rename path on %s" % uri)
     fm, channel = self.get_file_manager(uri)
     result = fm.rename(old, new)
     self.close_channel(channel, uri)
     return result
Пример #4
0
 def get_package_binaries(self, pkgname, grpc_url='grpc://localhost:12321'):
     uri, _path = nmdurl.split(grpc_url)
     rospy.logdebug("get_package_binaries for '%s' from '%s'" %
                    (pkgname, uri))
     fm = self.get_file_manager(uri)
     response = fm.get_package_binaries(pkgname)
     url, _ = nmdurl.split(grpc_url, with_scheme=True)
     result = {}
     for item in response:
         result[nmdurl.join(url, item.path)] = item.mtime
     return result
Пример #5
0
 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)
Пример #6
0
 def _get_mtimes_threaded(self, grpc_path='grpc://localhost:12321'):
     uri, path = nmdurl.split(grpc_path)
     rospy.logdebug("[thread] get mtimes from %s" % uri)
     try:
         lm, channel = self.get_launch_manager(uri)
         rpath, mtime, included_files = lm.get_mtimes(path)
         url, _ = nmdurl.split(grpc_path, with_scheme=True)
         self.mtimes.emit(nmdurl.join(url, rpath), mtime, {nmdurl.join(url, pobj.path): pobj.mtime for pobj in included_files})
     except Exception:
         pass
     finally:
         self.close_channel(channel, uri)
     if hasattr(self, '_threads'):
         self._threads.finished("gmt_%s" % grpc_path)
Пример #7
0
 def get_interpreted_path(self, grpc_url_or_path='grpc://localhost:12321', text=[]):
     '''
     :param str grpc_url_or_path: the url for node manager daemon
     :param [str] text: list of string with text to interpret to a path
     :return: Returns an iterator for tuples with interpreted path and file exists or not
     :rtype: tuple(str, bool)
     '''
     uri, _ = nmdurl.split(grpc_url_or_path)
     lm, channel = self.get_launch_manager(uri)
     rospy.logdebug("get_interpreted_path in text %s" % text)
     reply = lm.get_interpreted_path(text)
     url, _ = nmdurl.split(grpc_url_or_path, with_scheme=True)
     for path, exists in reply:
         yield (nmdurl.join(url, path), exists)
     self.close_channel(channel, uri)
Пример #8
0
 def delete(self, grpc_path='grpc://*****:*****@ %s" % (path, uri))
     fm, channel = self.get_file_manager(uri)
     result = fm.delete(path)
     self.close_channel(channel, uri)
     return result
Пример #9
0
 def current_grpc(self):
     '''
     Current URL of the node manager daemon.
     :rtype: str
     '''
     netloc, _ = nmdurl.split(self._current_path, with_scheme=True)
     return netloc
Пример #10
0
 def get_screens(self, grpc_url='grpc://localhost:12321', node=''):
     rospy.logdebug("get screen from %s for %s" % (grpc_url, node))
     uri, _ = nmdurl.split(grpc_url)
     sm, channel = self.get_screen_manager(uri)
     screens = sm.screens(node)
     self.close_channel(channel, uri)
     return screens
Пример #11
0
 def get_all_screens(self, grpc_url='grpc://localhost:12321'):
     rospy.logdebug("get all screens from %s" % (grpc_url))
     uri, _ = nmdurl.split(grpc_url)
     sm, channel = self.get_screen_manager(uri)
     screens = sm.all_screens()
     self.close_channel(channel, uri)
     return screens
Пример #12
0
 def delete_log(self, grpc_url='grpc://localhost:12321', nodes=[]):
     rospy.logdebug("delete logs on %s for %s" % (grpc_url, nodes))
     uri, _ = nmdurl.split(grpc_url)
     sm, channel = self.get_screen_manager(uri)
     result = sm.delete_log(nodes)
     self.close_channel(channel, uri)
     return result
Пример #13
0
 def start_standalone_node(self, grpc_url, package, binary, name, ns, args=[], env={}, masteruri=None, host=None):
     rospy.loginfo("start standalone node: %s on %s" % (name, grpc_url))
     uri, _ = nmdurl.split(grpc_url)
     lm, channel = self.get_launch_manager(uri)
     try:
         startcfg = StartConfig(package, binary)
         startcfg.name = name
         startcfg.namespace = ns
         startcfg.fullname = rospy.names.ns_join(ns, name)
         startcfg.prefix = ''
         startcfg.cwd = ''
         startcfg.env = env
         startcfg.remaps = {}
         startcfg.params = {}
         startcfg.clear_params = []
         startcfg.args = args
         startcfg.masteruri = masteruri
         startcfg.host = host
         startcfg.loglevel = ''
         startcfg.logformat = ''
         startcfg.respawn = False
         startcfg.respawn_delay = 30
         startcfg.respawn_max = 0
         startcfg.respawn_min_runtime = 0
         return lm.start_standalone_node(startcfg)
     except grpc.RpcError as err:
         rospy.logdebug("remove connection %s" % uri)
         raise err
     except exceptions.BinarySelectionRequest as bsr:
         rospy.loginfo("Question while start node: %s" % bsr.error)
         binaries = bsr.choices
         raise BinarySelectionRequest(binaries, 'Needs binary selection')
     finally:
         self.close_channel(channel, uri)
Пример #14
0
 def get_file_content(self,
                      grpc_path='grpc://localhost:12321',
                      force=False):
     file_size, file_mtime, file_content = (0, 0, '')
     try:
         if force:
             del self._cache_file_content[grpc_path]
         file_size, file_mtime, file_content = self._cache_file_content[
             grpc_path]
     except KeyError:
         rospy.logdebug("get file content for %s:" % grpc_path)
         uri, path = nmdurl.split(grpc_path)
         fm, channel = self.get_file_manager(uri)
         try:
             file_size, file_mtime, file_content = fm.get_file_content(path)
             self._cache_file_content[grpc_path] = (file_size, file_mtime,
                                                    file_content)
         except Exception as e:
             self.error.emit("get_file_content", "grpc://%s" % uri,
                             grpc_path, e)
             raise e
         finally:
             self.close_channel(channel, uri)
     if hasattr(self, '_threads'):
         self._threads.finished("gfc_%s_%d" % (grpc_path, force))
     self.file_content.emit(grpc_path, file_size, file_mtime, file_content)
     return file_size, file_mtime, file_content
Пример #15
0
 def start_node(self,
                name,
                grpc_path='grpc://localhost:12321',
                masteruri='',
                reload_global_param=False,
                loglevel='',
                logformat='',
                opt_binary='',
                cmd_prefix=''):
     rospy.loginfo("start node: %s with %s" % (name, grpc_path))
     uri, opt_launch = nmdurl.split(grpc_path)
     lm, channel = self.get_launch_manager(uri)
     try:
         return lm.start_node(name,
                              opt_binary=opt_binary,
                              opt_launch=opt_launch,
                              loglevel=loglevel,
                              logformat=logformat,
                              masteruri=masteruri,
                              reload_global_param=reload_global_param,
                              cmd_prefix=cmd_prefix)
     except grpc.RpcError as gerr:
         rospy.logdebug("remove connection %s" % uri)
         raise gerr
     except exceptions.BinarySelectionRequest as bsr:
         rospy.loginfo("Question while start node: %s" % bsr.error)
         binaries = bsr.choices
         raise BinarySelectionRequest(binaries, 'Needs binary selection')
     except Exception as err:
         raise err
     finally:
         self.close_channel(channel, uri)
Пример #16
0
    def _list_path_threaded(self,
                            grpc_path='grpc://localhost:12321',
                            clear_cache=False):
        uri, path = nmdurl.split(grpc_path)
        rospy.logdebug("[thread] list path: %s, '%s'" % (uri, path))
        fm, channel = self.get_file_manager(uri)
        result = None
        try:
            if not clear_cache:
                result = self._cache_path[grpc_path]
            else:
                self._cache_path['']  # only to cause an exception
        except KeyError:
            try:
                result = fm.list_path(path)
                if uri not in self._cache_packages:
                    self.list_packages_threaded(grpc_path, clear_cache)
#                    self.get_loaded_files_threaded(grpc_path)
            except Exception as e:
                self.error.emit("list_path", "grpc://%s" % uri, path, e)
                # rospy.logwarn("LIST PATH: %s" % e)
        if result is not None:
            self._cache_path[grpc_path] = result
            self.listed_path.emit("grpc://%s" % uri, path, result)
        self.close_channel(channel, uri)
        if hasattr(self, '_threads'):
            self._threads.finished("lpt_%s" % grpc_path)
Пример #17
0
 def _list_packages(self,
                    grpc_url_or_path='grpc://localhost:12321',
                    clear_ros_cache=False):
     uri, path = nmdurl.split(grpc_url_or_path)
     grpc_url = "grpc://%s" % uri
     result = {}
     try:
         if not clear_ros_cache:
             result = self._cache_packages[grpc_url]
         else:
             self._cache_packages['']  # only to cause an exception
     except KeyError:
         rospy.logdebug("[thread] get packages %s" % grpc_url)
         fm, channel = self.get_file_manager(uri)
         try:
             result = fm.list_packages(clear_ros_cache)
             fixed_result = {
                 nmdurl.join(grpc_url, path): name
                 for path, name in result.items()
             }
             self._cache_packages[grpc_url] = fixed_result
             self.packages.emit(grpc_url, fixed_result)
             self.packages_available.emit(grpc_url)
         except Exception as err:
             self.error.emit("_list_packages", "grpc://%s" % uri, path, err)
         finally:
             self.close_channel(channel, uri)
     if hasattr(self, '_threads'):
         self._threads.finished("gmt_%s_%d" %
                                (grpc_url_or_path, clear_ros_cache))
Пример #18
0
 def copy(self,
          grpc_path='grpc://localhost:12321',
          grpc_dest='grpc://localhost:12321'):
     uri, path = nmdurl.split(grpc_path)
     rospy.logdebug("copy '%s' to '%s'" % (grpc_path, grpc_dest))
     fm = self.get_file_manager(uri)
     fm.copy(path, grpc_dest)
Пример #19
0
 def rosclean(self, grpc_url='grpc://localhost:12321'):
     rospy.logdebug("clear log directory on %s" % (grpc_url))
     uri, _ = nmdurl.split(grpc_url)
     sm, channel = self.get_screen_manager(uri)
     result = sm.rosclean()
     self.close_channel(channel, uri)
     return result
Пример #20
0
 def _add_history(self):
     for hitem in nm.settings().launch_history:
         if not hitem.startswith(os.path.sep):
             hitem_uri, _ = nmdurl.split(hitem, with_scheme=True)
             current_uri = nmdurl.nmduri(self._current_path)
             if nmdurl.equal_uri(hitem_uri, current_uri):
                 self._add_path(hitem, PathItem.RECENT_FILE, 0, 0,
                                os.path.basename(hitem))
Пример #21
0
 def kill_process(self, pid, grpc_url='grpc://localhost:12321'):
     rospy.logdebug("kill process %d on %s" % (pid, grpc_url))
     uri, _ = nmdurl.split(grpc_url)
     vm = self.get_monitor_manager(uri)
     try:
         vm.kill_process(pid)
     except Exception as e:
         self.error.emit("kill_process", "grpc://%s" % uri, "", e)
Пример #22
0
 def _check_for_changed_files_threaded(self, grpc_url, path_dict):
     rospy.logdebug(
         "[thread] check_for_changed_files_threaded: with %d files on %s" %
         (len(path_dict), grpc_url))
     uri, _path = nmdurl.split(grpc_url, with_scheme=False)
     fm = self.get_file_manager(uri)
     try:
         response = fm.changed_files(path_dict)
         for item in response:
             self.changed_file.emit(nmdurl.join(grpc_url, item.path),
                                    item.mtime)
     except Exception as e:
         self.error.emit("changed_files", "grpc://%s" % uri, "", e)
         # rospy.logwarn("check_for_changed_files_threaded: %s" % e)
     url, _path = nmdurl.split(grpc_url, with_scheme=True)
     if hasattr(self, '_threads'):
         self._threads.finished("cft_%s" % url)
Пример #23
0
    def expand_item(self, path, path_id, clear_cache=False):
        '''
        Returns for the given item and path the file path if this is a file. Otherwise the
        folder will be expanded and None will be returned.

        :param str path: the real path of the item
        :param int path_id: the id of the path
        :param bool clear_cache: clear cache before reload
        :return: path of the launch file or None
        :rtype: str
        :raise Exception: if no path to given item was found
        '''
        if path_id in [PathItem.NOTHING]:
            return None
        has_shift_mod = Qt.ShiftModifier & QApplication.keyboardModifiers()
        if path_id in [
                PathItem.LAUNCH_FILE, PathItem.CFG_FILE, PathItem.PROFILE,
                PathItem.FILE, PathItem.RECENT_FILE, PathItem.LAUNCH_FILE
        ]:
            if not has_shift_mod:
                return path
        root = self.invisibleRootItem()
        while root.rowCount():
            root.removeRow(0)
        self.pyqt_workaround.clear()
        if has_shift_mod:
            if path_id in [
                    PathItem.LAUNCH_FILE, PathItem.CFG_FILE, PathItem.PROFILE,
                    PathItem.FILE, PathItem.RECENT_FILE, PathItem.LAUNCH_FILE
            ]:
                self._current_path = os.path.dirname(path)
            else:
                self._current_path = nmdurl.nmduri()
        else:
            if path_id in [PathItem.ROOT]:
                surl, spath = nmdurl.split(path, with_scheme=True)
                if self._is_root(path) or spath in ['', os.path.sep]:
                    self._current_path = nmdurl.nmduri()
                elif self._is_ros_root(path):
                    self._current_path = surl
                else:
                    dir_path = os.path.dirname(spath)
                    self._current_path = nmdurl.join(surl, dir_path)
            elif self._current_path != path:
                self._current_path = path
        self._add_path(self._current_path, PathItem.ROOT, 0, 0, 'loading...')
        nm.nmd().file.list_path_threaded(self._current_path, clear_cache)
        # TODO: add functionality to go deep automatically
        #         else:
        #             key_mod = QApplication.keyboardModifiers()
        #             onestep = False
        #             if key_mod & Qt.ControlModifier:
        #                 onestep = True
        #             root_path, items = self._moveDown(path, onestep)
        #        self._setNewList((root_path, items))
        return None
Пример #24
0
 def _get_loaded_files_threaded(self, grpc_path='grpc://localhost:12321'):
     uri, path = nmdurl.split(grpc_path)
     rospy.logdebug("[thread] get loaded_files from %s" % uri)
     try:
         lm, channel = self.get_launch_manager(uri)
         result = lm.get_loaded_files()
         url, _ = nmdurl.split(grpc_path, with_scheme=True)
         for _package, path, args, _masteruri, _host in result:
             with self._args_lock:
                 gpath = nmdurl.join(url, path)
                 rospy.logdebug("[thread] add args for %s: %s" % (gpath, args))
                 self._launch_args[gpath] = args
     except Exception:
         import traceback
         print(traceback.format_exc())
     finally:
         self.close_channel(channel, uri)
     if hasattr(self, '_threads'):
         self._threads.finished("glft_%s" % grpc_path)
Пример #25
0
 def save_file(self, grpc_path, content, mtime):
     rospy.logdebug("save_file_content: %s" % grpc_path)
     uri, path = nmdurl.split(grpc_path)
     fm = self.get_file_manager(uri)
     result = fm.save_file_content(path, content, mtime)
     for ack in result:
         if ack.path == path and ack.mtime != 0:
             self.clear_cache(grpc_path)
             return ack.mtime
     return 0
Пример #26
0
 def new(self, grpc_path='grpc://*****:*****@ %s" % (path, uri))
     fm, channel = self.get_file_manager(uri)
     result = fm.new(path, path_type)
     self.close_channel(channel, uri)
     return result
Пример #27
0
 def get_start_cfg(self, name, grpc_path='grpc://localhost:12321', masteruri='', reload_global_param=False, loglevel='', logformat=''):
     rospy.logdebug("get start configuration for '%s' from %s" % (name, grpc_path))
     uri, _ = nmdurl.split(grpc_path)
     lm, channel = self.get_launch_manager(uri)
     try:
         return lm.get_start_cfg(name, loglevel=loglevel, logformat=logformat, masteruri=masteruri, reload_global_param=reload_global_param)
     except Exception as err:
         raise err
     finally:
         self.close_channel(channel, uri)
Пример #28
0
 def unload_launch(self, grpc_path, masteruri=''):
     rospy.logdebug("unload launch %s" % grpc_path)
     uri, path = nmdurl.split(grpc_path)
     lm, channel = self.get_launch_manager(uri)
     launch_file = lm.unload_launch(path, masteruri)
     with self._args_lock:
         if launch_file in self._launch_args:
             rospy.logdebug("delete args after unload %s" % launch_file)
             del self._launch_args[launch_file]
     self.close_channel(channel, uri)
     return launch_file
Пример #29
0
 def _multiple_screens(self, grpc_url='grpc://localhost:12321'):
     rospy.logdebug("get multiple screens from %s" % (grpc_url))
     try:
         uri, _ = nmdurl.split(grpc_url)
         sm = self.get_screen_manager(uri)
         result = sm.multiple_screens()
         self.multiple_screens.emit(grpc_url, result)
     except Exception as e:
         self.error.emit("get_multiple_screens", "grpc://%s" % uri, "", e)
     if hasattr(self, '_threads'):
         self._threads.finished("mst_%s" % grpc_url)
Пример #30
0
 def kill_process(self, pid, grpc_url='grpc://localhost:12321'):
     if pid is not None:
         rospy.logdebug("kill process %d on %s" % (pid, grpc_url))
         uri, _ = nmdurl.split(grpc_url)
         vm, channel = self.get_monitor_manager(uri)
         try:
             vm.kill_process(pid)
         except Exception as e:
             self.error.emit("kill_process", "grpc://%s" % uri, "", e)
         finally:
             self.close_channel(channel, uri)