diff --git a/code/iottb b/code/iottb new file mode 100755 index 0000000..359e541 Binary files /dev/null and b/code/iottb differ diff --git a/code/iottb-project/README.md b/code/iottb-project/README.md index ac7a312..7119594 100644 --- a/code/iottb-project/README.md +++ b/code/iottb-project/README.md @@ -10,23 +10,23 @@ poetry install --editable # or with pip pip install -e . ``` -Currently this is the recommended method. +Currently, this is the recommended method. Alternatively install with pip into any activated environment: ```bash pip install -r requirements.txt ``` -It is possible to make a single executable for you machine wich you can just put in your path using pyinstaller. +It is possible to make a single executable for you machine which you can just put in your path using pyinstaller. 1. Install pyinstaller ```bash pip install pyinstaller ``` 2. Make the executable ```bash -pyinstaller --onefile iottb/main.py +pyinstaller --onefile --name iottb --distpath ~/opt iottb/main.py ``` -To be able to run it as `iottb` rename it to `iottb` and put it somewhere on your PATH. -Currently this method has bugs, since some python standard library names do not seem to be compiled into the executable. +to be able to run it as `iottb` if `~/opt' is a directory on your PATH. +A executable which should be able to run on linux is included in the repo. ## Basic Invocation ## Configuration diff --git a/code/iottb-project/iottb/commands/add_device.py b/code/iottb-project/iottb/commands/add_device.py index a7ab0a2..52fb6ce 100644 --- a/code/iottb-project/iottb/commands/add_device.py +++ b/code/iottb-project/iottb/commands/add_device.py @@ -1,4 +1,5 @@ import json +import sys import click from pathlib import Path @@ -165,7 +166,7 @@ def add_device(device, db, guided): click.echo( f'To initialize the testbed in the default location run "iottb init-db"') click.echo('Exiting...') - exit() + sys.exit() # Ensure a device name was passed as argument if device == "": click.echo("Device name cannot be an empty string. Exiting...", lvl='w') @@ -181,19 +182,18 @@ def add_device(device, db, guided): logger.warning(f'Device directory {device_dir} already exists.') click.echo(f'Device {device} already exists in the database.') click.echo('Exiting...') - exit() + sys.exit() try: device_dir.mkdir() except OSError as e: logger.error(f'Error trying to create device {e}') click.echo('Exiting...') - exit() + sys.exit() # Step 4: Save metadata into device_dir metadata_path = device_dir / definitions.DEVICE_METADATA_FILE_NAME with metadata_path.open('w') as metadata_file: json.dump(device_metadata.__dict__, metadata_file, indent=4) click.echo(f'Successfully added device {device} to database') - logger.debug(f'Added device {device} to database { - database}. Full path of metadata {metadata_path}') + logger.debug(f'Added device {device} to database {database}. Full path of metadata {metadata_path}') logger.info(f'Metadata for {device} {device_metadata.print_attributes()}') diff --git a/code/iottb-project/iottb/commands/sniff.py b/code/iottb-project/iottb/commands/sniff.py index aaf277e..f998b40 100644 --- a/code/iottb-project/iottb/commands/sniff.py +++ b/code/iottb-project/iottb/commands/sniff.py @@ -3,6 +3,7 @@ import logging import os import re import subprocess +import sys import uuid from datetime import datetime from pathlib import Path @@ -280,7 +281,7 @@ def sniff(ctx, device, interface, print_pacno, ff, count, monitor_mode, print_ll click.prompt('Create metadata anyway?') else: click.echo('Aborting capture...') - exit() + sys.exit() end_time = datetime.now().strftime("%H:%M:%S") end = time() delta = end - start diff --git a/code/iottb-project/iottb/commands/testbed.py b/code/iottb-project/iottb/commands/testbed.py index 4e23d8c..ee55563 100644 --- a/code/iottb-project/iottb/commands/testbed.py +++ b/code/iottb-project/iottb/commands/testbed.py @@ -30,7 +30,7 @@ def init_db(ctx, dest, name, update_default): click.echo(f'A database {name} already exists.') logger.debug(f'DB {name} exists in {dest}') click.echo(f'Exiting...') - exit() + sys.exit() logger.debug(f'DB name {name} registered but does not exist.') if not dest: logger.info('No dest set, choosing default destination.') diff --git a/code/iottb-project/iottb/main.py b/code/iottb-project/iottb/main.py index 48ca9cf..393b2de 100644 --- a/code/iottb-project/iottb/main.py +++ b/code/iottb-project/iottb/main.py @@ -1,5 +1,4 @@ -import os -import shutil +import sys import click from pathlib import Path