Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

wexample-filestate

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wexample-filestate

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

  • 0.0.15
  • PyPI
  • Socket score

Maintainers
1

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.

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc