storage-device-managers


Namestorage-device-managers JSON
Version 1.0.0 PyPI version JSON
download
home_pageNone
SummaryHelpful context managers for managing decryption and mounts of storage devices
upload_time2025-02-15 17:15:41
maintainerNone
docs_urlNone
authorMax Görner
requires_python>=3.9
licenseGPL-3.0-or-later
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/)
[![Checked with mypy](http://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/)
[![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](http://www.gnu.org/licenses/gpl-3.0)

# Storage Device Managers - Helpful context managers for managing decryption and mounts of storage devices

## Overview

The `storage_device_managers` module provides a set of utilities to manage
encrypted storage devices, handle BtrFS mounts, and perform file system
operations in a secure and structured way. It is designed to support common
storage-related tasks such as:

- Decrypting and mounting encrypted devices
- Managing BtrFS compression settings
- Creating and removing symbolic links with root privileges
- Formatting and encrypting devices
- Changing file ownership securely

## Features

- **Device Decryption & Encryption**: Easily decrypt and encrypt storage devices using `cryptsetup`.
- **BtrFS Mount Management**: Mount and unmount BtrFS file systems with optional compression settings.
- **Symbolic Link Handling**: Create and remove symbolic links with elevated permissions.
- **File System Operations**: Format devices with BtrFS, manage ownership, and check mount status.
- **Secure Passphrase Handling**: Automatically generate safe passwords for encryption.

## Usage

### Decrypting and Mounting a Device
```python
from pathlib import Path
from storage_device_managers import decrypted_device, mounted_device

# Decrypt and mount a device
with decrypted_device(Path("/dev/sdb1"), "cat /path/to/password-file") as dev:
    with mounted_device(dev) as mount_point:
        print(f"Device mounted at {mount_point}")
```

### Encrypting a Device
```python
from pathlib import Path
from storage_device_managers import encrypt_device

uuid = encrypt_device(Path("/dev/sdb1"), "cat /path/to/password-file")
print(f"Device encrypted with UUID: {uuid}")
```

### Creating a Symbolic Link
```python
from pathlib import Path
from storage_device_managers import symbolic_link

src = Path("/path/to/source")
dest = Path("/path/to/destination")

with symbolic_link(src, dest) as link:
    print(f"Symbolic link created at {link}")
```

## API Reference

### Context Managers
- `decrypted_device(device: Path, pass_cmd: str) -> Iterator[Path]`
  - Decrypts a device using `cryptsetup` and returns a context-managed path.
- `mounted_device(device: Path, compression: Optional[ValidCompressions] = None) -> Iterator[Path]`
  - Mounts a BtrFS device with optional compression settings.
- `symbolic_link(src: Path, dest: Path) -> Iterator[Path]`
  - Creates and removes a symbolic link with root privileges.

### Utility Functions
- `mount_btrfs_device(device: Path, mount_dir: Path, compression: Optional[ValidCompressions] = None) -> None`
- `is_mounted(device: Path) -> bool`
- `get_mounted_devices() -> Mapping[str, Mapping[Path, frozenset[str]]]`
- `unmount_device(device: Path) -> None`
- `open_encrypted_device(device: Path, pass_cmd: str) -> Path`
- `close_decrypted_device(device: Path) -> None`
- `encrypt_device(device: Path, password_cmd: str) -> UUID`
- `mkfs_btrfs(device: Path) -> None`
- `generate_passcmd() -> str`
- `chown(file_or_folder: Path, user: Union[int, str], group: Optional[Union[int, str]] = None, *, recursive: bool) -> None`

## Contributing
Contributions are welcome! Please submit issues and pull requests via GitHub.


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "storage-device-managers",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": null,
    "author": "Max G\u00f6rner",
    "author_email": "5477952+MaxG87@users.noreply.github.com",
    "download_url": "https://files.pythonhosted.org/packages/e8/2c/0e32b9c613792c550e567ed4ca6d5319aaa7c8eb090d1daf991d51646f3b/storage_device_managers-1.0.0.tar.gz",
    "platform": null,
    "description": "[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/)\n[![Checked with mypy](http://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/)\n[![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](http://www.gnu.org/licenses/gpl-3.0)\n\n# Storage Device Managers - Helpful context managers for managing decryption and mounts of storage devices\n\n## Overview\n\nThe `storage_device_managers` module provides a set of utilities to manage\nencrypted storage devices, handle BtrFS mounts, and perform file system\noperations in a secure and structured way. It is designed to support common\nstorage-related tasks such as:\n\n- Decrypting and mounting encrypted devices\n- Managing BtrFS compression settings\n- Creating and removing symbolic links with root privileges\n- Formatting and encrypting devices\n- Changing file ownership securely\n\n## Features\n\n- **Device Decryption & Encryption**: Easily decrypt and encrypt storage devices using `cryptsetup`.\n- **BtrFS Mount Management**: Mount and unmount BtrFS file systems with optional compression settings.\n- **Symbolic Link Handling**: Create and remove symbolic links with elevated permissions.\n- **File System Operations**: Format devices with BtrFS, manage ownership, and check mount status.\n- **Secure Passphrase Handling**: Automatically generate safe passwords for encryption.\n\n## Usage\n\n### Decrypting and Mounting a Device\n```python\nfrom pathlib import Path\nfrom storage_device_managers import decrypted_device, mounted_device\n\n# Decrypt and mount a device\nwith decrypted_device(Path(\"/dev/sdb1\"), \"cat /path/to/password-file\") as dev:\n    with mounted_device(dev) as mount_point:\n        print(f\"Device mounted at {mount_point}\")\n```\n\n### Encrypting a Device\n```python\nfrom pathlib import Path\nfrom storage_device_managers import encrypt_device\n\nuuid = encrypt_device(Path(\"/dev/sdb1\"), \"cat /path/to/password-file\")\nprint(f\"Device encrypted with UUID: {uuid}\")\n```\n\n### Creating a Symbolic Link\n```python\nfrom pathlib import Path\nfrom storage_device_managers import symbolic_link\n\nsrc = Path(\"/path/to/source\")\ndest = Path(\"/path/to/destination\")\n\nwith symbolic_link(src, dest) as link:\n    print(f\"Symbolic link created at {link}\")\n```\n\n## API Reference\n\n### Context Managers\n- `decrypted_device(device: Path, pass_cmd: str) -> Iterator[Path]`\n  - Decrypts a device using `cryptsetup` and returns a context-managed path.\n- `mounted_device(device: Path, compression: Optional[ValidCompressions] = None) -> Iterator[Path]`\n  - Mounts a BtrFS device with optional compression settings.\n- `symbolic_link(src: Path, dest: Path) -> Iterator[Path]`\n  - Creates and removes a symbolic link with root privileges.\n\n### Utility Functions\n- `mount_btrfs_device(device: Path, mount_dir: Path, compression: Optional[ValidCompressions] = None) -> None`\n- `is_mounted(device: Path) -> bool`\n- `get_mounted_devices() -> Mapping[str, Mapping[Path, frozenset[str]]]`\n- `unmount_device(device: Path) -> None`\n- `open_encrypted_device(device: Path, pass_cmd: str) -> Path`\n- `close_decrypted_device(device: Path) -> None`\n- `encrypt_device(device: Path, password_cmd: str) -> UUID`\n- `mkfs_btrfs(device: Path) -> None`\n- `generate_passcmd() -> str`\n- `chown(file_or_folder: Path, user: Union[int, str], group: Optional[Union[int, str]] = None, *, recursive: bool) -> None`\n\n## Contributing\nContributions are welcome! Please submit issues and pull requests via GitHub.\n\n",
    "bugtrack_url": null,
    "license": "GPL-3.0-or-later",
    "summary": "Helpful context managers for managing decryption and mounts of storage devices",
    "version": "1.0.0",
    "project_urls": {
        "Changelog": "https://github.com/MaxG87/storage-device-managers/blob/main/CHANGELOG.md",
        "Homepage": "https://github.com/MaxG87/storage-device-managers",
        "Issues": "https://github.com/MaxG87/storage-device-managers/issues",
        "Repository": "https://github.com/MaxG87/storage-device-managers"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "713ef47982e9df1b329a5fe6912a30373c216f570396ee2c72c21bd70f57c763",
                "md5": "59d5406866296fd3cd37188901312bc1",
                "sha256": "157994d9cc2822ee736b7f8e5a6e87d73bebf0bc70c22ec2c4afb280613e958b"
            },
            "downloads": -1,
            "filename": "storage_device_managers-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "59d5406866296fd3cd37188901312bc1",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 19427,
            "upload_time": "2025-02-15T17:15:35",
            "upload_time_iso_8601": "2025-02-15T17:15:35.588984Z",
            "url": "https://files.pythonhosted.org/packages/71/3e/f47982e9df1b329a5fe6912a30373c216f570396ee2c72c21bd70f57c763/storage_device_managers-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "e82c0e32b9c613792c550e567ed4ca6d5319aaa7c8eb090d1daf991d51646f3b",
                "md5": "3706704ce79a15540a0e83ae44763c8f",
                "sha256": "337b45394a0ea46c9c64062ec5762b74ca46c5776f39b33a1ba143256494e8ad"
            },
            "downloads": -1,
            "filename": "storage_device_managers-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "3706704ce79a15540a0e83ae44763c8f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 18548,
            "upload_time": "2025-02-15T17:15:41",
            "upload_time_iso_8601": "2025-02-15T17:15:41.938393Z",
            "url": "https://files.pythonhosted.org/packages/e8/2c/0e32b9c613792c550e567ed4ca6d5319aaa7c8eb090d1daf991d51646f3b/storage_device_managers-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-02-15 17:15:41",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "MaxG87",
    "github_project": "storage-device-managers",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "storage-device-managers"
}
        
Elapsed time: 1.92551s