A Python-based tool for updating, inserting, or deleting lines in project files.
Project description
CodeUpdater
CodeUpdater is a Python-based tool designed to automate the process of updating, inserting, or deleting lines in multiple files within a project directory based on a specified JSON configuration.
Table of Contents
Features
- Update: Replace specific lines in a file with new content.
- Insert: Insert new lines at a specific position in a file, pushing existing lines downward.
- Delete: Remove specific lines from a file.
Installation
To install CodeUpdater, you can use pip. Run the following command:
pip install code-updater
Or, if you are developing or want to install it from a local copy:
-
Clone the repository to your local machine:
git clone https://github.com/joonheeu/code-updater.git cd code-updater
-
Install the package locally:
pip install .
Usage
To use CodeUpdater, ensure that you have Python installed. Then, create an updates.json file in the root directory of your project, and structure it according to the configuration described below.
You can run the script using the following command:
cup [OPTIONS] {project_root_path}
Replace {project_root_path} with the root directory of your project where the files are located.
Options
-h,--help: Show the help message and exit.-V,--version: Show the current version ofCodeUpdaterand exit.
JSON Configuration
The JSON file should describe the operations you want to perform. Below is the structure of the JSON file:
[
{
"path": "src/example.py",
"line": 42,
"type": "update", # Type of operation: "update", "insert", or "delete"
"replace": [
"new line 42 content",
"new line 43 content"
]
}
]
Type
- update: Replaces the lines starting from the specified line number with the provided content in the "replace" list.
- insert: Inserts the lines from the "replace" list starting at the specified line number, shifting existing lines downward.
- delete: Removes the line specified by the line number. The "replace" field is not needed for this operation.
Example
Here’s an example configuration:
[
{
"path": "src/example.py",
"line": 42,
"type": "update",
"replace": [
"updated line 42 content",
"updated line 43 content"
]
},
{
"path": "src/example.py",
"line": 10,
"type": "insert",
"replace": [
"inserted line 10 content",
"inserted line 11 content"
]
},
{
"path": "src/example.py",
"line": 15,
"type": "delete"
}
]
In this example:
- The lines at 42 and 43 in
src/example.pywill be updated. - New lines will be inserted at line 10, and existing lines will be shifted downward.
- The line at 15 will be deleted.
Logging
The tool generates logs in the logs/ directory inside the specified project root. Each log file is timestamped and details the changes made to the files. The log includes both the original and the updated content for comparison.
Contributing
Contributions are welcome! Please fork the repository and submit a pull request. If you find any issues or have suggestions, feel free to open an issue on GitHub.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contact
Author: Daniel
Email: daniel@udit.one
Company: UDIT
For more details, visit the GitHub repository: CodeUpdater
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 code_updater-0.1.0.tar.gz.
File metadata
- Download URL: code_updater-0.1.0.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bb86d3167fd14fd6d7277ee9f7bc27310772a6406f303d7c8127fc32f2b86a61
|
|
| MD5 |
3714dd3ba3e1a29896ee9f0578818d2e
|
|
| BLAKE2b-256 |
15c83b5f5dc0cb2cd6de48eda1cc220e15b3e052e81bbbe6a6db551b067fe40a
|
File details
Details for the file code_updater-0.1.0-py3-none-any.whl.
File metadata
- Download URL: code_updater-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e377beac49715570ba7b6fb0d35a6fa179fd79ecda0e4d5c119ca6e24f48a0b0
|
|
| MD5 |
d5f92c8a25d781326225efb02ab5d207
|
|
| BLAKE2b-256 |
c6a91456d7494ca32f62cde91ad3cb8f9574c3cd1c60569b9d40bc11a03ecc49
|