spur


Namespur JSON
Version 0.3.23 PyPI version JSON
download
home_pagehttps://github.com/mwilliamson/spur.py
SummaryRun commands and manipulate files locally or over SSH using the same interface
upload_time2023-03-11 22:56:25
maintainer
docs_urlNone
authorMichael Williamson
requires_python>=3.6
licenseBSD-2-Clause
keywords ssh shell subprocess process
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            spur.py: Run commands and manipulate files locally or over SSH using the same interface
=======================================================================================

To run echo locally:

.. code-block:: python

    import spur

    shell = spur.LocalShell()
    result = shell.run(["echo", "-n", "hello"])
    print(result.output) # prints hello

Executing the same command over SSH uses the same interface -- the only
difference is how the shell is created:

.. code-block:: python

    import spur

    shell = spur.SshShell(hostname="localhost", username="bob", password="password1")
    with shell:
        result = shell.run(["echo", "-n", "hello"])
    print(result.output) # prints hello

Installation
------------

``$ pip install spur``

Shell constructors
------------------

LocalShell
~~~~~~~~~~

Takes no arguments:

.. code-block:: python

    spur.LocalShell()

SshShell
~~~~~~~~

Requires a hostname. Also requires some combination of a username,
password and private key, as necessary to authenticate:

.. code-block:: python

    # Use a password
    spur.SshShell(
        hostname="localhost",
        username="bob",
        password="password1"
    )
    # Use a private key
    spur.SshShell(
        hostname="localhost",
        username="bob",
        private_key_file="path/to/private.key"
    )
    # Use a port other than 22
    spur.SshShell(
        hostname="localhost",
        port=50022,
        username="bob",
        password="password1"
    )

Optional arguments:

* ``connect_timeout`` -- a timeout in seconds for establishing an SSH
  connection. Defaults to 60 (one minute).

* ``missing_host_key`` -- by default, an error is raised when a host
  key is missing. One of the following values can be used to change the
  behaviour when a host key is missing:

  - ``spur.ssh.MissingHostKey.raise_error`` -- raise an error
  - ``spur.ssh.MissingHostKey.warn`` -- accept the host key and log a
    warning
  - ``spur.ssh.MissingHostKey.accept`` -- accept the host key

* ``shell_type`` -- the type of shell used by the host. Defaults to
  ``spur.ssh.ShellTypes.sh``, which should be appropriate for most Linux
  distributions. If the host uses a different shell, such as simpler shells
  often found on embedded systems, try changing ``shell_type`` to a more
  appropriate value, such as ``spur.ssh.ShellTypes.minimal``. The following
  shell types are currently supported:

  - ``spur.ssh.ShellTypes.sh`` -- the Bourne shell. Supports all features.

  - ``spur.ssh.ShellTypes.minimal`` -- a minimal shell. Several features
    are unsupported:

    - Non-existent commands will not raise ``spur.NoSuchCommandError``.

    - The following arguments to ``spawn`` and ``run`` are unsupported unless
      set to their default values:
      ``cwd``, ``update_env``, and ``store_pid``.

* ``look_for_private_keys`` -- by default, Spur will search for discoverable
  private key files in ``~/.ssh/``.
  Set to ``False`` to disable this behaviour.

* ``load_system_host_keys`` -- by default, Spur will attempt to read host keys
  from the user's known hosts file, as used by OpenSSH, and no exception will
  be raised if the file can't be read.
  Set to ``False`` to disable this behaviour.

* ``sock`` -- an open socket or socket-like object to use for communication to
  the target host. For instance:

  .. code-block:: python

      sock=paramiko.proxy.ProxyCommand(
          "ssh -q -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
          "bob@proxy.example.com nc -q0 target.example.com 22"
      )

  Examples of socket-like objects include:

  * |paramiko.Channel|_
  * |paramiko.proxy.ProxyCommand|_
    (`unsupported in Python 3 <https://github.com/paramiko/paramiko/issues/673>`_ as of writing)

