| old_recipe_config | ||
| .gitignore | ||
| config_selector.py | ||
| deleted_files.csv | ||
| ignored_files.yml | ||
| README.md | ||
Drupal Configuration Selector
A Python utility to selectively copy configuration files from a source directory to a target directory based on file prefixes.
Overview
This script helps you manage and transfer specific Drupal configuration files by:
- Reading a list of configuration file prefixes from a JSON file
- Identifying matching files in a source directory
- Copying selected files to a target directory
- Providing a TUI (Text User Interface) to manage the selection process
Requirements
- Python 3.6+
- curses library (built into most Python installations on Linux/Mac)
- PyYAML library (install with:
pip install pyyaml)
Installation and Setup
The script operates in the current working directory where you run it. It will create the following subdirectories if they don't exist:
original_config/- Place your source configuration files herenew_recipe_config/- Matched files will be copied here (with UUID and _core removed)old_recipe_config/- Optional: Place previous recipe version here for comparisonchanged_files/- Files that changed between versions will be placed hereignored_files.yml- Optional: List files to exclude from change trackingdeleted_files.csv- Tracks files that should be deleted
Usage
- Copy or move the script to your working directory (or use the full path to run it)
- Place your source configuration files in the
original_configdirectory - Run the script:
python3 config_selector.py
- The script will create a default
config_prefixes.jsonin the current directory if it doesn't exist - Use the TUI to manage your file selections and copy files
Hierarchical Navigation
The script organizes configuration files in a tree-like structure based on dot-separated prefixes:
- Files like
field.storage.node.comment.ymlare split into segments:field>field.storage>field.storage.node> etc. - Use RIGHT ARROW to navigate deeper into a selected prefix
- Use LEFT ARROW to go back up one level in the hierarchy
- At each level, you see only the unique segments available at that level
- Each segment shows the total count of files under it
- Segments with children have a "▶" indicator
- You can perform actions (add, delete, select files) at any level in the hierarchy
TUI Navigation
The Text User Interface provides the following controls:
- UP/DOWN: Navigate through the list of prefixes
- LEFT/RIGHT: Navigate through the hierarchy tree (drill down/go back)
- SPACE: Toggle between matched and unmatched prefixes view
- ENTER: Select individual files from the selected prefix
- A: Add a new prefix (press ESC or Enter with empty input to cancel)
- O: Choose a prefix from the list of unmatched prefixes
- D: Delete the selected prefix (in matched view) or add the selected prefix (in unmatched view)
- C: Copy all matched files to the new_recipe_config directory (with UUID and _core removal)
- M: Compare old and new recipe configs, track changes and deletions
- S: Save the current list of prefixes to the JSON file
- Q: Quit the application
Individual File Selection
When you press ENTER on a prefix, a dialog opens that allows you to:
- In matched view: Select individual files to remove from the matching set
- In unmatched view: Select individual files to add to a matching prefix
Within the file selection dialog:
- Use UP/DOWN to navigate between files
- Press SPACE to toggle selection of a file
- Press ENTER to confirm your selection
- Press ESC to cancel
Configuration File
The script uses a JSON file to store prefixes. The default file is created at first run:
{
"prefixes": [
"put.your.prefixes.here"
]
}
You can modify this file directly or use the TUI to manage the prefixes.
File Comparison and Change Tracking
The script can compare configuration files between recipe versions:
- M: Compare old and new recipe configurations
- Compares files in
old_recipe_config/withnew_recipe_config/ - Copies changed files to
changed_files/directory - Tracks deleted files in
deleted_files.csv
- Compares files in
This feature helps you track what has changed between recipe versions and what files need to be removed.
Ignoring Files from Change Tracking
You can create an ignored_files.yml file to prevent specific configuration files from being copied to the changed_files/ folder during comparison. This is useful when certain files have intentional differences that should not be tracked as changes.
Example ignored_files.yml:
field:
name: field.field.wisski_individual.bb48a22d36f1c15cd16b143d23466812.field__vf__title
reason: because we need target id instead of uuid
another_category:
name: some.other.config.file.yml
reason: custom modification required
Files listed in this YAML will be excluded from the changed_files/ directory even if they have changed between versions.
Directory Structure
/your/working/directory/
├── config_selector.py # Main script
├── config_prefixes.json # Configuration prefixes list
├── ignored_files.yml # Optional: List of files to ignore from change tracking
├── original_config/ # Source directory containing all configuration files
├── new_recipe_config/ # Target directory where matched files will be copied (cleaned)
├── old_recipe_config/ # Previous version of recipe config (for comparison)
├── changed_files/ # Files that have changed between old and new versions
└── deleted_files.csv # List of files that should be deleted from the recipe