Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Inputs:
command -- command string to be executed
host -- hostname of execution target [default = None (i.e. run locally)]
bg -- run as background process? [default = True]
'''
#XXX: options, background, stdin can be set w/ kwds (also name, launcher)
bg = bool(bg) # overrides 'background'
if host in [None, '']:
from pathos.connection import Pipe
launcher = Pipe(**kwds)
launcher(command=command, background=bg)
else:
from pathos.secure import Pipe
opt = kwds.pop('options', '-q')
launcher = Pipe(**kwds)
launcher(options=opt, command=command, host=host, background=bg)
pathos.logger().info('executing {%s}', launcher.message)
launcher.launch()
#response = launcher.response()
#launcher.kill()
#return response
return launcher
>>> # configure and launch the copied file to a new destination
>>> copier(source='remote.host.edu:~/foo.txt', destination='.')
>>> copier.launch()
>>> print(copier.response())
"""
__all__ = ['FileNotFound','Copier']
class FileNotFound(Exception):
'''Exception for improper source or destination format'''
pass
from pathos.connection import Pipe as _Pipe
# broke backward compatability: 30/05/14 ==> replace base-class almost entirely
class Copier(_Pipe):
'''a popen-based copier for parallel and distributed computing.'''
def __init__(self, name=None, **kwds):
'''create a copier
Inputs:
name: a unique identifier (string) for the launcher
source: hostname:path of original [user@host:path is also valid]
destination: hostname:path for copy [user@host:path is also valid]
launcher: remote service mechanism (i.e. scp, cp) [default = 'scp']
options: remote service options (i.e. -v, -P) [default = '']
background: run in background [default = False]
decode: ensure response is 'ascii' [default = True]
stdin: file-like object to serve as standard input for the remote process
'''
self.launcher = kwds.pop('launcher', 'scp')
>>> pipe = Pipe('launcher')
>>>
>>> # configure the pipe to perform the command on the selected host
>>> pipe(command='hostname', host='remote.host.edu')
>>>
>>> # execute the launch and retrieve the response
>>> pipe.launch()
>>> print(pipe.response())
"""
__all__ = ['Pipe']
from pathos.connection import Pipe as _Pipe
# broke backward compatability: 30/05/14 ==> replace base-class almost entirely
class Pipe(_Pipe):
'''a popen-based ssh-pipe for parallel and distributed computing.'''
def __init__(self, name=None, **kwds):
'''create a ssh pipe
Inputs:
name: a unique identifier (string) for the pipe
host: hostname to recieve command [user@host is also valid]
command: a command to send [default = 'echo ']
launcher: remote service mechanism (i.e. ssh, rsh) [default = 'ssh']
options: remote service options (i.e. -v, -N, -L) [default = '']
background: run in background [default = False]
decode: ensure response is 'ascii' [default = True]
stdin: file-like object to serve as standard input for the remote process
'''
self.launcher = kwds.pop('launcher', 'ssh')
'''execute a command (possibly) on a remote host
Execute a process, and return the launcher. Use 'response' to retrieve the
response from the executed command. Use 'kill' to kill the launcher, and 'pid'
to get the process id for the launcher.
Inputs:
command -- command string to be executed
host -- hostname of execution target [default = None (i.e. run locally)]
bg -- run as background process? [default = True]
'''
#XXX: options, background, stdin can be set w/ kwds (also name, launcher)
bg = bool(bg) # overrides 'background'
if host in [None, '']:
from pathos.connection import Pipe
launcher = Pipe(**kwds)
launcher(command=command, background=bg)
else:
from pathos.secure import Pipe
opt = kwds.pop('options', '-q')
launcher = Pipe(**kwds)
launcher(options=opt, command=command, host=host, background=bg)
pathos.logger().info('executing {%s}', launcher.message)
launcher.launch()
#response = launcher.response()
#launcher.kill()
#return response
return launcher