def data(self, index, role=QtCore.Qt.DisplayRole): ''' The view asks us for all sorts of information about our data... @param index: parent of the list @type index: L{QtCore.QModelIndex} @param role: the art of the data @type role: L{QtCore.Qt.DisplayRole} @see: U{http://www.pyside.org/docs/pyside-1.0.1/PySide/QtCore/Qt.html} ''' if role == QtCore.Qt.DisplayRole: # return the displayed item name pathItem, path, pathId = self.items[index.row()] if pathId == LaunchListModel.RECENT_FILE: return ''.join([pathItem, ' [', str(package_name(os.path.dirname(path))[0]), ']']).decode(sys.getfilesystemencoding()) else: return pathItem elif role == QtCore.Qt.ToolTipRole: # return the tooltip of the item pathItem, path, pathId = self.items[index.row()] return path elif role == QtCore.Qt.DecorationRole: # return the showed icon pathItem, path, pathId = self.items[index.row()] if pathId > LaunchListModel.NOTHING and self.icons.has_key(pathId): return self.icons[pathId] return None else: # We don't care about anything else, so return None return None
def __init__(self, launch_file, package=None, masteruri=None, argv=[]): ''' Creates the LaunchConfig object. The launch file will be not loaded on creation, first on request of Roscfg value. @param launch_file: The absolute or relative path with the launch file. By using relative path a package must be valid for remote launches. @type launch_file: C{str} @param package: the package containing the launch file. If None the launch_file will be used to determine the launch file. No remote launches a possible without a valid package. @type package: C{str} or C{None} @param masteruri: The URL of the ROS master. @type masteruri: C{str} or C{None} @param argv: the list the arguments needed for loading the given launch file @type argv: C{[str]} @raise roslaunch.XmlParseException: if the launch file can't be found. ''' QtCore.QObject.__init__(self) self.__launchFile = launch_file self.__package = package_name(os.path.dirname(self.__launchFile))[0] if package is None else package self.__masteruri = masteruri if not masteruri is None else 'localhost' self.__roscfg = None self.argv = argv self.__reqTested = False self.global_param_done = [] # masteruri's where the global parameters are registered self.hostname = nm.nameres().getHostname(self.__masteruri) self.file_watcher = QtCore.QFileSystemWatcher() self.file_watcher.fileChanged.connect(self.on_file_changed) self.changed = {}
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: # print "ABS PATH:", value, os.path.dirname(value), host 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: # print " RESOLVED:", output # print " PACK_PATH:", package_path value.replace(package_path, output) # print " RENAMED:", value.replace(package_path, output.strip()) 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 __init__(self, launch_file, package=None, masteruri=None, argv=[]): ''' Creates the LaunchConfig object. The launch file will be not loaded on creation, first on request of Roscfg value. @param launch_file: The absolute or relative path with the launch file. By using relative path a package must be valid for remote launches. @type launch_file: C{str} @param package: the package containing the launch file. If None the launch_file will be used to determine the launch file. No remote launches a possible without a valid package. @type package: C{str} or C{None} @param masteruri: The URL of the ROS master. @type masteruri: C{str} or C{None} @param argv: the list the arguments needed for loading the given launch file @type argv: C{[str]} @raise roslaunch.XmlParseException: if the launch file can't be found. ''' QtCore.QObject.__init__(self) self.__launchFile = launch_file self.__package = package_name(os.path.dirname( self.__launchFile))[0] if package is None else package self.__masteruri = masteruri if not masteruri is None else 'localhost' self.__roscfg = None self.argv = argv self.__reqTested = False self.__argv_values = dict() self.global_param_done = [ ] # masteruri's where the global parameters are registered self.hostname = nm.nameres().getHostname(self.__masteruri) self.__launch_id = '%.9f' % time.time() nm.file_watcher().add_launch(self.__masteruri, self.__launchFile, self.__launch_id, [self.__launchFile])
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: # print "ABS PATH:", value, os.path.dirname(value), host path = os.path.dirname(value) if os.path.isfile(value) else value package, package_path = package_name(path) if package: output, _, ok = nm.ssh().ssh_exec(host, ['rospack', 'find', package], user, pw, auto_pw_request) if ok: if output: # print " RESOLVED:", output # print " PACK_PATH:", package_path value.replace(package_path, output) # print " RENAMED:", value.replace(package_path, output.strip()) 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 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 not pkg_name is 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 CACHED_PKG_PATH.has_key(host) and CACHED_PKG_PATH[host].has_key(pkg_name): output = CACHED_PKG_PATH[host][pkg_name] else: if not CACHED_PKG_PATH.has_key(host): 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 __init__(self, name, path, id, parent=None): ''' Initialize the topic item. @param name: the topic name @type name: C{str} ''' QtGui.QStandardItem.__init__(self, name) self.parent_item = parent self.name = name self.path = path self.package_name = package_name(os.path.dirname(self.path))[0] self.id = id if self.id == LaunchItem.FOLDER: self.setIcon(QtGui.QIcon(":/icons/crystal_clear_folder.png")) elif self.id == LaunchItem.PACKAGE: self.setIcon(QtGui.QIcon(":/icons/crystal_clear_package.png")) elif self.id == LaunchItem.LAUNCH_FILE: self.setIcon(QtGui.QIcon(":/icons/crystal_clear_launch_file.png")) elif self.id == LaunchItem.RECENT_FILE: self.setIcon(QtGui.QIcon(":/icons/crystal_clear_launch_file_recent.png")) elif self.id == LaunchItem.STACK: self.setIcon(QtGui.QIcon(":/icons/crystal_clear_stack.png"))
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 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 not pkg_name is 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 CACHED_PKG_PATH.has_key(host) and CACHED_PKG_PATH[host].has_key(pkg_name): output = CACHED_PKG_PATH[host][pkg_name] else: if not CACHED_PKG_PATH.has_key(host): CACHED_PKG_PATH[host] = dict() output, error, ok = nm.ssh().ssh_exec(host, [nm.settings().start_remote_script, '--package', pkg_name], user, pw, auto_pw_request) 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 __getTabName(self, lfile): base = os.path.basename(lfile).replace('.launch', '') (package, _) = package_name(os.path.dirname(lfile)) return ''.join([str(base), ' [', str(package),']'])