Package that allows you to manage the state of files and directories using YAML configuration files.
Project description
wexample-filestate
Package that allows you to manage the state of files and directories using YAML configuration files.
Version: 0.0.47
Features
- Apply and Modify Permissions and Ownership: Manage file and directory permissions and ownership individually or recursively.
- Create, Modify, and Delete Directories: Use patterns and regex to create, modify, and delete directories and subdirectories (e.g., ensure each
Entity/MyEntity.phpfile has a correspondingRepository/MyEntityRepository.php). - Create Files Using Templates and Placeholders: Generate files from templates with dynamic placeholders.
Requirements
- Python >=3.10
Dependencies
- pydantic>=2,<3
- python-dotenv
- toml
- wexample-config==0.0.49
- wexample-file==0.0.4
- wexample-helpers-yaml==0.0.65
- wexample-prompt==0.0.44
- xmltodict
Installation
pip install wexample-filestate
Usage
Configuration File Example
# example.yaml
children:
- path: /path/to/file
owner: user
group: group
mode: '0644'
- path: /path/to/directory
recursive: true
mode: '0755'
create: true
Usage
Here's how you can use filestate in your Python code:
from filestate import FileStateManager
# Initialize the state manager with the root directory
state_manager = FileStateManager('root/directory/')
# Configure the state manager from a YAML configuration file
state_manager.configure_from_file('configuration.yaml')
# Perform a dry run to see what changes would be made
result = state_manager.dry_run()
result.print()
# Check if the configuration can be successfully applied
if state_manager.succeed():
# Apply the configuration
state_manager.apply()
else:
print("Configuration could not be applied successfully.")
Applying and Modifying Permissions
state_manager = FileStateManager('/var/www/')
state_manager.configure({
'files': [
{'path': '/var/www/index.html', 'owner': 'www-data', 'group': 'www-data', 'mode': '0644'},
{'path': '/var/www/css/', 'recursive': True, 'owner': 'www-data', 'group': 'www-data', 'mode': '0755'}
]
})
state_manager.apply()
Applying and Modifying Permissions
state_manager = FileStateManager('/project/')
state_manager.configure({
'directories': [
{'path': '/project/src/Entity/', 'create': True},
{'path': '/project/src/Repository/', 'create': True, 'pattern': 'Entity/*Entity.php', 'target': 'Repository/*Repository.php'}
]
})
state_manager.apply()
Links
License
MIT
Credits
This package has been developed by Wexample, a collection of tools and utilities to streamline development workflows.
Visit wexample.com to discover more tools and resources for efficient development.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file wexample_filestate-0.0.49.tar.gz.
File metadata
- Download URL: wexample_filestate-0.0.49.tar.gz
- Upload date:
- Size: 8.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.25.9 CPython/3.12.3 Linux/6.8.0-71-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2b6ad5d9ccaa974146407d25d1b7bd6573e1a30a7886f3e406c44e75e384f06f
|
|
| MD5 |
1c92a848fa439c6cd6a07abf60751e5c
|
|
| BLAKE2b-256 |
59fe9484289974fdaf44e68cef07210a8386146879501f7df4e94b78b6eb3cb5
|
File details
Details for the file wexample_filestate-0.0.49-py3-none-any.whl.
File metadata
- Download URL: wexample_filestate-0.0.49-py3-none-any.whl
- Upload date:
- Size: 3.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.25.9 CPython/3.12.3 Linux/6.8.0-71-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
adc5bd37cd5b587b5653d78390ee240baa54fa591451337108ea08eb98fe4696
|
|
| MD5 |
4d4a743cde7197dca2b4e92450aca40e
|
|
| BLAKE2b-256 |
a4337cf18f8412450ad8605a2f303d7a3de3c0966aa092229e316e7eac7ab04f
|