-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
db22922
commit 836de58
Showing
2 changed files
with
24 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
command_group = [] | ||
from .export import export_command | ||
|
||
command_group = [export_command] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import json | ||
|
||
import click | ||
|
||
from stbl.stbl import STBLFile | ||
|
||
|
||
@click.command('export') | ||
@click.argument('stbl_file', type=click.Path(exists=True, dir_okay=False)) | ||
def export_command(stbl_file): | ||
"""Export .stbl file in JSON format.""" | ||
|
||
stbl = STBLFile() | ||
stbl.read(stbl_file) | ||
|
||
if not stbl.validate(): | ||
raise RuntimeError(f'Invalid .stbl file format "{stbl_file}".') | ||
|
||
data = list(map(lambda entry: {'instance': '0x' + ('%08x' % entry.instance_id).upper(), 'text': entry.text}, stbl.entries)) | ||
|
||
print(json.dumps(data, ensure_ascii=False, indent=4)) |