pylivemaker
pylivemaker copied to clipboard
Add more utility for lmlsb edit and dump
Resolves #126
lmlsb edit
- Added capability to insert certain parameters without prompt
- Added capability to edit based on the list of parameters in JSON format
Usage: lmlsb edit [OPTIONS] LSB_FILE [LINE_NUMBER]
Edit the specified command within an LSB file.
Only specific command types and specific fields can be edited.
The original LSB file will be backed up to <lsb_file>.bak
WARNING: This command should only be used by advanced users familiar with
the LiveMaker engine. Improper use of this command may cause undefined
behavior (or a complete crash) in the LiveMaker engine during runtime.
Note: Setting empty fields to improper data types may cause undefined
behavior in the LiveMaker engine. When editing a field, the data type of the
new value is assumed to be the same as the original data type.
Batch mode:
You can batch edit several line and paramaters with JSON file.
The format of JSON file is as follow:
{
"36" : {
"modified": true,
"params": {
"PR_LEFT": "20",
"PR_TOP": "12"
}
}
}
You can generate the JSON via "lmlsb.exe dump" command with JSON mode.
Example:
- To edit line 33 with prompt:
lmlsb.exe edit 00000001.lsb 33
- To set the value of PR_LEFT parameter on line 33 to 20:
lmlsb.exe edit 00000001.lsb 33 -p '{\"PR_LEFT\": 20}'
- To import back the value from lmlsb dump:
lmlsb.exe edit 00000001.lsb -b 00000001.json
Options:
-p, --param TEXT Parameter in JSON format.
-b, --batch TEXT Edit with parameter with JSON formatted file.
--help Show this message and exit.
lmlsb dump
- Add option to dump into JSON formatted data that supports
lmlsb edit
Usage: lmlsb dump [OPTIONS] INPUT_FILE...
Dump the contents of the specified LSB file(s) to stdout in a human-readable
format.
MODE:
text
The full LSB will be output as human-readable text.
xml
The full LSB file will be output as an XML document.
lines
only text lines will be output.
json
The output will be a JSON-formatted LSB command (JSON will always be in UTF-8 format).
You can edit the JSON and import it back using the lmlsb edit command.
Use "jsonfull" option if you want to output all line.
Note: - Don't forget to set the "modified" flag to true for each line you edit.
- This mode will only output the editable lines.
jsonfull
Will output the complete line instead of only editable lines
Example:
lmlsb.exe dump 00000001.lsb -m json -o 00000001.json
Options:
-m, --mode [text|xml|lines|json|jsonfull]
Output mode (defaults to text)
-e, --encoding [cp932|utf-8] Output text encoding (defaults to utf-8).
-o, --output-file FILE Output file. If unspecified, output will be
dumped to stdout.
--help Show this message and exit.
Codecov Report
Attention: Patch coverage is 5.63380% with 134 lines in your changes are missing coverage. Please review.
Project coverage is 48.07%. Comparing base (
04c8f5b) to head (808a6e7).
| Files | Patch % | Lines |
|---|---|---|
| src/livemaker/cli/lmlsb.py | 5.63% | 134 Missing :warning: |
:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@ Coverage Diff @@
## master #133 +/- ##
==========================================
- Coverage 49.04% 48.07% -0.97%
==========================================
Files 23 23
Lines 5548 5672 +124
==========================================
+ Hits 2721 2727 +6
- Misses 2827 2945 +118
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
@pmrowla Thank you for your insightful feedback.
In addressing the need for inputting values without manual intervention, several considerations emerged during the development process:
- Ensuring the edit command could accept parameters without needing human input was crucial for automation. This is the main issue that lead to this PR.
- Recognizing that multiple parameters might be involved, I pondered the most efficient way to transfer these values from CLI parameters to lmlsb.
- I also grappled with the need to edit multiple lines simultaneously, seeking a method more efficient than invoking the lmlsb edit command individually for each line. This led me to explore batch mode editing via an external file, recognizing that CLI arguments might not suffice due to potential size limitations.
- Recognizing the potential complexity of using an external file, I saw the importance of providing an easy way to create or edit templates. Thus, I introduced a new method in lmlsb dump to generate a ready-to-use template for the edit command.
After much trial and consideration, I found that JSON format offered the most logical solution for my use case. I prefer it over the original XML format due to its efficiency and compatibility with other applications. And yes, to answer your question, I've already integrated this feature for Translator++.
Thank you again for your feedback. I'll make sure to address your suggestions as I continue to refine the implementation.
One thing to note would be that when pylivemaker is installed you can just use it as a library, so any scripts and utilties you need for translator++ purposes can be kept separate and just import livemaker as needed (they don't necessarily need to be added back into the pylm CLI)
Thank you for the hint @pmrowla
Thanks again for this PR. I'm closing this for now as it's not something I have the time to maintain in pylm, and since it seems like this can be handled within translator++. But I'm open to revisiting this in the future if needed.