ogn-python/ogn/gateway/manage.py

40 wiersze
886 B
Python
Czysty Zwykły widok Historia

2015-11-19 22:17:12 +00:00
import socket
from ogn.gateway import ognGateway
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-19 22:17:12 +00:00
user_interrupted = False
gateway = ognGateway()
2015-11-19 22:17:12 +00:00
print("Connect to DB")
gateway.connect_db()
2015-11-19 22:17:12 +00:00
while user_interrupted is False:
2015-11-21 22:05:22 +00:00
print("Connect OGN gateway as {}".format(aprs_user))
2015-11-19 22:17:12 +00:00
gateway.connect(aprs_user)
2015-11-21 22:05:22 +00:00
socket_open = True
2015-11-19 22:17:12 +00:00
try:
gateway.run()
except KeyboardInterrupt:
print("User interrupted")
user_interrupted = True
except BrokenPipeError:
print("BrokenPipeError")
2015-11-21 22:05:22 +00:00
except socket.error:
2015-11-19 22:17:12 +00:00
print("socket error")
2015-11-21 22:05:22 +00:00
socket_open = False
2015-11-19 22:17:12 +00:00
2015-11-21 22:05:22 +00:00
if socket_open:
gateway.disconnect()
2015-11-19 22:17:12 +00:00
print("\nExit OGN gateway")