Metadata-Version: 2.1
Name: mntfinder
Version: 0.1.1
Summary: Parse /proc/mounts and find/list mountpoints (Not a wrapper of findmnt)
Author: nukemiko
License: MIT License
        
        Copyright (c) 2024 Nukemiko<https://github.com/nukemiko>
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Repository, https://github.com/nukemiko/python-mntfinder
Project-URL: Issues, https://github.com/nukemiko/python-mntfinder/issues
Project-URL: Changelog, https://github.com/nukemiko/python-mntfinder/blob/master/CHANGELOG.md
Keywords: mountpoint,mnt,findmnt
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: POSIX
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: attrs

# 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`

```python
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

```python
import mntfinder

mountpoints = mntfinder.listAllMountPoints()
```

#### Retrieve mount points with a specific source

```python
import mntfinder

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

#### Retrieve mount points with a specific target

```python
import mntfinder

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

#### Retrieve mount points with a specific file system type

```python
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`

```python
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')
```