.. |paramiko.Channel| replace:: ``paramiko.Channel``
.. _paramiko.Channel: http://docs.paramiko.org/en/latest/api/channel.html

.. |paramiko.proxy.ProxyCommand| replace:: ``paramiko.proxy.ProxyCommand``
.. _paramiko.proxy.ProxyCommand: http://docs.paramiko.org/en/latest/api/proxy.html

Shell interface
---------------

run(command, cwd, update\_env, store\_pid, allow\_error, stdout, stderr, encoding)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Run a command and wait for it to complete. The command is expected to be
a list of strings. Returns an instance of ``ExecutionResult``.

.. code-block:: python

    result = shell.run(["echo", "-n", "hello"])
    print(result.output) # prints hello

Note that arguments are passed without any shell expansion. For
instance, ``shell.run(["echo", "$PATH"])`` will print the literal string
``$PATH`` rather than the value of the environment variable ``$PATH``.

Raises ``spur.NoSuchCommandError`` if trying to execute a non-existent
command.

Raises ``spur.CouldNotChangeDirectoryError`` if changing the current directory
to ``cwd`` failed.

Optional arguments:

* ``cwd`` -- change the current directory to this value before
  executing the command.
* ``update_env`` -- a ``dict`` containing environment variables to be
  set before running the command. If there's an existing environment
  variable with the same name, it will be overwritten. Otherwise, it is
  unchanged.
* ``store_pid`` -- if set to ``True`` when calling ``spawn``, store the
  process id of the spawned process as the attribute ``pid`` on the
  returned process object. Has no effect when calling ``run``.
* ``allow_error`` -- ``False`` by default. If ``False``, an exception
  is raised if the return code of the command is anything but 0. If
  ``True``, a result is returned irrespective of return code.
* ``stdout`` -- if not ``None``, anything the command prints to
  standard output during its execution will also be written to
  ``stdout`` using ``stdout.write``.
* ``stderr`` -- if not ``None``, anything the command prints to
  standard error during its execution will also be written to
  ``stderr`` using ``stderr.write``.
* ``encoding`` -- if set, this is used to decode any output.
  By default, any output is treated as raw bytes.
  If set, the raw bytes are decoded before writing to
  the passed ``stdout`` and ``stderr`` arguments (if set)
  and before setting the output attributes on the result.

``shell.run(*args, **kwargs)`` should behave similarly to
``shell.spawn(*args, **kwargs).wait_for_result()``

spawn(command, cwd, update\_env, store\_pid, allow\_error, stdout, stderr, encoding)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Behaves the same as ``run`` except that ``spawn`` immediately returns an
object representing the running process.

Raises ``spur.NoSuchCommandError`` if trying to execute a non-existent
command.

Raises ``spur.CouldNotChangeDirectoryError`` if changing the current directory
to ``cwd`` failed.

open(path, mode="r")
~~~~~~~~~~~~~~~~~~~~

Open the file at ``path``. Returns a file-like object.

By default, files are opened in text mode.
Appending `"b"` to the mode will open the file in binary mode.

For instance, to copy a binary file over SSH,
assuming you already have an instance of ``SshShell``:

.. code-block:: python

    with ssh_shell.open("/path/to/remote", "rb") as remote_file:
        with open("/path/to/local", "wb") as local_file:
            shutil.copyfileobj(remote_file, local_file)

close()
~~~~~~~

Closes and the shell and releases any associated resources.
``close()`` is called automatically when the shell is used as a context manager.

Process interface
-----------------

Returned by calls to ``shell.spawn``. Has the following attributes:

* ``pid`` -- the process ID of the process. Only available if
  ``store_pid`` was set to ``True`` when calling ``spawn``.

Has the following methods:

* ``is_running()`` -- return ``True`` if the process is still running,
  ``False`` otherwise.
* ``stdin_write(value)`` -- write ``value`` to the standard input of
  the process.
* ``wait_for_result()`` -- wait for the process to exit, and then
  return an instance of ``ExecutionResult``. Will raise
  ``RunProcessError`` if the return code is not zero and
  ``shell.spawn`` was not called with ``allow_error=True``.
