Skip to content

Commit

Permalink
Allow applications to be run as scripts if desired.
Browse files Browse the repository at this point in the history
This allows users to run:
```
python fusion_engine_client/applications/p1_display.py
```

in addition to the normally recommended:
```
p1_display
```
  • Loading branch information
adamshapiro0 committed Oct 24, 2023
1 parent 99ba145 commit e2b48b1
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 2 deletions.
5 changes: 3 additions & 2 deletions python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ FusionEngine message specification.
time-aligning FusionEngine data captured in a `*.p1log` file
- `applications` - Applications and processing tools -- see [Applications](#applications) for detailed
descriptions of each of these tools
- _The applications in this directory will be installed on your system by `pip install` along with the rest of
the library code so that they can be called directly from the command line_
- _The applications in this directory will be installed on your system by `pip install`, along with the rest of
the library code, so that they can be called directly from the command line (e.g., `p1_display.py` can be run
on the command line as `p1_display`)_
- `messages` - Python message definitions
- `parsers` - Message encoding and decoding support
- [decoder.py](fusion_engine_client/parsers/decoder.py) - `FusionEngineDecoder` class, used to frame and parse
Expand Down
12 changes: 12 additions & 0 deletions python/fusion_engine_client/applications/p1_display.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
#!/usr/bin/env python3

import os
import sys

# If this application is being run directly as a script (e.g., python p1_*.py), rather than as a script installed by pip
# (e.g., p1_*), manually set the package name and add the Python root directory (fusion-engine-client/python/) to the
# import search path to enable relative imports.
if __name__ == "__main__":
root_dir = os.path.normpath(os.path.join(os.path.abspath(os.path.dirname(__file__)), '../..'))
sys.path.insert(0, root_dir)
__package__ = os.path.dirname(__file__).replace('/', '.')


from ..analysis.analyzer import main as analyzer_main


Expand Down
8 changes: 8 additions & 0 deletions python/fusion_engine_client/applications/p1_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
import os
import sys

# If this application is being run directly as a script (e.g., python p1_*.py), rather than as a script installed by pip
# (e.g., p1_*), manually set the package name and add the Python root directory (fusion-engine-client/python/) to the
# import search path to enable relative imports.
if __name__ == "__main__":
root_dir = os.path.normpath(os.path.join(os.path.abspath(os.path.dirname(__file__)), '../..'))
sys.path.insert(0, root_dir)
__package__ = os.path.dirname(__file__).replace('/', '.')

from ..utils import trace as logging
from ..utils.argument_parser import ArgumentParser
from ..utils.log import extract_fusion_engine_log, find_log_file, CANDIDATE_LOG_FILES, DEFAULT_LOG_BASE_DIR
Expand Down
8 changes: 8 additions & 0 deletions python/fusion_engine_client/applications/p1_lband_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
import os
import sys

# If this application is being run directly as a script (e.g., python p1_*.py), rather than as a script installed by pip
# (e.g., p1_*), manually set the package name and add the Python root directory (fusion-engine-client/python/) to the
# import search path to enable relative imports.
if __name__ == "__main__":
root_dir = os.path.normpath(os.path.join(os.path.abspath(os.path.dirname(__file__)), '../..'))
sys.path.insert(0, root_dir)
__package__ = os.path.dirname(__file__).replace('/', '.')

from ..utils.trace import HighlightFormatter, BrokenPipeStreamHandler
from ..utils.time_range import TimeRange
from ..utils.log import locate_log, DEFAULT_LOG_BASE_DIR
Expand Down
9 changes: 9 additions & 0 deletions python/fusion_engine_client/applications/p1_print.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
#!/usr/bin/env python3

from collections import defaultdict
import os
import sys

# If this application is being run directly as a script (e.g., python p1_*.py), rather than as a script installed by pip
# (e.g., p1_*), manually set the package name and add the Python root directory (fusion-engine-client/python/) to the
# import search path to enable relative imports.
if __name__ == "__main__":
root_dir = os.path.normpath(os.path.join(os.path.abspath(os.path.dirname(__file__)), '../..'))
sys.path.insert(0, root_dir)
__package__ = os.path.dirname(__file__).replace('/', '.')

from ..messages import *
from ..parsers import MixedLogReader
from ..utils import trace as logging
Expand Down

0 comments on commit e2b48b1

Please sign in to comment.