Skip to main content

An extension for "filestate" package, which adds GIT management operations.

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 -s 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_git-0.0.10.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

wexample_filestate_git-0.0.10-py3-none-any.whl (17.9 kB view details)

Uploaded Python 3

File details

Details for the file wexample_filestate_git-0.0.10.tar.gz.

File metadata

  • Download URL: wexample_filestate_git-0.0.10.tar.gz
  • Upload date:
  • Size: 11.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for wexample_filestate_git-0.0.10.tar.gz
Algorithm Hash digest
SHA256 2339eaf224a297b9c99acc530374e85f8677f3a791622e8832224e731c0fa8ef
MD5 a60d73c77bbee626b51bb4fe00f62d41
BLAKE2b-256 a85192600a4efe28ded6d6748a6a41652c944b84043c0b131a00518e626fc136

See more details on using hashes here.

File details

Details for the file wexample_filestate_git-0.0.10-py3-none-any.whl.

File metadata

File hashes

Hashes for wexample_filestate_git-0.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 154cc87ff1aa351f721919bff3340c6e00b5801f9d05daf701f7f723539d3c34
MD5 b74c327ad36e3fee003ec87fafa1dae1
BLAKE2b-256 da65cd5d60c620a3f9d24084c1a1b2220c25b220d0cd17342e0b1d58574ef2f5

See more details on using hashes here.

Supported by

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