Import sys and modify exit invocation to be able to create single file executable of iottb
This commit is contained in:
parent
78c155208e
commit
c6c8cfb223
BIN
code/iottb
Executable file
BIN
code/iottb
Executable file
Binary file not shown.
@ -10,23 +10,23 @@ poetry install --editable
|
|||||||
# or with pip
|
# or with pip
|
||||||
pip install -e .
|
pip install -e .
|
||||||
```
|
```
|
||||||
Currently this is the recommended method.
|
Currently, this is the recommended method.
|
||||||
Alternatively install with pip into any activated environment:
|
Alternatively install with pip into any activated environment:
|
||||||
```bash
|
```bash
|
||||||
pip install -r requirements.txt
|
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
|
1. Install pyinstaller
|
||||||
```bash
|
```bash
|
||||||
pip install pyinstaller
|
pip install pyinstaller
|
||||||
```
|
```
|
||||||
2. Make the executable
|
2. Make the executable
|
||||||
```bash
|
```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.
|
to be able to run it as `iottb` if `~/opt' is a directory on your PATH.
|
||||||
Currently this method has bugs, since some python standard library names do not seem to be compiled into the executable.
|
A executable which should be able to run on linux is included in the repo.
|
||||||
## Basic Invocation
|
## Basic Invocation
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import json
|
import json
|
||||||
|
import sys
|
||||||
|
|
||||||
import click
|
import click
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@ -165,7 +166,7 @@ def add_device(device, db, guided):
|
|||||||
click.echo(
|
click.echo(
|
||||||
f'To initialize the testbed in the default location run "iottb init-db"')
|
f'To initialize the testbed in the default location run "iottb init-db"')
|
||||||
click.echo('Exiting...')
|
click.echo('Exiting...')
|
||||||
exit()
|
sys.exit()
|
||||||
# Ensure a device name was passed as argument
|
# Ensure a device name was passed as argument
|
||||||
if device == "":
|
if device == "":
|
||||||
click.echo("Device name cannot be an empty string. Exiting...", lvl='w')
|
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.')
|
logger.warning(f'Device directory {device_dir} already exists.')
|
||||||
click.echo(f'Device {device} already exists in the database.')
|
click.echo(f'Device {device} already exists in the database.')
|
||||||
click.echo('Exiting...')
|
click.echo('Exiting...')
|
||||||
exit()
|
sys.exit()
|
||||||
try:
|
try:
|
||||||
device_dir.mkdir()
|
device_dir.mkdir()
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
logger.error(f'Error trying to create device {e}')
|
logger.error(f'Error trying to create device {e}')
|
||||||
click.echo('Exiting...')
|
click.echo('Exiting...')
|
||||||
exit()
|
sys.exit()
|
||||||
|
|
||||||
# Step 4: Save metadata into device_dir
|
# Step 4: Save metadata into device_dir
|
||||||
metadata_path = device_dir / definitions.DEVICE_METADATA_FILE_NAME
|
metadata_path = device_dir / definitions.DEVICE_METADATA_FILE_NAME
|
||||||
with metadata_path.open('w') as metadata_file:
|
with metadata_path.open('w') as metadata_file:
|
||||||
json.dump(device_metadata.__dict__, metadata_file, indent=4)
|
json.dump(device_metadata.__dict__, metadata_file, indent=4)
|
||||||
click.echo(f'Successfully added device {device} to database')
|
click.echo(f'Successfully added device {device} to database')
|
||||||
logger.debug(f'Added device {device} to database {
|
logger.debug(f'Added device {device} to database {database}. Full path of metadata {metadata_path}')
|
||||||
database}. Full path of metadata {metadata_path}')
|
|
||||||
logger.info(f'Metadata for {device} {device_metadata.print_attributes()}')
|
logger.info(f'Metadata for {device} {device_metadata.print_attributes()}')
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import logging
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import sys
|
||||||
import uuid
|
import uuid
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from pathlib import Path
|
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?')
|
click.prompt('Create metadata anyway?')
|
||||||
else:
|
else:
|
||||||
click.echo('Aborting capture...')
|
click.echo('Aborting capture...')
|
||||||
exit()
|
sys.exit()
|
||||||
end_time = datetime.now().strftime("%H:%M:%S")
|
end_time = datetime.now().strftime("%H:%M:%S")
|
||||||
end = time()
|
end = time()
|
||||||
delta = end - start
|
delta = end - start
|
||||||
|
|||||||
@ -30,7 +30,7 @@ def init_db(ctx, dest, name, update_default):
|
|||||||
click.echo(f'A database {name} already exists.')
|
click.echo(f'A database {name} already exists.')
|
||||||
logger.debug(f'DB {name} exists in {dest}')
|
logger.debug(f'DB {name} exists in {dest}')
|
||||||
click.echo(f'Exiting...')
|
click.echo(f'Exiting...')
|
||||||
exit()
|
sys.exit()
|
||||||
logger.debug(f'DB name {name} registered but does not exist.')
|
logger.debug(f'DB name {name} registered but does not exist.')
|
||||||
if not dest:
|
if not dest:
|
||||||
logger.info('No dest set, choosing default destination.')
|
logger.info('No dest set, choosing default destination.')
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
import os
|
import sys
|
||||||
import shutil
|
|
||||||
|
|
||||||
import click
|
import click
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user