本文整理汇总了Python中node_manager_fkie.ssh函数的典型用法代码示例。如果您正苦于以下问题:Python ssh函数的具体用法?Python ssh怎么用?Python ssh使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ssh函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: 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'])
示例2: 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'", str(nodename), str(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
nm.ssh().ssh_exec(host, [nm.settings().start_remote_script, '--delete_logs', nodename], user, pw, auto_pw_request, close_stdin=True, close_stdout=True, close_stderr=True)
except nm.AuthenticationRequest as e:
raise nm.InteractionNeededError(e, cls.deleteLog, (nodename, host, auto_pw_request))
示例3: _on_display_anchorClicked
def _on_display_anchorClicked(self, url, user=None, pw=None):
try:
ok = False
if self.show_only_rate:
self.ssh_input_file, self.ssh_output_file, self.ssh_error_file, ok = nm.ssh().ssh_exec(url.host(), ['rostopic hz %s'%(self.topic)], user, pw, auto_pw_request=True, get_pty=True)
self.status_label.setText('connected to %s over SSH'%url.host())
else:
self.combobox_displ_hz.setEnabled(False)
nostr = '--nostr' if self.no_str_checkbox.isChecked() else ''
noarr = '--noarr' if self.no_arr_checkbox.isChecked() else ''
self.ssh_input_file, self.ssh_output_file, self.ssh_error_file, ok = nm.ssh().ssh_exec(url.host(), ['rostopic echo %s %s %s'%(nostr, noarr, self.topic)], user, pw, auto_pw_request=True, get_pty=True)
if ok:
self.display.clear()
target = self._read_output_hz if self.show_only_rate else self._read_output
thread = threading.Thread(target=target, args=((self.ssh_output_file,)))
thread.setDaemon(True)
thread.start()
thread = threading.Thread(target=self._read_error, args=((self.ssh_error_file,)))
thread.setDaemon(True)
thread.start()
elif self.ssh_output_file:
self.ssh_output_file.close()
self.ssh_error_file.close()
except Exception as e:
self._append_error_text('%s\n'%e)
示例4: 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
示例5: 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
示例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: 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
示例8: _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, ''
示例9: 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
示例10: 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()
示例11: 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)
示例12: _on_request_interact
def _on_request_interact(self, ident, descr, req):
'''
If the interaction of the user is needed a message dialog must be exceuted
in the main Qt thread. The requests are done by different request exceptinos.
These are handled by this method.
'''
if isinstance(req.request, nm.AuthenticationRequest):
res, user, pw = nm.ssh()._requestPW(req.request.user, req.request.host)
if not res:
self._on_progress_canceled()
return
pt = ProgressThread(ident, descr, req.method, (req.args+(user, pw)))
pt.finished_signal.connect(self._progress_thread_finished)
pt.error_signal.connect(self._progress_thread_error)
pt.request_interact_signal.connect(self._on_request_interact)
pt.start()
elif isinstance(req.request, nm.ScreenSelectionRequest):
from select_dialog import SelectDialog
items, _ = SelectDialog.getValue('Show screen', '', req.request.choices.keys(), False)
if not items:
self._progress_thread_finished(ident)
return
res = [req.request.choices[i] for i in items]
pt = ProgressThread(ident, descr, req.method, (req.args+(res,)))
pt.finished_signal.connect(self._progress_thread_finished)
pt.error_signal.connect(self._progress_thread_error)
pt.request_interact_signal.connect(self._on_request_interact)
pt.start()
elif isinstance(req.request, nm.BinarySelectionRequest):
from select_dialog import SelectDialog
items, _ = SelectDialog.getValue('Multiple executables', '', req.request.choices, True)
if not items:
self._progress_thread_finished(ident)
return
res = items[0]
pt = ProgressThread(ident, descr, req.method, (req.args+(res,)))
pt.finished_signal.connect(self._progress_thread_finished)
pt.error_signal.connect(self._progress_thread_error)
pt.request_interact_signal.connect(self._on_request_interact)
pt.start()
elif isinstance(req.request, nm.LaunchArgsSelectionRequest):
from parameter_dialog import ParameterDialog
inputDia = ParameterDialog(req.request.args_dict)
inputDia.setFilterVisible(False)
inputDia.setWindowTitle(''.join(['Enter the argv for ', req.request.launchfile]))
if inputDia.exec_():
params = inputDia.getKeywords()
argv = []
for p,v in params.items():
if v:
argv.append(''.join([p, ':=', v]))
res = argv
pt = ProgressThread(ident, descr, req.method, (req.args+(argv,)))
pt.finished_signal.connect(self._progress_thread_finished)
pt.error_signal.connect(self._progress_thread_error)
pt.request_interact_signal.connect(self._on_request_interact)
pt.start()
else:
self._progress_thread_finished(ident)
return
示例13: _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, ''
示例14: _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
示例15: _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)