def _remove_search_result(self, index):
        try:
            (id, search_text, found, path, index, linenr,
             line) = self.search_results.pop(index)
            pkg, rpath = package_name(os.path.dirname(path))
            itemstr = '%s [%s]' % (os.path.basename(path), pkg)
            found_items = self.found_files_list.findItems(
                itemstr, Qt.MatchExactly)
            for item in found_items:
                for chi in range(item.childCount()):
                    child = item.child(chi)
                    if child.whatsThis(0) == id:
                        item.removeChild(child)
                        break
            # delete top level item if it is now empty
            for topidx in range(self.found_files_list.topLevelItemCount()):
                if self.found_files_list.topLevelItem(
                        topidx).childCount() == 0:
                    self.found_files_list.takeTopLevelItem(topidx)
                    break
            # create new set with files contain the search text
            new_path_set = set(path for _id, _st, _fd, path, _idx, lnr, lntxt
                               in self.search_results)
            self.search_results_fileset = new_path_set
#            self.found_files_list.setVisible(len(self.search_results_fileset) > 0)
        except:
            import traceback
            print traceback.format_exc()
 def _resolve_abs_paths(cls, value, host, user, pw, auto_pw_request):
     '''
     Replaces the local absolute path by remote absolute path. Only valid ROS
     package paths are resolved.
     @return: value, is absolute path, remote package found (ignore it on local host or if is not absolute path!), package name (if absolute path and remote package NOT found)
     '''
     if isinstance(value, types.StringTypes) and value.startswith('/') and (os.path.isfile(value) or os.path.isdir(value)):
         if nm.is_local(host):
             return value, True, True, ''
         else:
             path = os.path.dirname(value) if os.path.isfile(value) else value
             package, package_path = package_name(path)
             if package:
                 _, stdout, _, ok = nm.ssh().ssh_exec(host, ['rospack', 'find', package], user, pw, auto_pw_request, close_stdin=True, close_stderr=True)
                 output = stdout.read()
                 stdout.close()
                 if ok:
                     if output:
                         value.replace(package_path, output)
                         return value.replace(package_path, output.strip()), True, True, package
                     else:
                         # package on remote host not found!
                         # TODO add error message
                         #      error = stderr.read()
                         pass
             return value, True, False, ''
     else:
         return value, False, False, ''
