Skip to main content

A tool for managing file states, with configuration files in YAML.

Project description

filestate

filestate is a Python package that allows you to manage the state of files and directories using YAML configuration files.

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.

Installation

Install filestate with pip:

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()

Testing

 pytest -rP -x pip/filestate/tests/

License

This project is licensed under the MIT License - see the LICENSE file for details.

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.14.tar.gz (22.4 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.14-py3-none-any.whl (46.7 kB view details)

Uploaded Python 3

File details

Details for the file wexample-filestate-0.0.14.tar.gz.

File metadata

  • Download URL: wexample-filestate-0.0.14.tar.gz
  • Upload date:
  • Size: 22.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.2

File hashes

Hashes for wexample-filestate-0.0.14.tar.gz
Algorithm Hash digest
SHA256 5b42d66eb8d2cece3738b5f2aecd290d7f43327a8f53118b2acd4f8ddfb8a4b8
MD5 34eb62fed675257b4834c1aabf0ae949
BLAKE2b-256 9ba3f3cafe97a64c52a02aa5abec7ecf94ac9928bb67ddf6a744fcb6b09f58ff

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for wexample_filestate-0.0.14-py3-none-any.whl
Algorithm Hash digest
SHA256 ec2f8fb44ef247006909f9a7b8f0596cf5ccac352191f15eb5bc8bc87234d4f7
MD5 c6b900d02fe3444ca65e2b52900e8bd8
BLAKE2b-256 f2adac752bfe4851ba4a3e02901e7ebaec4364246d70b177dfcae1c28e9fa30f

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