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
Release files for code-updater 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 | |
|---|---|---|---|
| code_updater-0.1.0.tar.gz | 6.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| code_updater-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 12.7 kB
Release files / code_updater-0.1.0.tar.gz
| Download URL | code_updater-0.1.0.tar.gz |
|---|---|
| Size | 6.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bb86d3167fd14fd6d7277ee9f7bc27310772a6406f303d7c8127fc32f2b86a61
|
|
BLAKE2b-256 checksum How to use checksums |
15c83b5f5dc0cb2cd6de48eda1cc220e15b3e052e81bbbe6a6db551b067fe40a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.4
|
Release files / code_updater-0.1.0-py3-none-any.whl
| Download URL | code_updater-0.1.0-py3-none-any.whl |
|---|---|
| Size | 6.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e377beac49715570ba7b6fb0d35a6fa179fd79ecda0e4d5c119ca6e24f48a0b0
|
|
BLAKE2b-256 checksum How to use checksums |
c6a91456d7494ca32f62cde91ad3cb8f9574c3cd1c60569b9d40bc11a03ecc49
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.4
|