schrodinger.job.remote_command module

exception schrodinger.job.remote_command.CommandError(sp_error=None, command='', errmsg=None, output='', userhost='', returncode=None)[source]

Bases: Exception

Used to report external commands that fail.

When this is caught by the main cmdline driver, the error message will be printed and the usage message displayed.

__init__(sp_error=None, command='', errmsg=None, output='', userhost='', returncode=None)[source]

The constructor takes a subprocess.CalledProcessError for the failed command, from which details of the command are extracted. A user- friendly error message will be composed from that information unless an explicit error message is provided.

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

schrodinger.job.remote_command.which(program, search_path=None)[source]

Search for a file in the given list of directories. Use $PATH if no search path is specified.

Returns the absolute pathname for the first executable found.

Parameters

rogram – the executable to search for

Return type

string

Returns

the absolute pathname for the executable found, or None if the program could not be found.

schrodinger.job.remote_command.get_rsh_exec()[source]

Return the name of the rsh-compatible program to use for executing remote commands.

schrodinger.job.remote_command.shell()[source]

Return the pathname to a Bourne-compatible shell that can be used for running shell commands.

schrodinger.job.remote_command.remote_command(command, host, user=None, capture_stderr=False)[source]

Execute a the given command on a particular host.

Returns a tuple containing the captured output and an error message.

Parameters
  • host (string) – the host on which to run the command

  • user (string) – the user account under which to run the command

  • command (string) – the command to be executed on the remote machine

  • capture_stderr (boolean) – should stderr be captured along with stdout?

Return type

string

Returns

the captured output from the command

Raises

CommandError – if the remote command fails

schrodinger.job.remote_command.rsh_put_cmd(remotehost, put_fn, remoteuser=None, from_remote=False)[source]

Returns the ‘scp’ command needed to execute to copy a file to a given remote host. The actual remote command needs to be appended to the returned string.

Parameters
  • remotehost (string) – string

  • put_fn (string) – Path to the file that will be copied over. If it is a directory, it will be copied recursively

  • remoteuser (string) – Remote username

  • from_remote (bool) – If True, put from remote to local, otherwise (default) from local to remote

Return type

list

Returns

the list of command args for the command, suitable for use in subprocess functions

schrodinger.job.remote_command.get_remote_path(remoteuser, remotehost, path)[source]

Assemble remote path from remote user, host and path.

Parameters
  • remoteuser (str or None) – Remote user, can be None

  • remotehost (str) – Remote host

  • path (str) – Remote absolute path

Return type

str

Returns

Remote path with user and host

schrodinger.job.remote_command.rsh_test(hosts)[source]

Test remote commands to and from one or more hosts.