multiplatform build
This commit is contained in:
@@ -49,7 +49,7 @@ def cleanup():
|
||||
devices = []
|
||||
|
||||
|
||||
def start_discovery(timeout=20.0):
|
||||
def start_discovery(timeout=20):
|
||||
cleanup()
|
||||
global devices
|
||||
print(f'Start discovery with timout {timeout}s...')
|
||||
|
||||
16
python/src/load_env.py
Normal file
16
python/src/load_env.py
Normal file
@@ -0,0 +1,16 @@
|
||||
# This is a quick and dirty hack since the ENVs from the docker run command won't show up in the main.py
|
||||
# I echo the output from the env command of a .env file, read and load it here into the os.environ.
|
||||
# https://stackoverflow.com/questions/78684481/python-wont-find-the-env-in-my-docker-container
|
||||
|
||||
|
||||
import os
|
||||
|
||||
|
||||
def load_env():
|
||||
if 'DOCKER' not in os.listdir('.'): return False
|
||||
with open(file='.env', mode='r') as file: ENV = file.readlines()
|
||||
for env in ENV:
|
||||
env = env.strip()
|
||||
key, value = env.split('=')
|
||||
os.environ[key] = value
|
||||
return True
|
||||
@@ -3,8 +3,9 @@ from log_data import log_to_json
|
||||
from discovery import start_discovery
|
||||
|
||||
|
||||
def start_loop(interval=60):
|
||||
def start_loop(interval=40, timeout=20):
|
||||
print(f"Starting loop with interval {interval}s")
|
||||
while True:
|
||||
devices = start_discovery()
|
||||
devices = start_discovery(timeout=timeout)
|
||||
log_to_json(devices)
|
||||
sleep(interval)
|
||||
|
||||
@@ -1,9 +1,25 @@
|
||||
import os
|
||||
from discovery import start_discovery
|
||||
from log_data import log_to_json
|
||||
from loop import start_loop
|
||||
from load_env import load_env
|
||||
|
||||
DOCKER = load_env()
|
||||
INTERVAL = 40
|
||||
TIMEOUT = 20
|
||||
|
||||
# devices = start_discovery()
|
||||
# log_to_json(devices)
|
||||
if DOCKER:
|
||||
print("Running in docker")
|
||||
interval = os.getenv('LOOP')
|
||||
timeout = os.getenv('TIMEOUT')
|
||||
|
||||
start_loop()
|
||||
try:INTERVAL = int(interval)
|
||||
except:pass
|
||||
|
||||
try:TIMEOUT = int(timeout)
|
||||
except:pass
|
||||
|
||||
start_loop(INTERVAL, TIMEOUT)
|
||||
|
||||
else:
|
||||
start_loop(interval=40)
|
||||
|
||||
Reference in New Issue
Block a user