Skip to main content

Fstab parsing and formatting library

Project description

MIT-licensed libary for parsing and creating fstab files

PyPI Read the Docs License

Features

  • Unlike Canonical’s fstab Python library, this actually works with Python 3 and does not have a cancerous license (GPLv3)

  • Small

Installation

pip3 install pyfstab

Examples

# Import the classes
from pyfstab import Fstab

# Read the file
with open("/etc/fstab", "r") as f:
    fstab = Fstab().read_file(f)

# List all devices/identifiers of fstab entries
for entry in fstab.entries:
    print(entry.device)

# List all mountpoints of CIFS mounts
for entry in fstab.entries_by_type["cifs"]:
    print(entry.dir)

# Print filesystem type for mount at /mnt/disk
print(fstab.entry_by_dir["/mnt/disk"].type)

# List all mount options for device UUID=123456
for entry in fstab.entries_by_device["UUID=123456"]:
    print(entry.options)

# Print Tag value for all entries with device defined as
# UUID=something or ID=something
for entry in fstab.entries:
    if entry.device_tag_type in {"UUID", "ID"}:
        print(entry.device_tag_value)

# Change device tag type from UUID= to ID=
entry.device_tag_type = "ID"

# Change device tag value from "123456" to "4321"
# (Changes from "ID=123456" to "ID=4321")
entry.device_tag_value = "4321"

# Print new device string (it's "ID=4321" now)
print(entry.device)

# Set both tag type and value at the same time in both valid ways
entry.device = ("UUID", "11223344")
entry.device = "UUID=11223344"

# Add an entry (does not update entries_by_device/type/dir)
# but it will be printed when formatting the fstab object
fstab.entries.append(
    Entry(
        "/dev/sdg4",
        "/mnt/disk",
        "ext4",
        "rw,relatime",
        0,
        0
    )
)

# Remove all entries except ext*
fstab.entries = [
    entry
    for entry in fstab.entries
    if entry.type.startswith("ext")
]

# Print and write the formatted fstab file
formatted = str(fstab)
print(formatted)
with open("/etc/myfstab", "w") as f:
    f.write(formatted)

Contributing

  • Send any issues to GitHub’s issue tracker.

  • Before sending a pull request, format it with Black (-Sl79)

  • Any changes must be updated to the documentation

  • All pull requests must be tested with tox (if you are using pyenv, add the installed versions for py35-py38 and pypy3 to .python-version at the root of this repository before running tox)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyfstab-0.2.0.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

pyfstab-0.2.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file pyfstab-0.2.0.tar.gz.

File metadata

  • Download URL: pyfstab-0.2.0.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.10.1 Linux/5.15.11-zen1-1-zen

File hashes

Hashes for pyfstab-0.2.0.tar.gz
Algorithm Hash digest
SHA256 5f0ceeef5c6356a5414ff44eaf578b774a3ff14cce901593ff25f8cb79b769f5
MD5 052d3932fb94d0b9d4012c19e53cf5fc
BLAKE2b-256 397568453a33f32e5089a6cda22daa81ff0a41fec91b946ad2df20597881ef4b

See more details on using hashes here.

File details

Details for the file pyfstab-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: pyfstab-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.10.1 Linux/5.15.11-zen1-1-zen

File hashes

Hashes for pyfstab-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 798bf5dda62007fe94a56f91a9dddec972cfca482527eba768651df8b64171c5
MD5 b833c019d1c1f301e9eb9c49df3e3ffd
BLAKE2b-256 fe493f8982ed4dd3a82eb54395bef717490129c75b20e8612cc2b6a1e52a0ea3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page