コード例 #1
0
ファイル: manage.py プロジェクト: Turbo87/ogn-python
def run(aprs_user='******', 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()

    def process_beacon(beacon):
        session.add(beacon)
        session.commit()

    try:
        gateway.run(callback=process_beacon, autoreconnect=True)
    except KeyboardInterrupt:
        print('\nStop ogn gateway')

    gateway.disconnect()
    logging.shutdown()
コード例 #2
0
ファイル: test_ognGateway.py プロジェクト: Turbo87/ogn-python
 def test_disconnect(self, mock_socket):
     self.gw = ognGateway(aprs_user='******', aprs_filter='')
     self.gw.connect()
     self.gw.disconnect()
     self.gw.sock.shutdown.assert_called_once_with(0)
     self.gw.sock.close.assert_called_once_with()
コード例 #3
0
ファイル: test_ognGateway.py プロジェクト: Turbo87/ogn-python
 def test_initialisation(self):
     self.gw = ognGateway(aprs_user='******', aprs_filter='')
     self.assertEqual(self.gw.aprs_user, 'testuser')
     self.assertEqual(self.gw.aprs_filter, '')
コード例 #4
0
ファイル: test_ognGateway.py プロジェクト: Turbo87/ogn-python
 def test_connect(self, mock_socket):
     self.gw = ognGateway(aprs_user='******', aprs_filter='')
     self.gw.connect()
     self.gw.sock.send.assert_called_once_with('user testuser pass -1 vers {} {}\n'.format(APRS_APP_NAME, APRS_APP_VER).encode('ascii'))
     self.gw.sock.makefile.asser_called_once_with('rw')