Exemple #3
0
 def dropEvent(self, e):
     cursor = self.cursorForPosition(e.pos())
     if not cursor.isNull():
         text = e.mimeData().text()
         # the files will be included
         if text.startswith('file://'):
             text = text[7:]
         if os.path.exists(text) and os.path.isfile(text):
             # find the package name containing the included file
             (package, path) = package_name(os.path.dirname(text))
             if text.endswith('.launch'):
                 if package:
                     cursor.insertText('<include file="$(find %s)%s" />' %
                                       (package, text.replace(path, '')))
                 else:
                     cursor.insertText('<include file="%s" />' % text)
             else:
                 if package:
                     cursor.insertText(
                         '<rosparam file="$(find %s)%s" command="load" />' %
                         (package, text.replace(path, '')))
                 else:
                     cursor.insertText(
                         '<rosparam file="%s" command="load" />' % text)
         else:
             cursor.insertText(e.mimeData().text())
     e.accept()
 def _resolve_abs_paths(cls, value, host, user, pw, auto_pw_request):
     '''
     Replaces the local absolute path by remote absolute path. Only valid ROS
     package paths are resolved.
     @return: value, is absolute path, remote package found (ignore it on local host or if is not absolute path!), package name (if absolute path and remote package NOT found)
     '''
     if isinstance(value, types.StringTypes) and value.startswith('/') and (os.path.isfile(value) or os.path.isdir(value)):
         if nm.is_local(host):
             return value, True, True, ''
         else:
             path = os.path.dirname(value) if os.path.isfile(value) else value
             package, package_path = package_name(path)
             if package:
                 _, stdout, _, ok = nm.ssh().ssh_exec(host, ['rospack', 'find', package], user, pw, auto_pw_request, close_stdin=True, close_stderr=True)
                 output = stdout.read()
                 stdout.close()
                 if ok:
                     if output:
                         value.replace(package_path, output)
                         return value.replace(package_path, output.strip()), True, True, package
                     else:
                         # package on remote host not found!
                         # TODO add error message
                         #      error = stderr.read()
                         pass
             return value, True, False, ''
     else:
         return value, False, False, ''
 def _refill_tree(self, included_from, includes, create_tree=True):
     deep = 0
     file_dsrc = self._root_path
     try:
         file_dsrc = os.path.basename(self._root_path)
     except Exception:
         pass
     self.setWindowTitle("Include Graph - %s" % file_dsrc)
     if not self._created_tree and create_tree:
         with CHACHE_MUTEX:
             if self._root_path in GRAPH_CACHE:
                 pkg, _ = package_name(os.path.dirname(self._root_path))
                 itemstr = '%s [%s]' % (os.path.basename(self._root_path), pkg)
                 inc_item = QStandardItem('%s' % itemstr)
                 inc_item.setData(self._root_path, self.DATA_FILE)
                 inc_item.setData(-1, self.DATA_LINE)
                 inc_item.setData(self._root_path, self.DATA_INC_FILE)
                 inc_item.setData(deep, self.DATA_LEVEL)
                 self._append_items(inc_item, deep + 1)
                 self.graphTreeView.model().appendRow(inc_item)
                 # self.graphTreeView.expand(self.graphTreeView.model().indexFromItem(inc_item))
             self._created_tree = True
     items = self.graphTreeView.model().match(self.graphTreeView.model().index(0, 0), self.DATA_INC_FILE, self._current_path, 10, Qt.MatchRecursive)
     first = True
     self.graphTreeView.selectionModel().clearSelection()
     for item in items:
         if first:
             self._current_deep = item.data(self.DATA_LEVEL)
             self.graphTreeView.selectionModel().select(item, QItemSelectionModel.SelectCurrent)
             first = False
         else:
             self.graphTreeView.selectionModel().select(item, QItemSelectionModel.Select)
     self.graphTreeView.expandAll()
 def on_search_result(self, search_text, found, path, index, linenr, line):
     '''
     Slot to handle the signals for search result. This signals are forwarded used
     search_result_signal.
     '''
     if found and search_text == self.current_search_text:
         id = "%d:%s" % (index, path)
         self.search_results_fileset.add(path)
         item = (search_text, found, path, index)
         if item not in self.search_results:
             self.search_results.append((id, search_text, found, path, index, linenr, line))
         if self._wait_for_result:
             self._search_result_index += 1
             if index >= self._tabwidget.currentWidget().textCursor().position() or self._tabwidget.currentWidget().filename != path:
                 self._wait_for_result = False
                 self.search_result_signal.emit(search_text, found, path, index)
                 self.replace_button.setEnabled(True)
         pkg, rpath = package_name(os.path.dirname(path))
         itemstr = '%s [%s]' % (os.path.basename(path), pkg)
         if not self.found_files_list.findItems(itemstr, Qt.MatchExactly):
             list_item = QTreeWidgetItem(self.found_files_list)
             list_item.setText(0, itemstr)
             list_item.setToolTip(0, path)
             self.found_files_list.insertTopLevelItem(0, list_item)
             self.found_files_list.expandAll()
         for i in range(self.found_files_list.topLevelItemCount()):
             top_item = self.found_files_list.topLevelItem(i)
             if top_item.text(0) == itemstr:
                 sub_item_str = "%d: %s" % (linenr, line)
                 list_item2 = QTreeWidgetItem()
                 list_item2.setText(0, sub_item_str)
                 list_item2.setWhatsThis(0, id)
                 top_item.addChild(list_item2)
             #self.found_files_list.setVisible(len(self.search_results_fileset) > 0)
     self._update_label()
 def on_search_result(self, search_text, found, path, index):
     '''
     Slot to handle the signals for search result. This signals are forwarded used
     search_result_signal.
     '''
     if found and search_text == self.current_search_text:
         self.search_results_fileset.add(path)
         item = (search_text, found, path, index)
         if item not in self.search_results:
             self.search_results.append((search_text, found, path, index))
         if self._wait_for_result:
             self._search_result_index += 1
             if index >= self._tabwidget.currentWidget().textCursor(
             ).position() or self._tabwidget.currentWidget(
             ).filename != path:
                 self._wait_for_result = False
                 self.search_result_signal.emit(
                     *self.search_results[self._search_result_index])
                 self.replace_button.setEnabled(True)
     if self.search_results:
         if len(self.search_results_fileset) > 1:
             for item in self.search_results_fileset:
                 pkg, path = package_name(os.path.dirname(item))
                 itemstr = '%s [%s]' % (os.path.basename(item), pkg)
                 if not self.found_files_list.findItems(
                         itemstr, Qt.MatchExactly):
                     list_item = QListWidgetItem(itemstr)
                     list_item.setToolTip(item)
                     self.found_files_list.addItem(list_item)
                     self.found_files_frame.setVisible(True)
                     self.found_files_list.setVisible(
                         len(self.search_results_fileset) > 0)
     self._update_label()
 def _append_items(self, item, deep):
     path = item.data(self.DATA_INC_FILE)
     if not path:
         path = item.data(self.DATA_FILE)
     if path in GRAPH_CACHE:
         for inc_lnr, inc_path in GRAPH_CACHE[path]:
             pkg, _ = package_name(os.path.dirname(inc_path))
             itemstr = '%s [%s]' % (os.path.basename(inc_path), pkg)
             inc_item = QStandardItem('%d: %s' % (inc_lnr + 1, itemstr))
             inc_item.setData(path, self.DATA_FILE)
             inc_item.setData(inc_lnr + 1, self.DATA_LINE)
             inc_item.setData(inc_path, self.DATA_INC_FILE)
             inc_item.setData(deep, self.DATA_LEVEL)
             self._append_items(inc_item, deep + 1)
             item.appendRow(inc_item)
