Skip to content

Commit

Permalink
Change invocation pattern from Python script call to CLI command
Browse files Browse the repository at this point in the history
This patch carries out type revisions entailed by defining a `main()`
method.  Some of the global variables that were `if`-`__main__`-gated
needed to be moved outside of the `if` gate.  It seems as further
functions serving as subroutines get type-reviewed, `global` statements
will be needed.

Signed-off-by: Alex Nelson <[email protected]>
  • Loading branch information
ajnelson-nist committed Jan 7, 2025
1 parent f753f32 commit 394c64d
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 48 deletions.
12 changes: 8 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ SHELL := /bin/bash
all: \
check-examples
source venv/bin/activate \
&& python3 case_viewer/case_viewer.py \
&& case_viewer \
examples/WirelessNetworkConnection.json

.PHONY: \
Expand All @@ -28,19 +28,23 @@ all: \
.dry_run.done.log: \
.pytest.done.log
source venv/bin/activate \
&& python3 case_viewer/case_viewer.py \
&& case_viewer \
--dry-run \
examples/WirelessNetworkConnection.json
touch $@

.mypy.done.log: \
.mypy_strict.done.log: \
.venv.done.log \
case_viewer/case_viewer.py \
case_viewer/lib.py
source venv/bin/activate \
&& poetry run mypy \
--strict \
case_viewer/lib.py
touch $@

.mypy.done.log: \
.mypy_strict.done.log \
case_viewer/case_viewer.py
source venv/bin/activate \
&& poetry run mypy \
case_viewer/case_viewer.py
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ The application relies on Poetry as dependency manager, and all dependencies are

## Usage

> *CASEviewer.py JSON_INPUT*
> `case_viewer JSON_INPUT`
where:

* JSON_INPUT is the file to be processed.
* `JSON_INPUT` is the file to be processed.

For those with `make` available (e.g. in a POSIX command line environment), `make` will run enough from a fresh `git clone` to set up a demonstration call of the viewer against an [example JSON-LD file](examples/WirelessNetworkConnection.json).

Expand Down
90 changes: 48 additions & 42 deletions case_viewer/case_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ def buildDataCellSites(self, idObject):


def buildDataWirelessNet(self, idObject: str) -> list[list[str]]:
global wireless_net
tData = []
if idObject == ':WirelessNet':
self.headers = ["SSID", "BSID"]
Expand Down Expand Up @@ -1874,52 +1875,55 @@ def number_with_dots(n: Union[int, str]) -> str:
else:
raise TypeError('Parameter must be either integer or string')

if __name__ == '__main__':
#--- Gobal variables
chatMessages: list[dict[str, str]] = []
chatThreads: list[dict[str, str]] = []
#chatMessageAttachments = []
cookies: list[dict[str, str]] = []
geo_coordinates: list[dict[str, str]] = []
cell_sites: list[dict[str, str]] = []
bluetooths: list[dict[str, str]] = []
searched_items: list[dict[str, str]] = []
social_media_activities: list[dict[str, str]] = []
events: list[dict[str, str]] = []
relationAttachmentsTo: list[dict[str, str]] = []
relationMappedBy: list[dict[str, str]] = []
relationConnectedTo: list[dict[str, str]] = []
smsMessages: list[dict[str, str]] = []
accounts: list[dict[str, str]] = []
emailAddresses: list[dict[str, str]] = []
emailAccounts: list[dict[str, str]] = []
applications: list[dict[str, str]] = []
phoneCalls: list[dict[str, str]] = []
calendars: list[dict[str, str]] = []
emailMessages: list[dict[str, str]] = []
filesUncategorized: list[dict[str, str]] = []
filesImage: list[dict[str, str]] = []
filesAudio: list[dict[str, str]] = []
filesText: list[dict[str, str]] = []
filesPDF: list[dict[str, str]] = []
filesWord: list[dict[str, str]] = []
filesRTF: list[dict[str, str]] = []
filesVideo: list[dict[str, str]] = []
filesArchive: list[dict[str, str]] = []
filesDatabase: list[dict[str, str]] = []
filesApplication: list[dict[str, str]] = []
webURLs: list[dict[str, str]] = []
webURLHistory: list[dict[str, str]] = []
webSearchTerm: list[dict[str, str]] = []
webBookmark: list[dict[str, str]] = []
wireless_net: list[dict[str, str]] = []

