Skip to main content

Parse /proc/mounts and find/list mountpoints (Not a wrapper of findmnt)

Project description

mntfinder

Parse /proc/mounts and find/list mountpoints.

This project IS NOT a wrapper of findmnt.

Install

Just run the command: pip install mntfinder.

Or you can download and install the wheel file from release page manually.

Examples

All functions shown below can search for mountpoints in /proc/<pid>/mounts via the keyword argument pid. If not specified pid, these functions will search in /proc/mounts (it is usually linked to /proc/self/mounts.)

mntfinder.findMountPointByTarget(target: str | bytes | os.PathLike, *, pid: int | None = None) -> MountPoint | None

import mntfinder

mountpoint = mntfinder.findMountPointByTarget('/mnt/data')
if mountpoint:
    print(f"Mount point found: {mountpoint.source} -> {mountpoint.target} (Filesystem type: {mountpoint.fstype})")
else:
    print("Mount point not found")

mntfinder.listAllMountPoints(*, source: str | None = None, target: str | bytes | os.PathLike | None = None, fstype: str | None = None, pid: int | None = None) -> list[MountPoint]

Retrieve all mount points

import mntfinder

mountpoints = mntfinder.listAllMountPoints()

Retrieve mount points with a specific source

import mntfinder

mountpoints = mntfinder.listAllMountPoints(source='/dev/sda1')

Retrieve mount points with a specific target

import mntfinder

mountpoints = mntfinder.listAllMountPoints(target='/mnt/data')

Retrieve mount points with a specific file system type

import mntfinder

mountpoints = mntfinder.listAllMountPoints(fstype='ext4')

mntfinder.isMountPoint(target: str | bytes | os.PathLike, *, source: str | None = None, fstype: str | None = None, pid: int | None = None) -> bool

import mntfinder

is_mount = mntfinder.isMountPoint('/mnt/data', source='/dev/sdb1', fstype='ext4')
if is_mount:
    print('/mnt/data is a mountpoint')
else:
    print('/mnt/data is not a mountpoint')

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

mntfinder-0.1.1.tar.gz (4.6 kB view hashes)

Uploaded Source

Built Distribution

mntfinder-0.1.1-py3-none-any.whl (5.3 kB view hashes)

Uploaded Python 3

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