* ``send_signal(signal)`` -- sends the process the signal ``signal``.
  Only available if ``store_pid`` was set to ``True`` when calling
  ``spawn``.

Classes
-------

ExecutionResult
~~~~~~~~~~~~~~~

``ExecutionResult`` has the following properties:

* ``return_code`` -- the return code of the command
* ``output`` -- a string containing the result of capturing stdout
* ``stderr_output`` -- a string containing the result of capturing
  stdout

It also has the following methods:

* ``to_error()`` -- return the corresponding RunProcessError. This is
  useful if you want to conditionally raise RunProcessError, for
  instance:

.. code-block:: python

    result = shell.run(["some-command"], allow_error=True)
    if result.return_code > 4:
        raise result.to_error()

RunProcessError
~~~~~~~~~~~~~~~

A subclass of ``RuntimeError`` with the same properties as
``ExecutionResult``:

* ``return_code`` -- the return code of the command
* ``output`` -- a string containing the result of capturing stdout
* ``stderr_output`` -- a string containing the result of capturing
  stdout

NoSuchCommandError
~~~~~~~~~~~~~~~~~~

``NoSuchCommandError`` has the following properties:

* ``command`` -- the command that could not be found

CouldNotChangeDirectoryError
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

``CouldNotChangeDirectoryError`` has the following properties:

* ``directory`` -- the directory that could not be changed to

API stability
-------------

Using the the terminology from `Semantic
Versioning <http://semver.org/spec/v1.0.0.html>`_, if the version of
spur is X.Y.Z, then X is the major version, Y is the minor version, and
Z is the patch version.

While the major version is 0, incrementing the patch version indicates a
backwards compatible change. For instance, if you're using 0.3.1, then
it should be safe to upgrade to 0.3.2.

Incrementing the minor version indicates a change in the API. This means
that any code using previous minor versions of spur may need updating
before it can use the current minor version.

Undocumented features
~~~~~~~~~~~~~~~~~~~~~

Some features are undocumented, and should be considered experimental.
Use them at your own risk. They may not behave correctly, and their
behaviour and interface may change at any time.

Troubleshooting
---------------

I get the error "Connection refused" when trying to connect to a virtual machine using a forwarded port on ``localhost``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Try using ``"127.0.0.1"`` instead of ``"localhost"`` as the hostname.

I get the error "Connection refused" when trying to execute commands over SSH
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Try connecting to the machine using SSH on the command line with the
same settings. For instance, if you're using the code:

.. code-block:: python

    shell = spur.SshShell(
            hostname="remote",
            port=2222,
            username="bob",
            private_key_file="/home/bob/.ssh/id_rsa"
        )
    with shell:
        result = shell.run(["echo", "hello"])

Try running:

.. code-block:: sh

    ssh bob@remote -p 2222 -i /home/bob/.ssh/id_rsa

If the ``ssh`` command succeeds, make sure that the arguments to
``ssh.SshShell`` and the ``ssh`` command are the same. If any of the
arguments to ``ssh.SshShell`` are dynamically generated, try hard-coding
them to make sure they're set to the values you expect.

I can't spawn or run commands over SSH
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

If you're having trouble spawning or running commands over SSH, try passing
``shell_type=spur.ssh.ShellTypes.minimal`` as an argument to ``spur.SshShell``.
For instance:

.. code-block:: python

    import spur
    import spur.ssh

    spur.SshShell(
        hostname="localhost",
        username="bob",
        password="password1",
        shell_type=spur.ssh.ShellTypes.minimal,
    )

This makes minimal assumptions about the features that the host shell supports,
and is especially well-suited to minimal shells found on embedded systems. If
the host shell is more fully-featured but only works with
``spur.ssh.ShellTypes.minimal``, feel free to submit an issue.

Why don't shell features such as variables and redirection work?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Commands are run directly rather than through a shell.
If you want to use any shell features such as variables and redirection,
then you'll need to run those commands within an appropriate shell.
For instance:

