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.
Metadata
Release files for xmlapply 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| xmlapply-0.1.0.tar.gz | 12.3 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| xmlapply-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 19.8 kB
Release files / xmlapply-0.1.0.tar.gz
| Download URL | xmlapply-0.1.0.tar.gz |
|---|---|
| Size | 12.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
77e1cce253ce9d5d4b3fbecf14a32a277505f70a89f3feab6b27ddbb84ed5428
|
|
BLAKE2b-256 checksum How to use checksums |
6c7d0990b6bdf18b53675cdc8482480328e437a7086a1a2340898c59b67ca4ce
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.0.1 CPython/3.12.8
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 12, 2024.
Transparency logRelease files / xmlapply-0.1.0-py3-none-any.whl
| Download URL | xmlapply-0.1.0-py3-none-any.whl |
|---|---|
| Size | 7.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c04bacffa1609f0d492be80d19d8262f608a4cbb1408f10b78fe300b3e7489c6
|
|
BLAKE2b-256 checksum How to use checksums |
7575722fbd3410e026c678fcbc6cf54ea50043aa3a2234588ef23dec9d503248
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.0.1 CPython/3.12.8
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 12, 2024.
Transparency logSecurity for xmlapply 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for xmlapply-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 12, 2024.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.