Skip to main content

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.52

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.php file has a corresponding Repository/MyEntityRepository.php).
  • Create Files Using Templates and Placeholders: Generate files from templates with dynamic placeholders.

Requirements

  • Python >=3.10

Dependencies

  • attrs>=23.1.0
  • cattrs>=23.1.0
  • python-dotenv
  • toml
  • wexample-config==0.0.52
  • wexample-file==0.0.7
  • wexample-helpers-yaml==0.0.68
  • wexample-prompt==0.0.50
  • 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


Download files

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

Source Distribution

wexample_filestate-0.0.54.tar.gz (44.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wexample_filestate-0.0.54-py3-none-any.whl (78.5 kB view details)

Uploaded Python 3

File details

Details for the file wexample_filestate-0.0.54.tar.gz.

File metadata

  • Download URL: wexample_filestate-0.0.54.tar.gz
  • Upload date:
  • Size: 44.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.25.9 CPython/3.12.3 Linux/6.8.0-79-generic

File hashes

Hashes for wexample_filestate-0.0.54.tar.gz
Algorithm Hash digest
SHA256 45eb9620b21d3268154d917619ea7f2a49cd30698e07bbf71d2067f8dc67bcbb
MD5 4a7f41e8fe7cf06587dd7cc97879dd0f
BLAKE2b-256 2ba8c53770f8bdb0ad9fa57ab8dac78af373d7bd6e81cc7dde8c851966a66c81

See more details on using hashes here.

File details

Details for the file wexample_filestate-0.0.54-py3-none-any.whl.

File metadata

  • Download URL: wexample_filestate-0.0.54-py3-none-any.whl
  • Upload date:
  • Size: 78.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.25.9 CPython/3.12.3 Linux/6.8.0-79-generic

File hashes

Hashes for wexample_filestate-0.0.54-py3-none-any.whl
Algorithm Hash digest
SHA256 1a4222bc3a5bcd7b4403f84cd8d3a1adef9257cfc1597b17bdf1ffd279616ec4
MD5 ccb806da33a02eff3427effdc3f67c28
BLAKE2b-256 040e7567f86b140ebc4439307e17d4cd5da40f3c11ead8b35f742dcc00903692

See more details on using hashes here.

Supported by

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