Skip to main content

configure_with_sudo

Description

A Python module to handle executing system commands using sudo.

Usage

Extend GenericConfigure, setting at a minimum an appropriate argv command & argument list.

Example

The following class will check if pip is installed and, if not, install it system-wide using sudo easy_install pip:

from configure_with_sudo import GenericConfigure

class InstallPip(GenericConfigure):

    def __init__(self, kill_sudo_cred=True):
        # Initial argv is simply to check if 'pip' is installed
        argv = ["/usr/local/bin/pip", "-V"]
        super(InstallPip, self).__init__(
            argv, use_sudo=True, kill_sudo_cred=kill_sudo_cred)

        try:
            # Execute to check if pip is already installed
            # if it is, self.configured will be set to True
            # and subsequent calls to execute() will do nothing
            self.execute(use_sudo=False)

        except Exception:
            # If pip -V failed, assume pip is not installed.
            # Replace self.argv with the installation command.
            self.argv = ["/usr/bin/easy_install", "pip"]

pip_installer = InstallPip()
pip_installer.execute()

The following example will capture the output of sudo ls -l /private/var/root, and print it line-by-line:

class DirectoryLister(GenericConfigure):

    def __init__(self, path):
        argv = ["ls", "-l", path]
        super().__init__(argv, use_sudo=True)

path = "/private/var/root"
lister = DirectoryLister(path)
output = lister.execute(return_output=True)

for line in output:
    print(line)

Metadata

Release files for configure-with-sudo 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for configure-with-sudo 0.1.0
File Size Uploaded Provenance Actions
configure_with_sudo-0.1.0.tar.gz 4.6 kB Without provenance Details for configure_with_sudo-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for configure-with-sudo 0.1.0
File Interpreter ABI Platform Actions
configure_with_sudo-0.1.0-py3-none-any.whl Python 3 none any Details for configure_with_sudo-0.1.0-py3-none-any.whl

Total release size: 10.5 kB

Release files / configure_with_sudo-0.1.0.tar.gz

Download URL configure_with_sudo-0.1.0.tar.gz
Size 4.6 kB
Tags Source
SHA-256 checksum
How to use checksums
55148e2bcc18a11f661b5a0fbafd59586fb6ce2eb3325fbfff62d31983bd3b0b
BLAKE2b-256 checksum
How to use checksums
bd8247688450819b6c843b28464933045f7666f79cb69e5f6527b75dae8a9760
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

Release files / configure_with_sudo-0.1.0-py3-none-any.whl

Download URL configure_with_sudo-0.1.0-py3-none-any.whl
Size 5.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
98912c03d0185444c0e3084d1e712207d25243c577a3b1be9001b1a86b58559e
BLAKE2b-256 checksum
How to use checksums
60e03f5ba01d2929f170b0be4150e5733a1419b542ac3eb7bdb7663e7e8d0150
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

Security for configure-with-sudo 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page