Skip to content

Commit e5b10dc

Browse files
Add parse-trx as an installed script, needed to massage file_parser.py's main function to do this
1 parent b5fc5ee commit e5b10dc

File tree

3 files changed

+32
-24
lines changed

3 files changed

+32
-24
lines changed

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,14 @@ In the repository source there are a couple example TraceX traces which can be u
2727

2828
### As a command line utility
2929
[documentation](https://tracex-parser.readthedocs.io/en/latest/cli-interface.html)
30-
The `file_parser` module can also be run as a script, which will provide simple statistics on the trace as well as dumping all the events in the trace:
30+
The `file_parser` module can also be run as a script, which will provide simple statistics on the trace as well as dumping all the events in the trace.
31+
It can be run by either:
32+
- Running the module manually: `python3 -m tracex_parser.file_parser`
33+
- Using the newly installed command: `parse-trx`
34+
35+
Both run methods are identical.
3136
```console
32-
$ python3 -m tracex_parser.file_parser -vvv ./demo_threadx.trx
37+
$ parse-trx -vvv ./demo_threadx.trx
3338
Parsing ./demo_threadx.trx
3439
total events: 974
3540
object registry size: 16

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ include = [
1313
'*.trx',
1414
]
1515

16+
[tool.poetry.scripts]
17+
parse-trx = "tracex_parser.file_parser:main"
18+
1619
[tool.poetry.dependencies]
1720
python = "^3.6"
1821

tracex_parser/file_parser.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,28 @@ def parse_tracex_buffer(filepath: str, custom_events_map: Optional[Dict[int, Tra
188188

189189

190190
def main():
191+
args = parser.parse_args()
192+
193+
from signal import signal, SIGPIPE, SIG_DFL
194+
# Don't break when piping output
195+
signal(SIGPIPE, SIG_DFL)
196+
197+
# set up colours
198+
# Truth table for what we want.
199+
# Precedence is: color, nocolor, tty
200+
# tty | nocolor | color | output
201+
# ==============================
202+
# 0 | 0 | 0 | 0
203+
# 0 | 0 | 1 | 1
204+
# 0 | 1 | 0 | 1
205+
# 0 | 1 | 1 | 1
206+
# 1 | 0 | 0 | 1
207+
# 1 | 0 | 1 | 1
208+
# 1 | 1 | 0 | 0
209+
# 1 | 1 | 1 | 1
210+
have_colours = (sys.stdout.isatty() and not args.nocolor) or args.color
211+
colour = TextColour(have_colours)
212+
191213
for input_filepath in args.input_trxs:
192214
print(f'Parsing {input_filepath}')
193215
tracex_events, obj_reg_map = parse_tracex_buffer(input_filepath)
@@ -218,26 +240,4 @@ def main():
218240

219241

220242
if __name__ == '__main__':
221-
args = parser.parse_args()
222-
223-
from signal import signal, SIGPIPE, SIG_DFL
224-
225-
# Don't break when piping output
226-
signal(SIGPIPE, SIG_DFL)
227-
228-
# set up colours
229-
# Truth table for what we want.
230-
# Precedence is: color, nocolor, tty
231-
# tty | nocolor | color | output
232-
# ==============================
233-
# 0 | 0 | 0 | 0
234-
# 0 | 0 | 1 | 1
235-
# 0 | 1 | 0 | 1
236-
# 0 | 1 | 1 | 1
237-
# 1 | 0 | 0 | 1
238-
# 1 | 0 | 1 | 1
239-
# 1 | 1 | 0 | 0
240-
# 1 | 1 | 1 | 1
241-
have_colours = (sys.stdout.isatty() and not args.nocolor) or args.color
242-
colour = TextColour(have_colours)
243243
main()

0 commit comments

Comments
 (0)