.. code-block:: python

    shell.run(["sh", "-c", "echo $PATH"])
    shell.run(["sh", "-c", "ls | grep bananas"])

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/mwilliamson/spur.py",
    "name": "spur",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "ssh shell subprocess process",
    "author": "Michael Williamson",
    "author_email": "mike@zwobble.org",
    "download_url": "https://files.pythonhosted.org/packages/e3/55/6960989438cf304aa15bbcaa1233ab2df2cfffd269b7cbb6b90b991ad10f/spur-0.3.23.tar.gz",
    "platform": null,
    "description": "spur.py: Run commands and manipulate files locally or over SSH using the same interface\n=======================================================================================\n\nTo run echo locally:\n\n.. code-block:: python\n\n    import spur\n\n    shell = spur.LocalShell()\n    result = shell.run([\"echo\", \"-n\", \"hello\"])\n    print(result.output) # prints hello\n\nExecuting the same command over SSH uses the same interface -- the only\ndifference is how the shell is created:\n\n.. code-block:: python\n\n    import spur\n\n    shell = spur.SshShell(hostname=\"localhost\", username=\"bob\", password=\"password1\")\n    with shell:\n        result = shell.run([\"echo\", \"-n\", \"hello\"])\n    print(result.output) # prints hello\n\nInstallation\n------------\n\n``$ pip install spur``\n\nShell constructors\n------------------\n\nLocalShell\n~~~~~~~~~~\n\nTakes no arguments:\n\n.. code-block:: python\n\n    spur.LocalShell()\n\nSshShell\n~~~~~~~~\n\nRequires a hostname. Also requires some combination of a username,\npassword and private key, as necessary to authenticate:\n\n.. code-block:: python\n\n    # Use a password\n    spur.SshShell(\n        hostname=\"localhost\",\n        username=\"bob\",\n        password=\"password1\"\n    )\n    # Use a private key\n    spur.SshShell(\n        hostname=\"localhost\",\n        username=\"bob\",\n        private_key_file=\"path/to/private.key\"\n    )\n    # Use a port other than 22\n    spur.SshShell(\n        hostname=\"localhost\",\n        port=50022,\n        username=\"bob\",\n        password=\"password1\"\n    )\n\nOptional arguments:\n\n* ``connect_timeout`` -- a timeout in seconds for establishing an SSH\n  connection. Defaults to 60 (one minute).\n\n* ``missing_host_key`` -- by default, an error is raised when a host\n  key is missing. One of the following values can be used to change the\n  behaviour when a host key is missing:\n\n  - ``spur.ssh.MissingHostKey.raise_error`` -- raise an error\n  - ``spur.ssh.MissingHostKey.warn`` -- accept the host key and log a\n    warning\n  - ``spur.ssh.MissingHostKey.accept`` -- accept the host key\n\n* ``shell_type`` -- the type of shell used by the host. Defaults to\n  ``spur.ssh.ShellTypes.sh``, which should be appropriate for most Linux\n  distributions. If the host uses a different shell, such as simpler shells\n  often found on embedded systems, try changing ``shell_type`` to a more\n  appropriate value, such as ``spur.ssh.ShellTypes.minimal``. The following\n  shell types are currently supported:\n\n  - ``spur.ssh.ShellTypes.sh`` -- the Bourne shell. Supports all features.\n\n  - ``spur.ssh.ShellTypes.minimal`` -- a minimal shell. Several features\n    are unsupported:\n\n    - Non-existent commands will not raise ``spur.NoSuchCommandError``.\n\n    - The following arguments to ``spawn`` and ``run`` are unsupported unless\n      set to their default values:\n      ``cwd``, ``update_env``, and ``store_pid``.\n\n* ``look_for_private_keys`` -- by default, Spur will search for discoverable\n  private key files in ``~/.ssh/``.\n  Set to ``False`` to disable this behaviour.\n\n* ``load_system_host_keys`` -- by default, Spur will attempt to read host keys\n  from the user's known hosts file, as used by OpenSSH, and no exception will\n  be raised if the file can't be read.\n  Set to ``False`` to disable this behaviour.\n\n* ``sock`` -- an open socket or socket-like object to use for communication to\n  the target host. For instance:\n\n  .. code-block:: python\n\n      sock=paramiko.proxy.ProxyCommand(\n          \"ssh -q -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null\"\n          \"bob@proxy.example.com nc -q0 target.example.com 22\"\n      )\n\n  Examples of socket-like objects include:\n\n  * |paramiko.Channel|_\n  * |paramiko.proxy.ProxyCommand|_\n    (`unsupported in Python 3 <https://github.com/paramiko/paramiko/issues/673>`_ as of writing)\n\n.. |paramiko.Channel| replace:: ``paramiko.Channel``\n.. _paramiko.Channel: http://docs.paramiko.org/en/latest/api/channel.html\n\n.. |paramiko.proxy.ProxyCommand| replace:: ``paramiko.proxy.ProxyCommand``\n.. _paramiko.proxy.ProxyCommand: http://docs.paramiko.org/en/latest/api/proxy.html\n\nShell interface\n---------------\n\nrun(command, cwd, update\\_env, store\\_pid, allow\\_error, stdout, stderr, encoding)\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nRun a command and wait for it to complete. The command is expected to be\na list of strings. Returns an instance of ``ExecutionResult``.\n\n.. code-block:: python\n\n    result = shell.run([\"echo\", \"-n\", \"hello\"])\n    print(result.output) # prints hello\n\nNote that arguments are passed without any shell expansion. For\ninstance, ``shell.run([\"echo\", \"$PATH\"])`` will print the literal string\n``$PATH`` rather than the value of the environment variable ``$PATH``.\n\nRaises ``spur.NoSuchCommandError`` if trying to execute a non-existent\ncommand.\n\nRaises ``spur.CouldNotChangeDirectoryError`` if changing the current directory\nto ``cwd`` failed.\n\nOptional arguments:\n\n* ``cwd`` -- change the current directory to this value before\n  executing the command.\n* ``update_env`` -- a ``dict`` containing environment variables to be\n  set before running the command. If there's an existing environment\n  variable with the same name, it will be overwritten. Otherwise, it is\n  unchanged.\n* ``store_pid`` -- if set to ``True`` when calling ``spawn``, store the\n  process id of the spawned process as the attribute ``pid`` on the\n  returned process object. Has no effect when calling ``run``.\n* ``allow_error`` -- ``False`` by default. If ``False``, an exception\n  is raised if the return code of the command is anything but 0. If\n  ``True``, a result is returned irrespective of return code.\n* ``stdout`` -- if not ``None``, anything the command prints to\n  standard output during its execution will also be written to\n  ``stdout`` using ``stdout.write``.\n* ``stderr`` -- if not ``None``, anything the command prints to\n  standard error during its execution will also be written to\n  ``stderr`` using ``stderr.write``.\n* ``encoding`` -- if set, this is used to decode any output.\n  By default, any output is treated as raw bytes.\n  If set, the raw bytes are decoded before writing to\n  the passed ``stdout`` and ``stderr`` arguments (if set)\n  and before setting the output attributes on the result.\n\n``shell.run(*args, **kwargs)`` should behave similarly to\n``shell.spawn(*args, **kwargs).wait_for_result()``\n\nspawn(command, cwd, update\\_env, store\\_pid, allow\\_error, stdout, stderr, encoding)\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nBehaves the same as ``run`` except that ``spawn`` immediately returns an\nobject representing the running process.\n\nRaises ``spur.NoSuchCommandError`` if trying to execute a non-existent\ncommand.\n\nRaises ``spur.CouldNotChangeDirectoryError`` if changing the current directory\nto ``cwd`` failed.\n\nopen(path, mode=\"r\")\n~~~~~~~~~~~~~~~~~~~~\n\nOpen the file at ``path``. Returns a file-like object.\n\nBy default, files are opened in text mode.\nAppending `\"b\"` to the mode will open the file in binary mode.\n\nFor instance, to copy a binary file over SSH,\nassuming you already have an instance of ``SshShell``:\n\n.. code-block:: python\n\n    with ssh_shell.open(\"/path/to/remote\", \"rb\") as remote_file:\n        with open(\"/path/to/local\", \"wb\") as local_file:\n            shutil.copyfileobj(remote_file, local_file)\n\nclose()\n~~~~~~~\n\nCloses and the shell and releases any associated resources.\n``close()`` is called automatically when the shell is used as a context manager.\n\nProcess interface\n-----------------\n\nReturned by calls to ``shell.spawn``. Has the following attributes:\n\n* ``pid`` -- the process ID of the process. Only available if\n  ``store_pid`` was set to ``True`` when calling ``spawn``.\n\nHas the following methods:\n\n* ``is_running()`` -- return ``True`` if the process is still running,\n  ``False`` otherwise.\n* ``stdin_write(value)`` -- write ``value`` to the standard input of\n  the process.\n* ``wait_for_result()`` -- wait for the process to exit, and then\n  return an instance of ``ExecutionResult``. Will raise\n  ``RunProcessError`` if the return code is not zero and\n  ``shell.spawn`` was not called with ``allow_error=True``.\n* ``send_signal(signal)`` -- sends the process the signal ``signal``.\n  Only available if ``store_pid`` was set to ``True`` when calling\n  ``spawn``.\n\nClasses\n-------\n\nExecutionResult\n~~~~~~~~~~~~~~~\n\n``ExecutionResult`` has the following properties:\n\n* ``return_code`` -- the return code of the command\n* ``output`` -- a string containing the result of capturing stdout\n* ``stderr_output`` -- a string containing the result of capturing\n  stdout\n\nIt also has the following methods:\n\n* ``to_error()`` -- return the corresponding RunProcessError. This is\n  useful if you want to conditionally raise RunProcessError, for\n  instance:\n\n.. code-block:: python\n\n    result = shell.run([\"some-command\"], allow_error=True)\n    if result.return_code > 4:\n        raise result.to_error()\n\nRunProcessError\n~~~~~~~~~~~~~~~\n\nA subclass of ``RuntimeError`` with the same properties as\n``ExecutionResult``:\n\n* ``return_code`` -- the return code of the command\n* ``output`` -- a string containing the result of capturing stdout\n* ``stderr_output`` -- a string containing the result of capturing\n  stdout\n\nNoSuchCommandError\n~~~~~~~~~~~~~~~~~~\n\n``NoSuchCommandError`` has the following properties:\n\n* ``command`` -- the command that could not be found\n\nCouldNotChangeDirectoryError\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n``CouldNotChangeDirectoryError`` has the following properties:\n\n* ``directory`` -- the directory that could not be changed to\n\nAPI stability\n-------------\n\nUsing the the terminology from `Semantic\nVersioning <http://semver.org/spec/v1.0.0.html>`_, if the version of\nspur is X.Y.Z, then X is the major version, Y is the minor version, and\nZ is the patch version.\n\nWhile the major version is 0, incrementing the patch version indicates a\nbackwards compatible change. For instance, if you're using 0.3.1, then\nit should be safe to upgrade to 0.3.2.\n\nIncrementing the minor version indicates a change in the API. This means\nthat any code using previous minor versions of spur may need updating\nbefore it can use the current minor version.\n\nUndocumented features\n~~~~~~~~~~~~~~~~~~~~~\n\nSome features are undocumented, and should be considered experimental.\nUse them at your own risk. They may not behave correctly, and their\nbehaviour and interface may change at any time.\n\nTroubleshooting\n---------------\n\nI get the error \"Connection refused\" when trying to connect to a virtual machine using a forwarded port on ``localhost``\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nTry using ``\"127.0.0.1\"`` instead of ``\"localhost\"`` as the hostname.\n\nI get the error \"Connection refused\" when trying to execute commands over SSH\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nTry connecting to the machine using SSH on the command line with the\nsame settings. For instance, if you're using the code:\n\n.. code-block:: python\n\n    shell = spur.SshShell(\n            hostname=\"remote\",\n            port=2222,\n            username=\"bob\",\n            private_key_file=\"/home/bob/.ssh/id_rsa\"\n        )\n    with shell:\n        result = shell.run([\"echo\", \"hello\"])\n\nTry running:\n\n.. code-block:: sh\n\n    ssh bob@remote -p 2222 -i /home/bob/.ssh/id_rsa\n\nIf the ``ssh`` command succeeds, make sure that the arguments to\n``ssh.SshShell`` and the ``ssh`` command are the same. If any of the\narguments to ``ssh.SshShell`` are dynamically generated, try hard-coding\nthem to make sure they're set to the values you expect.\n\nI can't spawn or run commands over SSH\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nIf you're having trouble spawning or running commands over SSH, try passing\n``shell_type=spur.ssh.ShellTypes.minimal`` as an argument to ``spur.SshShell``.\nFor instance:\n\n.. code-block:: python\n\n    import spur\n    import spur.ssh\n\n    spur.SshShell(\n        hostname=\"localhost\",\n        username=\"bob\",\n        password=\"password1\",\n        shell_type=spur.ssh.ShellTypes.minimal,\n    )\n\nThis makes minimal assumptions about the features that the host shell supports,\nand is especially well-suited to minimal shells found on embedded systems. If\nthe host shell is more fully-featured but only works with\n``spur.ssh.ShellTypes.minimal``, feel free to submit an issue.\n\nWhy don't shell features such as variables and redirection work?\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nCommands are run directly rather than through a shell.\nIf you want to use any shell features such as variables and redirection,\nthen you'll need to run those commands within an appropriate shell.\nFor instance:\n\n.. code-block:: python\n\n    shell.run([\"sh\", \"-c\", \"echo $PATH\"])\n    shell.run([\"sh\", \"-c\", \"ls | grep bananas\"])\n",
    "bugtrack_url": null,
    "license": "BSD-2-Clause",
    "summary": "Run commands and manipulate files locally or over SSH using the same interface",
    "version": "0.3.23",
    "split_keywords": [
        "ssh",
        "shell",
        "subprocess",
        "process"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "70e74767b3623086417a897f332a107a77be8d6081e53ed546035364686396d7",
                "md5": "8d68655e2c3a73cca505ea53106d54c4",
                "sha256": "9b73b7b8e0444c1bcc50be609c6c2e820b2a7e9b92eee821682e1359ca63c74e"
            },
            "downloads": -1,
            "filename": "spur-0.3.23-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8d68655e2c3a73cca505ea53106d54c4",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": ">=3.6",
            "size": 14526,
            "upload_time": "2023-03-11T22:56:23",
            "upload_time_iso_8601": "2023-03-11T22:56:23.607333Z",
            "url": "https://files.pythonhosted.org/packages/70/e7/4767b3623086417a897f332a107a77be8d6081e53ed546035364686396d7/spur-0.3.23-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e3556960989438cf304aa15bbcaa1233ab2df2cfffd269b7cbb6b90b991ad10f",
                "md5": "7af533b211b959afa4cc393cdfb94c07",
                "sha256": "8cc13bf43a35214ebe5f795f5f4b8c04aa714dbaa95f3a0b6256266e52de4f17"
            },
            "downloads": -1,
            "filename": "spur-0.3.23.tar.gz",
            "has_sig": false,
            "md5_digest": "7af533b211b959afa4cc393cdfb94c07",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 16948,
            "upload_time": "2023-03-11T22:56:25",
            "upload_time_iso_8601": "2023-03-11T22:56:25.556651Z",
            "url": "https://files.pythonhosted.org/packages/e3/55/6960989438cf304aa15bbcaa1233ab2df2cfffd269b7cbb6b90b991ad10f/spur-0.3.23.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-03-11 22:56:25",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "mwilliamson",
    "github_project": "spur.py",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "tox": true,
    "lcname": "spur"
}
        
Elapsed time: 0.05826s