Exemple #9
0
 def _append_items(self, item, deep):
     path = item.data(self.DATA_INC_FILE)
     if not path:
         path = item.data(self.DATA_FILE)
     if path in GRAPH_CACHE:
         for inc_lnr, inc_path in GRAPH_CACHE[path]:
             pkg, _ = package_name(os.path.dirname(inc_path))
             itemstr = '%s [%s]' % (os.path.basename(inc_path), pkg)
             inc_item = QStandardItem('%d: %s' % (inc_lnr + 1, itemstr))
             inc_item.setData(path, self.DATA_FILE)
             inc_item.setData(inc_lnr + 1, self.DATA_LINE)
             inc_item.setData(inc_path, self.DATA_INC_FILE)
             inc_item.setData(deep, self.DATA_LEVEL)
             self._append_items(inc_item, deep + 1)
             item.appendRow(inc_item)
 def transfer_files(cls, host, path, auto_pw_request=False, user=None, pw=None):
     '''
     Copies the given file to the remote host. Uses caching of remote paths.
     '''
     # get package of the file
     if nm.is_local(host):
         # it's local -> no copy needed
         return
     (pkg_name, pkg_path) = package_name(os.path.dirname(path))
     if pkg_name is not None:
         # get the subpath of the file
         subfile_path = path.replace(pkg_path, '')
         # get the path of the package on the remote machine
         try:
             output = ''
             error = ''
             ok = True
             if host in CACHED_PKG_PATH and pkg_name in CACHED_PKG_PATH[host]:
                 output = CACHED_PKG_PATH[host][pkg_name]
             else:
                 if host not in CACHED_PKG_PATH:
                     CACHED_PKG_PATH[host] = dict()
                 _, stdout, stderr, ok = nm.ssh().ssh_exec(host, [nm.settings().start_remote_script, '--package', pkg_name], user, pw, auto_pw_request, close_stdin=True)
                 output = stdout.read()
                 error = stderr.read()
                 stdout.close()
                 stderr.close()
             if ok:
                 if error:
                     rospy.logwarn("ERROR while transfer %s to %s: %s", path, host, error)
                     raise StartException(utf8(''.join(['The host "', host, '" reports:\n', error])))
                 if output:
                     CACHED_PKG_PATH[host][pkg_name] = output
                     nm.ssh().transfer(host, path, os.path.join(output.strip(), subfile_path.strip(os.sep)), user)
                 else:
                     raise StartException("Remote host no returned any answer. Is there the new version of node_manager installed?")
             else:
                 raise StartException("Can't get path from remote host. Is there the new version of node_manager installed?")
         except nm.AuthenticationRequest as e:
             raise nm.InteractionNeededError(e, cls.transfer_files, (host, path, auto_pw_request))
 def transfer_files(cls, host, path, auto_pw_request=False, user=None, pw=None):
     '''
     Copies the given file to the remote host. Uses caching of remote paths.
     '''
     # get package of the file
     if nm.is_local(host):
         # it's local -> no copy needed
         return
     (pkg_name, pkg_path) = package_name(os.path.dirname(path))
     if pkg_name is not None:
         # get the subpath of the file
         subfile_path = path.replace(pkg_path, '')
         # get the path of the package on the remote machine
         try:
             output = ''
             error = ''
             ok = True
             if host in CACHED_PKG_PATH and pkg_name in CACHED_PKG_PATH[host]:
                 output = CACHED_PKG_PATH[host][pkg_name]
             else:
                 if host not in CACHED_PKG_PATH:
                     CACHED_PKG_PATH[host] = dict()
                 _, stdout, stderr, ok = nm.ssh().ssh_exec(host, [nm.settings().start_remote_script, '--package', pkg_name], user, pw, auto_pw_request, close_stdin=True)
                 output = stdout.read()
                 error = stderr.read()
                 stdout.close()
                 stderr.close()
             if ok:
                 if error:
                     rospy.logwarn("ERROR while transfer %s to %s: %s", path, host, error)
                     raise StartException(str(''.join(['The host "', host, '" reports:\n', error])))
                 if output:
                     CACHED_PKG_PATH[host][pkg_name] = output
                     nm.ssh().transfer(host, path, os.path.join(output.strip(), subfile_path.strip(os.sep)), user)
                 else:
                     raise StartException("Remote host no returned any answer. Is there the new version of node_manager installed?")
             else:
                 raise StartException("Can't get path from remote host. Is there the new version of node_manager installed?")
         except nm.AuthenticationRequest as e:
             raise nm.InteractionNeededError(e, cls.transfer_files, (host, path, auto_pw_request))
 def on_search_result(self, search_text, found, path, index, linenr, line):
     '''
     Slot to handle the signals for search result. This signals are forwarded used
     search_result_signal.
     '''
     if found and search_text == self.current_search_text:
         id = "%d:%s" % (index, path)
         self.search_results_fileset.add(path)
         item = (search_text, found, path, index)
         if item not in self.search_results:
             self.search_results.append(
                 (id, search_text, found, path, index, linenr, line))
         if self._wait_for_result:
             self._search_result_index += 1
             if index >= self._tabwidget.currentWidget().textCursor(
             ).position() or self._tabwidget.currentWidget(
             ).filename != path:
                 self._wait_for_result = False
                 self.search_result_signal.emit(search_text, found, path,
                                                index)
                 self.replace_button.setEnabled(True)
         pkg, rpath = package_name(os.path.dirname(path))
         itemstr = '%s [%s]' % (os.path.basename(path), pkg)
         if not self.found_files_list.findItems(itemstr, Qt.MatchExactly):
             list_item = QTreeWidgetItem(self.found_files_list)
             list_item.setText(0, itemstr)
             list_item.setToolTip(0, path)
             self.found_files_list.insertTopLevelItem(0, list_item)
             self.found_files_list.expandAll()
         for i in range(self.found_files_list.topLevelItemCount()):
             top_item = self.found_files_list.topLevelItem(i)
             if top_item.text(0) == itemstr:
                 sub_item_str = "%d: %s" % (linenr, line)
                 list_item2 = QTreeWidgetItem()
                 list_item2.setText(0, sub_item_str)
                 list_item2.setWhatsThis(0, id)
                 top_item.addChild(list_item2)
             #self.found_files_list.setVisible(len(self.search_results_fileset) > 0)
     self._update_label()
