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.1

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.1
File Size Uploaded
configure_with_sudo-0.1.1.tar.gz 4.7 kB Details

Built distribution (wheel)

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

Total release size: 10.6 kB

Release files / configure_with_sudo-0.1.1.tar.gz

Download URL configure_with_sudo-0.1.1.tar.gz
Size 4.7 kB
Tags Source
SHA-256 checksum
How to use checksums
134fbd70a40a2dce9337d84adc621efa459cf3f619be36a646af063c2601db6c
BLAKE2b-256 checksum
How to use checksums
bef0e8a57cfe4249a43c1649711ae2d6c7a9a92603abfd6b85aee0f3d83fc7fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

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

Download URL configure_with_sudo-0.1.1-py3-none-any.whl
Size 5.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
379a89d5ba2700a9d926901b370940fc0641b65b75cedca403fb5d78b47229d7
BLAKE2b-256 checksum
How to use checksums
1f958cb371c534bed40fb02f5150c8615e8ba4acbeebaf8e2a08490d995e176c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13
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