ogn-python/ogn/gateway/manage.py

43 wiersze
1.2 KiB
Python

import logging
from ogn.gateway.client import ognGateway
from ogn.gateway.process import process_beacon
from manager import Manager
manager = Manager()
logging_formatstr = '%(asctime)s - %(levelname).4s - %(name)s - %(message)s'
log_levels = ['CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG']
@manager.command
def run(aprs_user='anon-dev', logfile='main.log', loglevel='INFO'):
"""Run the aprs client."""
# User input validation
if len(aprs_user) < 3 or len(aprs_user) > 9:
print('aprs_user must be a string of 3-9 characters.')
return
if loglevel not in log_levels:
print('loglevel must be an element of {}.'.format(log_levels))
return
# Enable logging
log_handlers = [logging.StreamHandler()]
if logfile:
log_handlers.append(logging.FileHandler(logfile))
logging.basicConfig(format=logging_formatstr, level=loglevel, handlers=log_handlers)
print('Start ogn gateway')
gateway = ognGateway(aprs_user)
gateway.connect()
try:
gateway.run(callback=process_beacon, autoreconnect=True)
except KeyboardInterrupt:
print('\nStop ogn gateway')
gateway.disconnect()
logging.shutdown()