Skip to main content

linux-utils: Linux system administration tools for Python

https://travis-ci.org/xolox/python-linux-utils.svg?branch=master https://coveralls.io/repos/xolox/python-linux-utils/badge.svg?branch=master

The Python package linux-utils provides utility functions that make it easy to script system administration tasks on Linux systems in Python. The following functionality is currently implemented:

The package is currently tested on cPython 2.7, 3.4, 3.5, 3.6, 3.7 and PyPy (2.7) on Ubuntu Linux (using Travis CI).

Installation

The linux-utils package is available on PyPI which means installation should be as simple as:

$ pip install linux-utils

There’s actually a multitude of ways to install Python packages (e.g. the per user site-packages directory, virtual environments or just installing system wide) and I have no intention of getting into that discussion here, so if this intimidates you then read up on your options before returning to these instructions 😉.

Usage

For details about the Python API please refer to the API documentation available on Read the Docs. The Python implementation of cryptdisks_start and cryptdisks_stop is available on the command line as the following two programs:

As the names imply these programs are not functional equivalents of their “official” counterparts, because they only support LUKS encryption and a small subset of the available encryption options.

cryptdisks-start-fallback

Usage: cryptdisks-start-fallback NAME

Reads /etc/crypttab and unlocks the encrypted filesystem with the given NAME.

This program emulates the functionality of Debian’s cryptdisks_start program, but it only supports LUKS encryption and a small subset of the available encryption options.

cryptdisks-stop-fallback

Usage: cryptdisks-stop-fallback NAME

Reads /etc/crypttab and locks the encrypted filesystem with the given NAME.

This program emulates the functionality of Debian’s cryptdisks_stop program, but it only supports LUKS encryption and a small subset of the available encryption options.

History

Back in 2015 I wrote some Python code to parse the Linux configuration files /etc/fstab and /etc/crypttab for use in crypto-drive-manager. Fast forward to 2017 and I found myself wanting to use the same functionality in rsync-system-backup. Three options presented themselves to me:

Copy/paste the relevant code

Having to maintain the same code in multiple places causes lower quality code because having to duplicate the effort of writing documentation, developing tests and fixing bugs is a very demotivating endeavor. In fact sometime in 2016 I did copy/paste parts of this code into a project at work, because I needed similar functionality there. Of course since then the two implementations have started diverging 😛.

Make crypto-drive-manager a dependency of rsync-system-backup

Although this approach is less ugly than copy/pasting the code, it still isn’t exactly elegant because the two projects have nothing to do with each other apart from working with LUKS encrypted disks on Linux.

Extract the functionality into a new package

In my opinion this is clearly the most elegant approach, unfortunately it also requires the most work from me 😇. On the plus side I’m publishing the new package with a test suite which means less untested code remains in crypto-drive-manager (which doesn’t have a test suite at the time of writing).

While extracting the code I shortly considered integrating the functionality into debuntu-tools, however the /etc/fstab and /etc/crypttab parsing isn’t specific to Debian or Ubuntu at all and debuntu-tools has several dependencies that aren’t relevant to Linux configuration file parsing.

Since then it has become clear that this was a good choice (not merging the functionality into debuntu-tools) because linux-utils now provides a Python implementation of cryptdisks_start and cryptdisks_stop, which is mostly useful on Linux systems that aren’t based on Debian 🙂.

Contact

The latest version of linux-utils is available on PyPI and GitHub. The documentation is available on Read the Docs and includes a changelog. For bug reports please create an issue on GitHub. If you have questions, suggestions, etc. feel free to send me an e-mail at peter@peterodding.com.

License

This software is licensed under the MIT license.

© 2020 Peter Odding.

Metadata

Release files for linux-utils 0.7

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

Source distribution (sdist)

Source distribution for linux-utils 0.7
File Size Uploaded
linux-utils-0.7.tar.gz 25.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for linux-utils 0.7
File Interpreter ABI Platform
linux_utils-0.7-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 53.1 kB

Release files / linux-utils-0.7.tar.gz

Download URL linux-utils-0.7.tar.gz
Size 25.4 kB
Tags Source
SHA-256 checksum
How to use checksums
c54ad479d9fe70ccefa32127a3723b3ee76725901e5fb3f68d4d5473b63534dc
BLAKE2b-256 checksum
How to use checksums
e0fa0faf9fc8c07349f2b2c121f501ff581476b69c1ddafd3dd065d2fd61407f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.6.9

Release files / linux_utils-0.7-py2.py3-none-any.whl

Download URL linux_utils-0.7-py2.py3-none-any.whl
Size 27.7 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
a2790d7813d5c695535ab93d5f87ad03d2e2f8133e0755de40084ec2ad461c07
BLAKE2b-256 checksum
How to use checksums
005ece5bfbdc80f7c7cc9ff2df64873c092446a6bafdc5ac6af199373c441cef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.6.9

Release history Release notifications | RSS feed

This release

0.7 This release

2 release files

0.6

2 release files

0.5

2 release files

0.4.1

2 release files

0.4

2 release files

0.3

2 release files

0.2

2 release files

0.1

2 release files

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