Exemple #13
0
 def _refill_tree(self, included_from, includes, create_tree=True):
     deep = 0
     file_dsrc = self._root_path
     try:
         file_dsrc = os.path.basename(self._root_path)
     except Exception:
         pass
     self.setWindowTitle("Include Graph - %s" % file_dsrc)
     if not self._created_tree and create_tree:
         with CHACHE_MUTEX:
             if self._root_path in GRAPH_CACHE:
                 pkg, _ = package_name(os.path.dirname(self._root_path))
                 itemstr = '%s [%s]' % (os.path.basename(
                     self._root_path), pkg)
                 inc_item = QStandardItem('%s' % itemstr)
                 inc_item.setData(self._root_path, self.DATA_FILE)
                 inc_item.setData(-1, self.DATA_LINE)
                 inc_item.setData(self._root_path, self.DATA_INC_FILE)
                 inc_item.setData(deep, self.DATA_LEVEL)
                 self._append_items(inc_item, deep + 1)
                 self.graphTreeView.model().appendRow(inc_item)
                 # self.graphTreeView.expand(self.graphTreeView.model().indexFromItem(inc_item))
             self._created_tree = True
     items = self.graphTreeView.model().match(
         self.graphTreeView.model().index(0, 0), self.DATA_INC_FILE,
         self._current_path, 10, Qt.MatchRecursive)
     first = True
     self.graphTreeView.selectionModel().clearSelection()
     for item in items:
         if first:
             self._current_deep = item.data(self.DATA_LEVEL)
             self.graphTreeView.selectionModel().select(
                 item, QItemSelectionModel.SelectCurrent)
             first = False
         else:
             self.graphTreeView.selectionModel().select(
                 item, QItemSelectionModel.Select)
     self.graphTreeView.expandAll()
 def dropEvent(self, e):
     cursor = self.cursorForPosition(e.pos())
     if not cursor.isNull():
         text = e.mimeData().text()
         # the files will be included
         if text.startswith('file://'):
             text = text[7:]
         if os.path.exists(text) and os.path.isfile(text):
             # find the package name containing the included file
             (package, path) = package_name(os.path.dirname(text))
             if text.endswith('.launch'):
                 if package:
                     cursor.insertText('<include file="$(find %s)%s" />' % (package, text.replace(path, '')))
                 else:
                     cursor.insertText('<include file="%s" />' % text)
             else:
                 if package:
                     cursor.insertText('<rosparam file="$(find %s)%s" command="load" />' % (package, text.replace(path, '')))
                 else:
                     cursor.insertText('<rosparam file="%s" command="load" />' % text)
         else:
             cursor.insertText(e.mimeData().text())
     e.accept()
    def _remove_search_result(self, index):
        try:
            (id, search_text, found, path, index, linenr, line) = self.search_results.pop(index)
            pkg, rpath = package_name(os.path.dirname(path))
            itemstr = '%s [%s]' % (os.path.basename(path), pkg)
            found_items = self.found_files_list.findItems(itemstr, Qt.MatchExactly)
            for item in found_items:
                for chi in range(item.childCount()):
                    child = item.child(chi)
                    if child.whatsThis(0) == id:
                        item.removeChild(child)
                        break
            # delete top level item if it is now empty
            for topidx in range(self.found_files_list.topLevelItemCount()):
                if self.found_files_list.topLevelItem(topidx).childCount() == 0:
                    self.found_files_list.takeTopLevelItem(topidx)
                    break
            # create new set with files contain the search text
            new_path_set = set(path for _id, _st, _fd, path, _idx, lnr, lntxt in self.search_results)
            self.search_results_fileset = new_path_set
#            self.found_files_list.setVisible(len(self.search_results_fileset) > 0)
        except:
            import traceback
            print traceback.format_exc()
Exemple #16
0
 def __getTabName(self, lfile):
     base = os.path.basename(lfile).replace('.launch', '')
     (package, _) = package_name(os.path.dirname(lfile))
     return '%s [%s]' % (base, package)
Exemple #17
0
 def __getTabName(self, lfile):
     base = os.path.basename(lfile).replace('.launch', '')
     (package, _) = package_name(os.path.dirname(lfile))
     return '%s [%s]' % (base, package)