13
13
from loguru import logger
14
14
from oslo_config import cfg
15
15
from rich .console import Console
16
- from typing import Union
17
16
18
17
# local imports here
19
18
import aprsd
20
19
from aprsd import cli_helper , packets , plugin , threads , utils
21
20
from aprsd .client import client_factory
22
21
from aprsd .main import cli
23
22
from aprsd .packets import collector as packet_collector
23
+ from aprsd .packets import core , seen_list
24
24
from aprsd .packets import log as packet_log
25
- from aprsd .packets import seen_list
26
- from aprsd .packets import core
27
- from aprsd .packets .filters import dupe_filter
28
- from aprsd .packets .filters import packet_type
29
25
from aprsd .packets .filter import PacketFilter
26
+ from aprsd .packets .filters import dupe_filter , packet_type
30
27
from aprsd .stats import collector
31
28
from aprsd .threads import keepalive , rx
32
29
from aprsd .threads import stats as stats_thread
33
30
from aprsd .threads .aprsd import APRSDThread
34
- from aprsd .utils import singleton
35
31
36
32
# setup the global logger
37
33
# log.basicConfig(level=log.DEBUG) # level=10
38
- LOG = logging .getLogger (" APRSD" )
34
+ LOG = logging .getLogger (' APRSD' )
39
35
CONF = cfg .CONF
40
36
LOGU = logger
41
37
console = Console ()
42
38
43
39
44
40
def signal_handler (sig , frame ):
45
41
threads .APRSDThreadList ().stop_all ()
46
- if " subprocess" not in str (frame ):
42
+ if ' subprocess' not in str (frame ):
47
43
LOG .info (
48
- " Ctrl+C, Sending all threads exit! Can take up to 10 seconds {}" .format (
44
+ ' Ctrl+C, Sending all threads exit! Can take up to 10 seconds {}' .format (
49
45
datetime .datetime .now (),
50
46
),
51
47
)
@@ -60,14 +56,14 @@ def __init__(
60
56
packet_queue ,
61
57
packet_filter = None ,
62
58
plugin_manager = None ,
63
- enabled_plugins = [] ,
59
+ enabled_plugins = None ,
64
60
log_packets = False ,
65
61
):
66
- super ().__init__ (" ListenProcThread" , packet_queue )
62
+ super ().__init__ (' ListenProcThread' , packet_queue )
67
63
self .packet_filter = packet_filter
68
64
self .plugin_manager = plugin_manager
69
65
if self .plugin_manager :
70
- LOG .info (f" Plugins { self .plugin_manager .get_message_plugins ()} " )
66
+ LOG .info (f' Plugins { self .plugin_manager .get_message_plugins ()} ' )
71
67
self .log_packets = log_packets
72
68
73
69
def print_packet (self , packet ):
@@ -85,35 +81,35 @@ class ListenStatsThread(APRSDThread):
85
81
"""Log the stats from the PacketList."""
86
82
87
83
def __init__ (self ):
88
- super ().__init__ (" PacketStatsLog" )
84
+ super ().__init__ (' PacketStatsLog' )
89
85
self ._last_total_rx = 0
90
86
self .period = 31
91
87
92
88
def loop (self ):
93
89
if self .loop_count % self .period == 0 :
94
90
# log the stats every 10 seconds
95
91
stats_json = collector .Collector ().collect ()
96
- stats = stats_json [" PacketList" ]
97
- total_rx = stats ["rx" ]
98
- packet_count = len (stats [" packets" ])
92
+ stats = stats_json [' PacketList' ]
93
+ total_rx = stats ['rx' ]
94
+ packet_count = len (stats [' packets' ])
99
95
rx_delta = total_rx - self ._last_total_rx
100
- rate = rx_delta / self .period
96
+ rate = rx_delta / self .period
101
97
102
98
# Log summary stats
103
99
LOGU .opt (colors = True ).info (
104
- f" <green>RX Rate: { rate :.2f} pps</green> "
105
- f" <yellow>Total RX: { total_rx } </yellow> "
106
- f" <red>RX Last { self .period } secs: { rx_delta } </red> "
107
- f" <white>Packets in PacketListStats: { packet_count } </white>" ,
100
+ f' <green>RX Rate: { rate :.2f} pps</green> '
101
+ f' <yellow>Total RX: { total_rx } </yellow> '
102
+ f' <red>RX Last { self .period } secs: { rx_delta } </red> '
103
+ f' <white>Packets in PacketListStats: { packet_count } </white>' ,
108
104
)
109
105
self ._last_total_rx = total_rx
110
106
111
107
# Log individual type stats
112
- for k , v in stats [" types" ].items ():
113
- thread_hex = f" fg { utils .hex_from_name (k )} "
108
+ for k , v in stats [' types' ].items ():
109
+ thread_hex = f' fg { utils .hex_from_name (k )} '
114
110
LOGU .opt (colors = True ).info (
115
- f" <{ thread_hex } >{ k :<15} </{ thread_hex } > "
116
- f" <blue>RX: { v ['rx' ]} </blue> <red>TX: { v ['tx' ]} </red>" ,
111
+ f' <{ thread_hex } >{ k :<15} </{ thread_hex } > '
112
+ f' <blue>RX: { v ["rx" ]} </blue> <red>TX: { v ["tx" ]} </red>' ,
117
113
)
118
114
119
115
time .sleep (1 )
@@ -123,19 +119,19 @@ def loop(self):
123
119
@cli .command ()
124
120
@cli_helper .add_options (cli_helper .common_options )
125
121
@click .option (
126
- " --aprs-login" ,
127
- envvar = " APRS_LOGIN" ,
122
+ ' --aprs-login' ,
123
+ envvar = ' APRS_LOGIN' ,
128
124
show_envvar = True ,
129
- help = " What callsign to send the message from." ,
125
+ help = ' What callsign to send the message from.' ,
130
126
)
131
127
@click .option (
132
- " --aprs-password" ,
133
- envvar = " APRS_PASSWORD" ,
128
+ ' --aprs-password' ,
129
+ envvar = ' APRS_PASSWORD' ,
134
130
show_envvar = True ,
135
- help = " the APRS-IS password for APRS_LOGIN" ,
131
+ help = ' the APRS-IS password for APRS_LOGIN' ,
136
132
)
137
133
@click .option (
138
- " --packet-filter" ,
134
+ ' --packet-filter' ,
139
135
type = click .Choice (
140
136
[
141
137
packets .AckPacket .__name__ ,
@@ -154,35 +150,35 @@ def loop(self):
154
150
),
155
151
multiple = True ,
156
152
default = [],
157
- help = " Filter by packet type" ,
153
+ help = ' Filter by packet type' ,
158
154
)
159
155
@click .option (
160
- " --enable-plugin" ,
156
+ ' --enable-plugin' ,
161
157
multiple = True ,
162
- help = " Enable a plugin. This is the name of the file in the plugins directory." ,
158
+ help = ' Enable a plugin. This is the name of the file in the plugins directory.' ,
163
159
)
164
160
@click .option (
165
- " --load-plugins" ,
161
+ ' --load-plugins' ,
166
162
default = False ,
167
163
is_flag = True ,
168
- help = " Load plugins as enabled in aprsd.conf ?" ,
164
+ help = ' Load plugins as enabled in aprsd.conf ?' ,
169
165
)
170
166
@click .argument (
171
- " filter" ,
167
+ ' filter' ,
172
168
nargs = - 1 ,
173
169
required = True ,
174
170
)
175
171
@click .option (
176
- " --log-packets" ,
172
+ ' --log-packets' ,
177
173
default = False ,
178
174
is_flag = True ,
179
- help = " Log incoming packets." ,
175
+ help = ' Log incoming packets.' ,
180
176
)
181
177
@click .option (
182
- " --enable-packet-stats" ,
178
+ ' --enable-packet-stats' ,
183
179
default = False ,
184
180
is_flag = True ,
185
- help = " Enable packet stats periodic logging." ,
181
+ help = ' Enable packet stats periodic logging.' ,
186
182
)
187
183
@click .pass_context
188
184
@cli_helper .process_standard_options
@@ -212,41 +208,41 @@ def listen(
212
208
213
209
if not aprs_login :
214
210
click .echo (ctx .get_help ())
215
- click .echo ("" )
216
- ctx .fail (" Must set --aprs-login or APRS_LOGIN" )
211
+ click .echo ('' )
212
+ ctx .fail (' Must set --aprs-login or APRS_LOGIN' )
217
213
ctx .exit ()
218
214
219
215
if not aprs_password :
220
216
click .echo (ctx .get_help ())
221
- click .echo ("" )
222
- ctx .fail (" Must set --aprs-password or APRS_PASSWORD" )
217
+ click .echo ('' )
218
+ ctx .fail (' Must set --aprs-password or APRS_PASSWORD' )
223
219
ctx .exit ()
224
220
225
221
# CONF.aprs_network.login = aprs_login
226
222
# config["aprs"]["password"] = aprs_password
227
223
228
- LOG .info (f" APRSD Listen Started version: { aprsd .__version__ } " )
224
+ LOG .info (f' APRSD Listen Started version: { aprsd .__version__ } ' )
229
225
230
226
CONF .log_opt_values (LOG , logging .DEBUG )
231
227
collector .Collector ()
232
228
233
229
# Try and load saved MsgTrack list
234
- LOG .debug (" Loading saved MsgTrack object." )
230
+ LOG .debug (' Loading saved MsgTrack object.' )
235
231
236
232
# Initialize the client factory and create
237
233
# The correct client object ready for use
238
234
# Make sure we have 1 client transport enabled
239
235
if not client_factory .is_client_enabled ():
240
- LOG .error (" No Clients are enabled in config." )
236
+ LOG .error (' No Clients are enabled in config.' )
241
237
sys .exit (- 1 )
242
238
243
239
# Creates the client object
244
- LOG .info (" Creating client connection" )
240
+ LOG .info (' Creating client connection' )
245
241
aprs_client = client_factory .create ()
246
242
LOG .info (aprs_client )
247
243
if not aprs_client .login_success :
248
244
# We failed to login, will just quit!
249
- msg = f" Login Failure: { aprs_client .login_failure } "
245
+ msg = f' Login Failure: { aprs_client .login_failure } '
250
246
LOG .error (msg )
251
247
print (msg )
252
248
sys .exit (- 1 )
@@ -263,16 +259,16 @@ def listen(
263
259
# we don't want the dupe filter to run here.
264
260
PacketFilter ().unregister (dupe_filter .DupePacketFilter )
265
261
if packet_filter :
266
- LOG .info (" Enabling packet filtering for {packet_filter}" )
262
+ LOG .info (' Enabling packet filtering for {packet_filter}' )
267
263
packet_type .PacketTypeFilter ().set_allow_list (packet_filter )
268
264
PacketFilter ().register (packet_type .PacketTypeFilter )
269
265
else :
270
- LOG .info (" No packet filtering enabled." )
266
+ LOG .info (' No packet filtering enabled.' )
271
267
272
268
pm = None
273
269
if load_plugins :
274
270
pm = plugin .PluginManager ()
275
- LOG .info (" Loading plugins" )
271
+ LOG .info (' Loading plugins' )
276
272
pm .setup_plugins (load_help_plugin = False )
277
273
elif enable_plugin :
278
274
pm = plugin .PluginManager ()
@@ -283,37 +279,36 @@ def listen(
283
279
else :
284
280
LOG .warning (
285
281
"Not Loading any plugins use --load-plugins to load what's "
286
- " defined in the config file." ,
282
+ ' defined in the config file.' ,
287
283
)
288
284
289
285
if pm :
290
286
for p in pm .get_plugins ():
291
- LOG .info (" Loaded plugin %s" , p .__class__ .__name__ )
287
+ LOG .info (' Loaded plugin %s' , p .__class__ .__name__ )
292
288
293
289
stats = stats_thread .APRSDStatsStoreThread ()
294
290
stats .start ()
295
291
296
- LOG .debug (" Start APRSDRxThread" )
292
+ LOG .debug (' Start APRSDRxThread' )
297
293
rx_thread = rx .APRSDRXThread (packet_queue = threads .packet_queue )
298
294
rx_thread .start ()
299
295
300
-
301
- LOG .debug ("Create APRSDListenProcessThread" )
296
+ LOG .debug ('Create APRSDListenProcessThread' )
302
297
listen_thread = APRSDListenProcessThread (
303
298
packet_queue = threads .packet_queue ,
304
299
packet_filter = packet_filter ,
305
300
plugin_manager = pm ,
306
301
enabled_plugins = enable_plugin ,
307
302
log_packets = log_packets ,
308
303
)
309
- LOG .debug (" Start APRSDListenProcessThread" )
304
+ LOG .debug (' Start APRSDListenProcessThread' )
310
305
listen_thread .start ()
311
306
if enable_packet_stats :
312
307
listen_stats = ListenStatsThread ()
313
308
listen_stats .start ()
314
309
315
310
keepalive_thread .start ()
316
- LOG .debug (" keepalive Join" )
311
+ LOG .debug (' keepalive Join' )
317
312
keepalive_thread .join ()
318
313
rx_thread .join ()
319
314
listen_thread .join ()
0 commit comments