tableData: list[list[str]] = [[]]
treeData: list[dict[str,str]] = []

def main():
C_GREEN = '\033[32m'
C_RED = '\033[31m'
C_BLACK = '\033[0m'
C_CYAN = '\033[36m'
EMPTY_DATA = "1900-01-01T00:00:00"

chatThreads: list[dict[str, str]] = []
chatMessages: list[dict[str, str]] = []
#chatMessageAttachments = []
cookies: list[dict[str, str]] = []
geo_coordinates: list[dict[str, str]] = []
cell_sites: list[dict[str, str]] = []
bluetooths: list[dict[str, str]] = []
searched_items: list[dict[str, str]] = []
social_media_activities: list[dict[str, str]] = []
events: list[dict[str, str]] = []
wireless_net: list[dict[str, str]] = []
relationAttachmentsTo: list[dict[str, str]] = []
relationMappedBy: list[dict[str, str]] = []
relationConnectedTo: list[dict[str, str]] = []
smsMessages: list[dict[str, str]] = []
accounts: list[dict[str, str]] = []
emailAddresses: list[dict[str, str]] = []
emailAccounts: list[dict[str, str]] = []
applications: list[dict[str, str]] = []
phoneCalls: list[dict[str, str]] = []
calendars: list[dict[str, str]] = []
emailMessages: list[dict[str, str]] = []
filesUncategorized: list[dict[str, str]] = []
filesImage: list[dict[str, str]] = []
filesAudio: list[dict[str, str]] = []
filesText: list[dict[str, str]] = []
filesPDF: list[dict[str, str]] = []
filesWord: list[dict[str, str]] = []
filesRTF: list[dict[str, str]] = []
filesVideo: list[dict[str, str]] = []
filesArchive: list[dict[str, str]] = []
filesDatabase: list[dict[str, str]] = []
filesApplication: list[dict[str, str]] = []
webURLs: list[dict[str, str]] = []
webURLHistory: list[dict[str, str]] = []
webSearchTerm: list[dict[str, str]] = []
webBookmark: list[dict[str, str]] = []

parser = argparse.ArgumentParser()
parser.add_argument("--debug", action="store_true")
parser.add_argument("--dry-run", action="store_true", help="Run application, exiting without initiating GUI.")
Expand All @@ -1940,7 +1944,7 @@ def number_with_dots(n: Union[int, str]) -> str:
json_obj = json.load(f)
if args.dry_run:
logging.info("Exiting dry run.")
sys.exit("Exit dry run.")
sys.exit(0)
app = QApplication([])
_widget=QWidget()
msgBox = QMessageBox()
Expand Down Expand Up @@ -2057,8 +2061,6 @@ def number_with_dots(n: Union[int, str]) -> str:
f.close()
print(C_CYAN + "\n\nEnd Observables processing!" + C_BLACK + "\n\n")

tableData: list[list[str]] = [[]]
treeData: list[dict[str,str]] = []
i = 1
totMessages = 0

Expand Down Expand Up @@ -2227,3 +2229,7 @@ def number_with_dots(n: Union[int, str]) -> str:
_view.setWindowTitle('Cyber items view - ' + args.input_jsonld + ' (n. Observables: ' + number_with_dots(nObjects) + ')')
_view.show()
sys.exit(app.exec_())


if __name__ == '__main__':
main()
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ argparse = "^1.4.0"
mypy = "^1"
pytest = "^8"

[tool.poetry.scripts]
case_viewer = "case_viewer.case_viewer:main"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

0 comments on commit 394c64d

Please sign in to comment.