本文整理汇总了Python中node_manager_fkie.is_local函数的典型用法代码示例。如果您正苦于以下问题:Python is_local函数的具体用法?Python is_local怎么用?Python is_local使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了is_local函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: updateMaster
def updateMaster(self, master):
'''
Updates the information of the ros master. If the ROS master not exists, it
will be added.
@param master: the ROS master to update
@type master: L{master_discovery_fkie.msg.ROSMaster}
'''
# remove master, if his name was changed but not the ROS master URI
root = self.invisibleRootItem()
for i in reversed(range(root.rowCount())):
masterItem = root.child(i)
if masterItem.master.uri == master.uri and masterItem.master.name != master.name:
root.removeRow(i)
break
# update or add a the item
root = self.invisibleRootItem()
doAddItem = True
for i in range(root.rowCount()):
masterItem = root.child(i)
if (masterItem == master.name):
# update item
masterItem.master = master
masterItem.updateMasterView(root)
doAddItem = False
break
elif (masterItem > master.name):
root.insertRow(i, MasterItem.getItemList(master, (nm.is_local(nm.nameres().getHostname(master.uri)))))
doAddItem = False
break
if doAddItem:
root.appendRow(MasterItem.getItemList(master, (nm.is_local(nm.nameres().getHostname(master.uri)))))
示例2: killScreens
def killScreens(cls, host, node, user=None, parent=None):
'''
Searches for the screen associated with the given node and kill this screens.
@param host: the host name or ip where the screen is running
@type host: C{str}
@param node: the name of the node those screen output to show
@type node: C{str}
@param parent: the parent widget to show a message box, if a user
input is required.
@type parent: L{PySide.QtGui.QWidget}
'''
if node is None or len(node) == 0:
return False
# get the available screens
screens = cls.getActiveScreens(host, cls.createSessionName(node), user=user) #user=user, pwd=pwd
if screens:
from PySide import QtGui
result = QtGui.QMessageBox.question(parent, "Kill SCREENs?", '\n'.join(screens), QtGui.QMessageBox.Ok | QtGui.QMessageBox.Cancel, QtGui.QMessageBox.Ok)
if result & QtGui.QMessageBox.Ok:
for s in screens:
pid, sep, name = s.partition('.')
if pid:
try:
nm.starter().kill(host, int(pid))
except:
import traceback
rospy.logwarn("Error while kill screen (PID: %s) on host '%s': %s", str(pid), str(host), str(traceback.format_exc()))
if nm.is_local(host):
ps = subprocess.Popen([cls.SCREEN, '-wipe'])
# wait for process to avoid 'defunct' processes
thread = threading.Thread(target=ps.wait)
thread.setDaemon(True)
thread.start()
else:
nm.ssh().ssh_exec(host, [cls.SCREEN, '-wipe'])
示例3: openLog
def openLog(cls, nodename, host):
'''
Opens the log file associated with the given node in a new terminal.
@param nodename: the name of the node (with name space)
@type nodename: C{str}
@param host: the host name or ip where the log file are
@type host: C{str}
@return: C{True}, if a log file was found
@rtype: C{bool}
@raise Exception: on errors while resolving host
@see: L{node_manager_fkie.is_local()}
'''
title_opt = ' '.join(['"LOG', nodename, 'on', host, '"'])
if nm.is_local(host):
found = False
screenLog = nm.screen().getScreenLogFile(node=nodename)
if os.path.isfile(screenLog):
cmd = nm.terminal_cmd([nm.LESS, screenLog], title_opt)
rospy.loginfo("open log: %s", cmd)
subprocess.Popen(shlex.split(cmd))
found = True
#open roslog file
roslog = nm.screen().getROSLogFile(nodename)
if os.path.isfile(roslog):
title_opt = title_opt.replace('LOG', 'ROSLOG')
cmd = nm.terminal_cmd([nm.LESS, roslog], title_opt)
rospy.loginfo("open ROS log: %s", cmd)
subprocess.Popen(shlex.split(cmd))
found = True
return found
else:
nm.ssh().ssh_x11_exec(host, [nm.STARTER_SCRIPT, '--show_screen_log', nodename], title_opt)
nm.ssh().ssh_x11_exec(host, [nm.STARTER_SCRIPT, '--show_ros_log', nodename], title_opt.replace('LOG', 'ROSLOG'))
return False
示例4: getActiveScreens
def getActiveScreens(cls, host, session='', user=None, pwd=None):
'''
Returns the list with all compatible screen names. If the session is set to
an empty string all screens will be returned.
@param host: the host name or IP to search for the screen session.
@type host: C{str}
@param session: the name or the suffix of the screen session
@type session: C{str} (Default: C{''})
@return: the list with session names
@rtype: C{[str(session name), ...]}
@raise Exception: on errors while resolving host
@see: L{node_manager_fkie.is_local()}
'''
output = None
result = []
if nm.is_local(host):
out, out_err = cls.getLocalOutput([cls.SCREEN, '-ls'])
output = out
else:
(stdin, stdout, stderr), ok = nm.ssh().ssh_exec(host, [cls.SCREEN, ' -ls'])
if ok:
stdin.close()
# error = stderr.read()
output = stdout.read()
if not (output is None):
splits = output.split()
for i in splits:
if i.count('.') > 0 and i.endswith(session):
result.append(i)
return result
示例5: _resolve_abs_paths
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, ''
示例6: killScreens
def killScreens(cls, node, host, auto_ok_request=True, user=None, pw=None):
'''
Searches for the screen associated with the given node and kill this screens.
@param node: the name of the node those screen output to show
@type node: C{str}
@param host: the host name or ip where the screen is running
@type host: C{str}
'''
if node is None or len(node) == 0:
return False
try:
# get the available screens
screens = cls._getActiveScreens(host, cls.createSessionName(node), auto_ok_request, user=user, pwd=pw) # user=user, pwd=pwd
if screens:
do_kill = True
if auto_ok_request:
from node_manager_fkie.detailed_msg_box import MessageBox
result = MessageBox.question(None, "Kill SCREENs?", '\n'.join(screens), buttons=MessageBox.Ok | MessageBox.Cancel)
if result == MessageBox.Ok:
do_kill = True
if do_kill:
for s in screens:
pid, _, _ = s.partition('.')
if pid:
try:
nm.starter()._kill_wo(host, int(pid), auto_ok_request, user, pw)
except:
import traceback
rospy.logwarn("Error while kill screen (PID: %s) on host '%s': %s", utf8(pid), utf8(host), traceback.format_exc(1))
if nm.is_local(host):
SupervisedPopen([cls.SCREEN, '-wipe'], object_id='screen -wipe', description="screen: clean up the socket with -wipe")
else:
nm.ssh().ssh_exec(host, [cls.SCREEN, '-wipe'], close_stdin=True, close_stdout=True, close_stderr=True)
except nm.AuthenticationRequest as e:
raise nm.InteractionNeededError(e, cls.killScreens, (node, host, auto_ok_request))
示例7: openScreenTerminal
def openScreenTerminal(cls, host, screen_name, nodename, user=None):
'''
Open the screen output in a new terminal.
@param host: the host name or ip where the screen is running.
@type host: C{str}
@param screen_name: the name of the screen to show
@type screen_name: C{str}
@param nodename: the name of the node is used for the title of the terminal
@type nodename: C{str}
@raise Exception: on errors while resolving host
@see: L{node_manager_fkie.is_local()}
'''
#create a title of the terminal
# pid, session_name = cls.splitSessionName(screen_name)
title_opt = ' '.join(['"SCREEN', nodename, 'on', host, '"'])
if nm.is_local(host):
cmd = nm.terminal_cmd([cls.SCREEN, '-x', screen_name], title_opt)
rospy.loginfo("Open screen terminal: %s", cmd)
ps = subprocess.Popen(shlex.split(cmd))
# wait for process to avoid 'defunct' processes
thread = threading.Thread(target=ps.wait)
thread.setDaemon(True)
thread.start()
else:
ps = nm.ssh().ssh_x11_exec(host, [cls.SCREEN, '-x', screen_name], title_opt)
rospy.loginfo("Open remote screen terminal: %s", ps)
# wait for process to avoid 'defunct' processes
thread = threading.Thread(target=ps.wait)
thread.setDaemon(True)
thread.start()
示例8: _resolve_abs_paths
def _resolve_abs_paths(cls, value, host):
'''
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)
dir = os.path.dirname(value) if os.path.isfile(value) else value
package, package_path = LaunchConfig.packageName(dir)
if package:
(stdin, stdout, stderr), ok = nm.ssh().ssh_exec(host, ['rospack', 'find', package])
if ok:
stdin.close()
output = stdout.read()
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, ''
示例9: updateTypeView
def updateTypeView(cls, service, item):
'''
Updates the representation of the column contains the type of the service.
@param service: the service data
@type service: L{master_discovery_fkie.ServiceInfo}
@param item: corresponding item in the model
@type item: L{ServiceItem}
'''
try:
if service.isLocal and service.type:
service_class = service.get_service_class(nm.is_local(nm.nameres().getHostname(service.uri)))
item.setText(service_class._type)
elif service.type:
item.setText(service.type)
else:
item.setText('unknown type')
# removed tooltip for clarity !!!
# tooltip = ''
# tooltip = ''.join([tooltip, '<h4>', service_class._type, '</h4>'])
# tooltip = ''.join([tooltip, '<b><u>', 'Request', ':</u></b>'])
# tooltip = ''.join([tooltip, '<dl><dt>', str(service_class._request_class.__slots__), '</dt></dl>'])
#
# tooltip = ''.join([tooltip, '<b><u>', 'Response', ':</u></b>'])
# tooltip = ''.join([tooltip, '<dl><dt>', str(service_class._response_class.__slots__), '</dt></dl>'])
#
# item.setToolTip(''.join(['<div>', tooltip, '</div>']))
item.setToolTip('')
except:
if not service.isLocal:
tooltip = ''.join(['<h4>', 'Service type is not available due to he running on another host.', '</h4>'])
item.setToolTip(''.join(['<div>', tooltip, '</div>']))
示例10: kill
def kill(self, host, pid):
'''
Kills the process with given process id on given host.
@param host: the name or address of the host, where the process must be killed.
@type host: C{str}
@param pid: the process id
@type pid: C{int}
@raise StartException: on error
@raise Exception: on errors while resolving host
@see: L{node_manager_fkie.is_local()}
'''
if nm.is_local(host):
import signal
os.kill(pid, signal.SIGKILL)
rospy.loginfo("kill: %s", str(pid))
else:
# kill on a remote machine
cmd = ['kill -9', str(pid)]
rospy.loginfo("kill remote on %s: %s", host, ' '.join(cmd))
(stdin, stdout, stderr), ok = nm.ssh().ssh_exec(host, cmd)
if ok:
stdin.close()
error = stderr.read()
if error:
rospy.logwarn("ERROR while kill %s: %s", str(pid), error)
raise nm.StartException(str(''.join(['The host "', host, '" reports:\n', error])))
output = stdout.read()
if output:
rospy.logdebug("STDOUT while kill %s on %s: %s", str(pid), host, output)
示例11: _getActiveScreens
def _getActiveScreens(cls, host, session='', auto_pw_request=True, user=None, pwd=None):
'''
Returns the list with all compatible screen names. If the session is set to
an empty string all screens will be returned.
@param host: the host name or IP to search for the screen session.
@type host: C{str}
@param session: the name or the suffix of the screen session
@type session: C{str} (Default: C{''})
@return: the list with session names
@rtype: C{[str(session name), ...]}
@raise Exception: on errors while resolving host
@see: L{node_manager_fkie.is_local()}
'''
output = None
result = []
if nm.is_local(host):
output = cls.getLocalOutput([cls.SCREEN, '-ls'])
else:
_, stdout, _, _ = nm.ssh().ssh_exec(host, [cls.SCREEN, ' -ls'], user, pwd, auto_pw_request, close_stdin=True, close_stderr=True)
output = stdout.read()
stdout.close()
if output:
splits = output.split()
for i in splits:
if i.count('.') > 0 and i.endswith(session) and i.find('._') >= 0:
result.append(i)
return result
示例12: load
def load(self, argv):
'''
@param argv: the list with argv parameter needed to load the launch file.
The name and value are separated by C{:=}
@type argv: C{[str]}
@return True, if the launch file was loaded
@rtype boolean
@raise LaunchConfigException: on load errors
'''
try:
roscfg = roslaunch.ROSLaunchConfig()
loader = roslaunch.XmlLoader()
self.argv = self.resolveArgs(argv)
loader.load(self.Filename, roscfg, verbose=False, argv=self.argv)
self.__roscfg = roscfg
nm.file_watcher().add_launch(self.__masteruri, self.__launchFile, self.__launch_id, self.getIncludedFiles(self.Filename))
if not nm.is_local(nm.nameres().getHostname(self.__masteruri)):
files = self.getIncludedFiles(self.Filename,
regexp_list=[QRegExp("\\bdefault\\b"),
QRegExp("\\bvalue=.*pkg:\/\/\\b"),
QRegExp("\\bvalue=.*package:\/\/\\b"),
QRegExp("\\bvalue=.*\$\(find\\b")])
nm.file_watcher_param().add_launch(self.__masteruri,
self.__launchFile,
self.__launch_id,
files)
except roslaunch.XmlParseException, e:
test = list(re.finditer(r"environment variable '\w+' is not set", str(e)))
message = str(e)
if test:
message = ''.join([message, '\n', 'environment substitution is not supported, use "arg" instead!'])
raise LaunchConfigException(message)
示例13: openLog
def openLog(cls, nodename, host, user=None):
'''
Opens the log file associated with the given node in a new terminal.
@param nodename: the name of the node (with name space)
@type nodename: C{str}
@param host: the host name or ip where the log file are
@type host: C{str}
@return: C{True}, if a log file was found
@rtype: C{bool}
@raise Exception: on errors while resolving host
@see: L{node_manager_fkie.is_local()}
'''
rospy.loginfo("show log for '%s' on '%s'", str(nodename), str(host))
title_opt = 'LOG %s on %s'%(nodename, host)
if nm.is_local(host):
found = False
screenLog = nm.screen().getScreenLogFile(node=nodename)
if os.path.isfile(screenLog):
cmd = nm.settings().terminal_cmd([nm.settings().log_viewer, screenLog], title_opt)
rospy.loginfo("open log: %s", cmd)
SupervisedPopen(shlex.split(cmd), id="Open log", description="Open log for '%s' on '%s'"%(str(nodename), str(host)))
found = True
#open roslog file
roslog = nm.screen().getROSLogFile(nodename)
if os.path.isfile(roslog):
title_opt = title_opt.replace('LOG', 'ROSLOG')
cmd = nm.settings().terminal_cmd([nm.settings().log_viewer, roslog], title_opt)
rospy.loginfo("open ROS log: %s", cmd)
SupervisedPopen(shlex.split(cmd), id="Open log", description="Open log for '%s' on '%s'"%(str(nodename), str(host)))
found = True
return found
else:
ps = nm.ssh().ssh_x11_exec(host, [nm.settings().start_remote_script, '--show_screen_log', nodename], title_opt, user)
ps = nm.ssh().ssh_x11_exec(host, [nm.settings().start_remote_script, '--show_ros_log', nodename], title_opt.replace('LOG', 'ROSLOG'), user)
return False
示例14: deleteLog
def deleteLog(cls, nodename, host, auto_pw_request=False, user=None, pw=None):
'''
Deletes the log file associated with the given node.
@param nodename: the name of the node (with name space)
@type nodename: C{str}
@param host: the host name or ip where the log file are to delete
@type host: C{str}
@raise Exception: on errors while resolving host
@see: L{node_manager_fkie.is_local()}
'''
rospy.loginfo("delete log for '%s' on '%s'", utf8(nodename), utf8(host))
if nm.is_local(host):
screenLog = nm.screen().getScreenLogFile(node=nodename)
pidFile = nm.screen().getScreenPidFile(node=nodename)
roslog = nm.screen().getROSLogFile(nodename)
if os.path.isfile(screenLog):
os.remove(screenLog)
if os.path.isfile(pidFile):
os.remove(pidFile)
if os.path.isfile(roslog):
os.remove(roslog)
else:
try:
# output ignored: output, error, ok
_, stdout, _, ok = nm.ssh().ssh_exec(host, [nm.settings().start_remote_script, '--delete_logs', nodename], user, pw, auto_pw_request, close_stdin=True, close_stdout=False, close_stderr=True)
if ok:
stdout.readlines()
stdout.close()
except nm.AuthenticationRequest as e:
raise nm.InteractionNeededError(e, cls.deleteLog, (nodename, host, auto_pw_request))
示例15: _poweroff_wo
def _poweroff_wo(self, host, auto_pw_request=False, user=None, pw=None):
if nm.is_local(host):
rospy.logwarn("shutdown localhost localhost!")
cmd = nm.settings().terminal_cmd(['sudo poweroff'], "poweroff")
SupervisedPopen(shlex.split(cmd), object_id="poweroff", description="poweroff")
else:
rospy.loginfo("poweroff %s", host)
# kill on a remote machine
cmd = ['sudo poweroff']
_ = nm.ssh().ssh_x11_exec(host, cmd, 'Shutdown %s' % host, user)