ogn-python/ogn/gateway/manage.py

49 wiersze
1.3 KiB
Python
Czysty Zwykły widok Historia

2015-11-19 22:17:12 +00:00
import socket
from ogn.gateway import ognGateway
2015-11-22 20:11:55 +00:00
from ogn.logger import logger
DB_URI = 'sqlite:///beacons.db'
from manager import Manager
manager = Manager()
2015-11-15 11:10:20 +00:00
@manager.command
def run(aprs_user="anon-dev"):
"""Run the aprs client."""
2015-11-22 20:11:55 +00:00
if len(aprs_user) < 3 or len(aprs_user) > 9:
print("aprs_user must be a string of 3-9 characters")
return
2015-11-19 22:17:12 +00:00
user_interrupted = False
gateway = ognGateway()
2015-11-19 22:17:12 +00:00
print("Connect to DB")
2015-11-22 20:11:55 +00:00
logger.info('Connect to DB')
gateway.connect_db()
2015-11-19 22:17:12 +00:00
while user_interrupted is False:
2015-11-22 20:11:55 +00:00
logger.info("Connect OGN gateway as {}".format(aprs_user))
2015-11-19 22:17:12 +00:00
gateway.connect(aprs_user)
try:
2015-11-22 20:11:55 +00:00
logger.info('Run gateway')
2015-11-19 22:17:12 +00:00
gateway.run()
except KeyboardInterrupt:
2015-11-22 20:11:55 +00:00
logger.error('User interrupted', exc_info=True)
2015-11-19 22:17:12 +00:00
user_interrupted = True
except BrokenPipeError:
2015-11-22 20:11:55 +00:00
logger.error('BrokenPipeError', exc_info=True)
2015-11-21 22:05:22 +00:00
except socket.error:
2015-11-22 20:11:55 +00:00
logger.error('Socket error', exc_info=True)
2015-11-19 22:17:12 +00:00
2015-11-22 20:11:55 +00:00
try:
logger.info('Close socket')
2015-11-21 22:05:22 +00:00
gateway.disconnect()
2015-11-22 20:11:55 +00:00
except OSError as e:
print('Socket close error: {}'.format(e.strerror))
logger.error('Socket close error', exc_info=True)
2015-11-19 22:17:12 +00:00
print("\nExit OGN gateway")