本文整理汇总了Python中node_manager_fkie.is_local函数的典型用法代码示例。如果您正苦于以下问题:Python is_local函数的具体用法?Python is_local怎么用?Python is_local使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了is_local函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)))))
开发者ID:mjschuster,项目名称:multimaster_fkie,代码行数:33,代码来源:master_list_model.py
示例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'])
开发者ID:mjschuster,项目名称:multimaster_fkie,代码行数:35,代码来源:screen_handler.py
示例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
开发者ID:schneider42,项目名称:fkie-ros-pkg,代码行数:34,代码来源:start_handler.py
示例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
开发者ID:schneider42,项目名称:fkie-ros-pkg,代码行数:30,代码来源:screen_handler.py
示例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, ''
开发者ID:zhouchengming1,项目名称:multimaster_fkie,代码行数:28,代码来源:start_handler.py
示例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))
开发者ID:zhouchengming1,项目名称:multimaster_fkie,代码行数:35,代码来源:screen_handler.py
示例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()
开发者ID:markusachtelik,项目名称:multimaster_fkie,代码行数:30,代码来源:screen_handler.py
示例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, ''
开发者ID:mjschuster,项目名称:multimaster_fkie,代码行数:32,代码来源:start_handler.py
示例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>']))
开发者ID:fkie,项目名称:multimaster_fkie,代码行数:31,代码来源:service_list_model.py
示例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)
开发者ID:mjschuster,项目名称:multimaster_fkie,代码行数:29,代码来源:start_handler.py
示例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
开发者ID:jhu-lcsr-forks,项目名称:multimaster_fkie,代码行数:27,代码来源:screen_handler.py
示例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)
开发者ID:fkie,项目名称:multimaster_fkie,代码行数:32,代码来源:launch_config.py
示例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
开发者ID:jhu-lcsr-forks,项目名称:multimaster_fkie,代码行数:35,代码来源:start_handler.py
示例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))
开发者ID:zhouchengming1,项目名称:multimaster_fkie,代码行数:30,代码来源:start_handler.py
示例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)
开发者ID:zhouchengming1,项目名称:multimaster_fkie,代码行数:10,代码来源:start_handler.py
示例16: 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)
try:
del self.pyqt_workaround[masterItem.master.name]
except:
pass
break
# update or add a the item
root = self.invisibleRootItem()
doAddItem = True
for i in range(root.rowCount()):
masterItem = root.child(i, self.COL_NAME)
if (masterItem == master.name):
# update item
masterItem.master = master
masterItem.updateMasterView(root)
doAddItem = False
break
elif (masterItem > master.name):
mitem = MasterItem.getItemList(master, (nm.is_local(nm.nameres().getHostname(master.uri))))
self.pyqt_workaround[master.name] = mitem # workaround for using with PyQt: store the python object to keep the defined attributes in the MasterItem subclass
root.insertRow(i, mitem)
mitem[self.COL_NAME].parent_item = root
doAddItem = False
break
if doAddItem:
mitem = MasterItem.getItemList(master, (nm.is_local(nm.nameres().getHostname(master.uri))))
self.pyqt_workaround[master.name] = mitem # workaround for using with PyQt: store the python object to keep the defined attributes in the MasterItem subclass
root.appendRow(mitem)
mitem[self.COL_NAME].parent_item = root
开发者ID:jhu-lcsr-forks,项目名称:multimaster_fkie,代码行数:43,代码来源:master_list_model.py
示例17: _rosclean_wo
def _rosclean_wo(self, host, auto_pw_request=False, user=None, pw=None):
if nm.is_local(host):
rospy.loginfo("rosclean purge on localhost!")
cmd = nm.settings().terminal_cmd(['rosclean purge -y'], "rosclean")
SupervisedPopen(shlex.split(cmd), object_id="rosclean", description="rosclean")
else:
rospy.loginfo("rosclean %s", host)
# kill on a remote machine
cmd = ['rosclean purge -y']
_ = nm.ssh().ssh_x11_exec(host, cmd, 'rosclean purge on %s' % host, user)
开发者ID:zhouchengming1,项目名称:multimaster_fkie,代码行数:10,代码来源:start_handler.py
示例18: _prepareROSMaster
def _prepareROSMaster(cls, masteruri):
if masteruri is None:
masteruri = masteruri_from_ros()
# start roscore, if needed
try:
if not os.path.isdir(nm.ScreenHandler.LOG_PATH):
os.makedirs(nm.ScreenHandler.LOG_PATH)
socket.setdefaulttimeout(3)
master = xmlrpclib.ServerProxy(masteruri)
master.getUri(rospy.get_name())
# restart ROSCORE on different masteruri?, not now...
# master_uri = master.getUri(rospy.get_name())
# if masteruri != master_uri[2]:
# # kill the local roscore...
# raise
except:
# run a roscore
master_host = get_hostname(masteruri)
if nm.is_local(master_host, True):
master_port = get_port(masteruri)
new_env = dict(os.environ)
new_env['ROS_MASTER_URI'] = masteruri
ros_hostname = NameResolution.get_ros_hostname(masteruri)
if ros_hostname:
new_env['ROS_HOSTNAME'] = ros_hostname
cmd_args = '%s roscore --port %d' % (nm.ScreenHandler.getSceenCmd('/roscore--%d' % master_port), master_port)
for n in [1, 2, 3, 4]:
try:
if n == 1:
print("Launch ROS Master in screen ...")
SupervisedPopen(shlex.split(cmd_args), env=new_env, object_id="ROSCORE", description="Start roscore")
elif n == 2:
print("ROS Master takes too long for start, wait for next 10 sec ...")
elif n == 3:
print("A really slow start, wait for last 10 sec ...")
# wait for roscore to avoid connection problems while init_node
result = -1
count = 1
while result == -1 and count < 11:
try:
master = xmlrpclib.ServerProxy(masteruri)
result, _, _ = master.getUri(rospy.get_name()) # _:=uri, msg
return
except Exception:
time.sleep(1)
count += 1
if n == 4 and count >= 11:
raise StartException('Cannot connect to ROS-Master: %s\n--> please run "roscore" manually!' % utf8(masteruri))
except Exception as e:
raise Exception("Error while call '%s': %s" % (cmd_args, utf8(e)))
else:
raise Exception("ROS master '%s' is not reachable" % masteruri)
finally:
socket.setdefaulttimeout(None)
开发者ID:zhouchengming1,项目名称:multimaster_fkie,代码行数:54,代码来源:start_handler.py
示例19: _prepareROSMaster
def _prepareROSMaster(cls, masteruri):
if masteruri is None:
masteruri = masteruri_from_ros()
#start roscore, if needed
try:
if not os.path.isdir(nm.ScreenHandler.LOG_PATH):
os.makedirs(nm.ScreenHandler.LOG_PATH)
socket.setdefaulttimeout(3)
master = xmlrpclib.ServerProxy(masteruri)
master.getUri(rospy.get_name())
# restart ROSCORE on different masteruri?, not now...
# master_uri = master.getUri(rospy.get_name())
# if masteruri != master_uri[2]:
# # kill the local roscore...
# raise
except:
# socket.setdefaulttimeout(None)
# import traceback
# print traceback.format_exc(3)
# run a roscore
from urlparse import urlparse
master_host = urlparse(masteruri).hostname
if nm.is_local(master_host, True):
master_port = urlparse(masteruri).port
new_env = dict(os.environ)
new_env['ROS_MASTER_URI'] = masteruri
ros_hostname = NameResolution.get_ros_hostname(masteruri)
if ros_hostname:
new_env['ROS_HOSTNAME'] = ros_hostname
cmd_args = '%s roscore --port %d'%(nm.ScreenHandler.getSceenCmd('/roscore--%d'%master_port), master_port)
try:
SupervisedPopen(shlex.split(cmd_args), env=new_env, object_id="ROSCORE", description="Start roscore")
# wait for roscore to avoid connection problems while init_node
result = -1
count = 1
while result == -1 and count < 11:
try:
master = xmlrpclib.ServerProxy(masteruri)
result, _, _ = master.getUri(rospy.get_name())#_:=uri, msg
except:
time.sleep(1)
count += 1
if count >= 11:
raise StartException('Cannot connect to the ROS-Master: '+ str(masteruri))
except Exception as e:
import sys
print >> sys.stderr, e
raise
else:
raise Exception("ROS master '%s' is not reachable"%masteruri)
finally:
socket.setdefaulttimeout(None)
开发者ID:garyservin,项目名称:multimaster_fkie,代码行数:52,代码来源:start_handler.py
示例20: 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 = ' '.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)
ps = subprocess.Popen(shlex.split(cmd))
# wait for process to avoid 'defunct' processes
thread = threading.Thread(target=ps.wait)
thread.setDaemon(True)
thread.start()
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)
ps = subprocess.Popen(shlex.split(cmd))
# wait for process to avoid 'defunct' processes
thread = threading.Thread(target=ps.wait)
thread.setDaemon(True)
thread.start()
found = True
return found
else:
ps = nm.ssh().ssh_x11_exec(host, [nm.STARTER_SCRIPT, '--show_screen_log', nodename], title_opt, user)
# wait for process to avoid 'defunct' processes
thread = threading.Thread(target=ps.wait)
thread.setDaemon(True)
thread.start()
ps = nm.ssh().ssh_x11_exec(host, [nm.STARTER_SCRIPT, '--show_ros_log', nodename], title_opt.replace('LOG', 'ROSLOG'), user)
# wait for process to avoid 'defunct' processes
thread = threading.Thread(target=ps.wait)
thread.setDaemon(True)
thread.start()
return False
开发者ID:awesomebytes,项目名称:multimaster_fkie,代码行数:51,代码来源:start_handler.py
注:本文中的node_manager_fkie.is_local函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论