A tool for applying XML-defined file changes to a project directory
Project description
xmlapply
xmlapply is a command-line tool for applying file changes defined in an XML specification to a target project directory.
Changes can include creating, updating, or deleting files.
credit idea: https://github.com/mckaywrigley/o1-xml-parser
workflow
prereqs
- install
code2prompt- cargo install code2prompt
setup
git clone https://github.com/darinkishore/xmlapply.git
cd xmlapply
mkdir -p ~/templates (or wherever you wanna put your templates)
cp o1.hbs ~/templates/
Workflow
Okay, so you're working on a project.
Want to use o1 to help.
go to project directory, run
xmlapply use-dir to indicate that you're working on the project in that directory now.
for whatever directory you want to include in your query as context, (inlcuding the root .)
code2prompt --template ~/templates/o1.hbs $dir
Give that to o1, wait however long it takes, copy that to your clipboard, then run xmlapply apply.
Table of Contents
- xmlapply
- Apply changes from a file
- Apply changes from clipboard content (if you have copied XML)
- Copy XML content to clipboard, then:
Features
- XML-Defined Changes: Define file operations in an XML file. Operations supported:
- CREATE: Create new files and write provided content.
- UPDATE: Overwrite existing files with new content.
- DELETE: Remove specified files.
- Clipboard Support: If an XML file is not provided, xmlapply can read the XML content directly from your clipboard.
- Configurable Default Directory: Set a global default directory to avoid specifying the target directory each time.
- Dry-Run Mode: Preview changes without actually modifying any files.
How It Works
- Parse XML: xmlapply reads an XML file (or clipboard content) to determine which files to create, update, or delete.
- Apply Changes: It then executes the requested operations against a target directory, ensuring that no changes are made outside of the intended project directory.
- Configuration Management: A simple YAML config file in your home directory (
~/.xmlapply.yml) stores your default project directory.
Installation
Prerequisites:
- Python 3.8+
- pip
Install from Source:
git clone https://github.com/yourusername/xmlapply.git
cd xmlapply
pip install .
This will install xmlapply as a CLI command on your system (assuming ~/.local/bin or equivalent is on your PATH).
Usage
Basic Command Structure:
xmlapply [COMMAND] [OPTIONS]
Applying Changes
Use the apply command to apply changes defined in an XML file or from the clipboard:
# Apply changes from a file
xmlapply apply --file /path/to/changes.xml --directory /path/to/project
# Apply changes from clipboard content (if you have copied XML)
xmlapply apply
If no --directory is provided, xmlapply will use the configured default directory. If no --file is provided, xmlapply will attempt to read XML from the clipboard.
Changing the Default Directory
To set or update the default directory:
xmlapply set_dir /path/to/my/project
Once set, you can omit the --directory option when running apply.
Viewing Configuration
To view the current configuration:
xmlapply show_config
Dry Runs
Use --dry-run to preview changes without making them:
xmlapply apply --file changes.xml --dry-run
This will show you which operations would have been performed.
XML Format
The tool expects an XML structure like:
<root>
<changed_files>
<file>
<file_summary>Initial creation of README</file_summary>
<file_operation>CREATE</file_operation>
<file_path>docs/README.md</file_path>
<file_code>This is the README content</file_code>
</file>
<file>
<file_summary>Remove obsolete config</file_summary>
<file_operation>DELETE</file_operation>
<file_path>config/old_config.yml</file_path>
</file>
</changed_files>
</root>
Required Fields:
• <file_operation>: CREATE, UPDATE, or DELETE
• <file_path>: Relative path within the project directory
Optional Fields:
• <file_summary>: A short description of the change.
• <file_code>: The content to write when creating or updating a file.
Configuration
xmlapply stores configuration in a YAML file located at ~/.xmlapply.yml. The primary configuration value is default_directory.
Example ~/.xmlapply.yml:
default_directory: /Users/username/Projects/mydefaultproject
You typically won’t need to edit this file directly; use the set_dir command instead.
Examples
1. Apply from a file directly:
xmlapply apply --file test.xml --directory /Users/darin/Projects/myproject
2. Apply changes from clipboard to the default directory:
# Copy XML content to clipboard, then:
xmlapply apply
3. Preview what would happen (no actual changes):
xmlapply apply --file edge_cases.xml --dry-run
Development
This repository includes:
• CLI Tool: src/xmlapply/cli.py
• Parser: src/xmlapply/parser.py for parsing XML structures into Python data classes.
• Applier: src/xmlapply/apply.py for applying changes to the filesystem.
• Configuration: src/xmlapply/config.py for reading and writing default directory settings.
• Core Module Init: src/xmlapply/__init__.py defines the package interface.
• Examples & Tests: test.xml and edge_cases.xml provide sample XML inputs.
For development, ensure you have requirements.txt dependencies installed:
pip install -r requirements.txt
You can run the hello.py script to confirm the environment is set up:
python hello.py
Expected output:
Hello from xmlapply!
License
This project is distributed under the terms of the MIT license. See LICENSE for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file xmlapply-0.1.0.tar.gz.
File metadata
- Download URL: xmlapply-0.1.0.tar.gz
- Upload date:
- Size: 12.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
77e1cce253ce9d5d4b3fbecf14a32a277505f70a89f3feab6b27ddbb84ed5428
|
|
| MD5 |
e3d928f65e4f2d81e9847e14744f85b4
|
|
| BLAKE2b-256 |
6c7d0990b6bdf18b53675cdc8482480328e437a7086a1a2340898c59b67ca4ce
|
Provenance
The following attestation bundles were made for xmlapply-0.1.0.tar.gz:
Publisher:
publish.yml on darinkishore/xmlapply
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
xmlapply-0.1.0.tar.gz -
Subject digest:
77e1cce253ce9d5d4b3fbecf14a32a277505f70a89f3feab6b27ddbb84ed5428 - Sigstore transparency entry: 154951211
- Sigstore integration time:
-
Permalink:
darinkishore/xmlapply@4f6185d7a5ff60993624c561742303c1a3b542af -
Branch / Tag:
refs/tags/0.0.1 - Owner: https://github.com/darinkishore
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4f6185d7a5ff60993624c561742303c1a3b542af -
Trigger Event:
release
-
Statement type:
File details
Details for the file xmlapply-0.1.0-py3-none-any.whl.
File metadata
- Download URL: xmlapply-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c04bacffa1609f0d492be80d19d8262f608a4cbb1408f10b78fe300b3e7489c6
|
|
| MD5 |
926e8dcd0053b98b764d22a8394e4c1a
|
|
| BLAKE2b-256 |
7575722fbd3410e026c678fcbc6cf54ea50043aa3a2234588ef23dec9d503248
|
Provenance
The following attestation bundles were made for xmlapply-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on darinkishore/xmlapply
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
xmlapply-0.1.0-py3-none-any.whl -
Subject digest:
c04bacffa1609f0d492be80d19d8262f608a4cbb1408f10b78fe300b3e7489c6 - Sigstore transparency entry: 154951212
- Sigstore integration time:
-
Permalink:
darinkishore/xmlapply@4f6185d7a5ff60993624c561742303c1a3b542af -
Branch / Tag:
refs/tags/0.0.1 - Owner: https://github.com/darinkishore
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4f6185d7a5ff60993624c561742303c1a3b542af -
Trigger Event:
release
-
Statement type: