Skip to content

Commit ec02b46

Browse files
committed
Fixed some pep8 failures.
1 parent ab1f513 commit ec02b46

File tree

3 files changed

+95
-105
lines changed

3 files changed

+95
-105
lines changed

aprsd/cmds/listen.py

Lines changed: 56 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -13,39 +13,35 @@
1313
from loguru import logger
1414
from oslo_config import cfg
1515
from rich.console import Console
16-
from typing import Union
1716

1817
# local imports here
1918
import aprsd
2019
from aprsd import cli_helper, packets, plugin, threads, utils
2120
from aprsd.client import client_factory
2221
from aprsd.main import cli
2322
from aprsd.packets import collector as packet_collector
23+
from aprsd.packets import core, seen_list
2424
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
2925
from aprsd.packets.filter import PacketFilter
26+
from aprsd.packets.filters import dupe_filter, packet_type
3027
from aprsd.stats import collector
3128
from aprsd.threads import keepalive, rx
3229
from aprsd.threads import stats as stats_thread
3330
from aprsd.threads.aprsd import APRSDThread
34-
from aprsd.utils import singleton
3531

3632
# setup the global logger
3733
# log.basicConfig(level=log.DEBUG) # level=10
38-
LOG = logging.getLogger("APRSD")
34+
LOG = logging.getLogger('APRSD')
3935
CONF = cfg.CONF
4036
LOGU = logger
4137
console = Console()
4238

4339

4440
def signal_handler(sig, frame):
4541
threads.APRSDThreadList().stop_all()
46-
if "subprocess" not in str(frame):
42+
if 'subprocess' not in str(frame):
4743
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(
4945
datetime.datetime.now(),
5046
),
5147
)
@@ -60,14 +56,14 @@ def __init__(
6056
packet_queue,
6157
packet_filter=None,
6258
plugin_manager=None,
63-
enabled_plugins=[],
59+
enabled_plugins=None,
6460
log_packets=False,
6561
):
66-
super().__init__("ListenProcThread", packet_queue)
62+
super().__init__('ListenProcThread', packet_queue)
6763
self.packet_filter = packet_filter
6864
self.plugin_manager = plugin_manager
6965
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()}')
7167
self.log_packets = log_packets
7268

7369
def print_packet(self, packet):
@@ -85,35 +81,35 @@ class ListenStatsThread(APRSDThread):
8581
"""Log the stats from the PacketList."""
8682

8783
def __init__(self):
88-
super().__init__("PacketStatsLog")
84+
super().__init__('PacketStatsLog')
8985
self._last_total_rx = 0
9086
self.period = 31
9187

9288
def loop(self):
9389
if self.loop_count % self.period == 0:
9490
# log the stats every 10 seconds
9591
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'])
9995
rx_delta = total_rx - self._last_total_rx
100-
rate = rx_delta / self.period
96+
rate = rx_delta / self.period
10197

10298
# Log summary stats
10399
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>',
108104
)
109105
self._last_total_rx = total_rx
110106

111107
# 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)}'
114110
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>',
117113
)
118114

119115
time.sleep(1)
@@ -123,19 +119,19 @@ def loop(self):
123119
@cli.command()
124120
@cli_helper.add_options(cli_helper.common_options)
125121
@click.option(
126-
"--aprs-login",
127-
envvar="APRS_LOGIN",
122+
'--aprs-login',
123+
envvar='APRS_LOGIN',
128124
show_envvar=True,
129-
help="What callsign to send the message from.",
125+
help='What callsign to send the message from.',
130126
)
131127
@click.option(
132-
"--aprs-password",
133-
envvar="APRS_PASSWORD",
128+
'--aprs-password',
129+
envvar='APRS_PASSWORD',
134130
show_envvar=True,
135-
help="the APRS-IS password for APRS_LOGIN",
131+
help='the APRS-IS password for APRS_LOGIN',
136132
)
137133
@click.option(
138-
"--packet-filter",
134+
'--packet-filter',
139135
type=click.Choice(
140136
[
141137
packets.AckPacket.__name__,
@@ -154,35 +150,35 @@ def loop(self):
154150
),
155151
multiple=True,
156152
default=[],
157-
help="Filter by packet type",
153+
help='Filter by packet type',
158154
)
159155
@click.option(
160-
"--enable-plugin",
156+
'--enable-plugin',
161157
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.',
163159
)
164160
@click.option(
165-
"--load-plugins",
161+
'--load-plugins',
166162
default=False,
167163
is_flag=True,
168-
help="Load plugins as enabled in aprsd.conf ?",
164+
help='Load plugins as enabled in aprsd.conf ?',
169165
)
170166
@click.argument(
171-
"filter",
167+
'filter',
172168
nargs=-1,
173169
required=True,
174170
)
175171
@click.option(
176-
"--log-packets",
172+
'--log-packets',
177173
default=False,
178174
is_flag=True,
179-
help="Log incoming packets.",
175+
help='Log incoming packets.',
180176
)
181177
@click.option(
182-
"--enable-packet-stats",
178+
'--enable-packet-stats',
183179
default=False,
184180
is_flag=True,
185-
help="Enable packet stats periodic logging.",
181+
help='Enable packet stats periodic logging.',
186182
)
187183
@click.pass_context
188184
@cli_helper.process_standard_options
@@ -212,41 +208,41 @@ def listen(
212208

213209
if not aprs_login:
214210
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')
217213
ctx.exit()
218214

219215
if not aprs_password:
220216
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')
223219
ctx.exit()
224220

225221
# CONF.aprs_network.login = aprs_login
226222
# config["aprs"]["password"] = aprs_password
227223

228-
LOG.info(f"APRSD Listen Started version: {aprsd.__version__}")
224+
LOG.info(f'APRSD Listen Started version: {aprsd.__version__}')
229225

230226
CONF.log_opt_values(LOG, logging.DEBUG)
231227
collector.Collector()
232228

233229
# Try and load saved MsgTrack list
234-
LOG.debug("Loading saved MsgTrack object.")
230+
LOG.debug('Loading saved MsgTrack object.')
235231

236232
# Initialize the client factory and create
237233
# The correct client object ready for use
238234
# Make sure we have 1 client transport enabled
239235
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.')
241237
sys.exit(-1)
242238

243239
# Creates the client object
244-
LOG.info("Creating client connection")
240+
LOG.info('Creating client connection')
245241
aprs_client = client_factory.create()
246242
LOG.info(aprs_client)
247243
if not aprs_client.login_success:
248244
# 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}'
250246
LOG.error(msg)
251247
print(msg)
252248
sys.exit(-1)
@@ -263,16 +259,16 @@ def listen(
263259
# we don't want the dupe filter to run here.
264260
PacketFilter().unregister(dupe_filter.DupePacketFilter)
265261
if packet_filter:
266-
LOG.info("Enabling packet filtering for {packet_filter}")
262+
LOG.info('Enabling packet filtering for {packet_filter}')
267263
packet_type.PacketTypeFilter().set_allow_list(packet_filter)
268264
PacketFilter().register(packet_type.PacketTypeFilter)
269265
else:
270-
LOG.info("No packet filtering enabled.")
266+
LOG.info('No packet filtering enabled.')
271267

272268
pm = None
273269
if load_plugins:
274270
pm = plugin.PluginManager()
275-
LOG.info("Loading plugins")
271+
LOG.info('Loading plugins')
276272
pm.setup_plugins(load_help_plugin=False)
277273
elif enable_plugin:
278274
pm = plugin.PluginManager()
@@ -283,37 +279,36 @@ def listen(
283279
else:
284280
LOG.warning(
285281
"Not Loading any plugins use --load-plugins to load what's "
286-
"defined in the config file.",
282+
'defined in the config file.',
287283
)
288284

289285
if pm:
290286
for p in pm.get_plugins():
291-
LOG.info("Loaded plugin %s", p.__class__.__name__)
287+
LOG.info('Loaded plugin %s', p.__class__.__name__)
292288

293289
stats = stats_thread.APRSDStatsStoreThread()
294290
stats.start()
295291

296-
LOG.debug("Start APRSDRxThread")
292+
LOG.debug('Start APRSDRxThread')
297293
rx_thread = rx.APRSDRXThread(packet_queue=threads.packet_queue)
298294
rx_thread.start()
299295

300-
301-
LOG.debug("Create APRSDListenProcessThread")
296+
LOG.debug('Create APRSDListenProcessThread')
302297
listen_thread = APRSDListenProcessThread(
303298
packet_queue=threads.packet_queue,
304299
packet_filter=packet_filter,
305300
plugin_manager=pm,
306301
enabled_plugins=enable_plugin,
307302
log_packets=log_packets,
308303
)
309-
LOG.debug("Start APRSDListenProcessThread")
304+
LOG.debug('Start APRSDListenProcessThread')
310305
listen_thread.start()
311306
if enable_packet_stats:
312307
listen_stats = ListenStatsThread()
313308
listen_stats.start()
314309

315310
keepalive_thread.start()
316-
LOG.debug("keepalive Join")
311+
LOG.debug('keepalive Join')
317312
keepalive_thread.join()
318313
rx_thread.join()
319314
listen_thread.join()

aprsd/packets/filters/dupe_filter.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
11
import logging
2-
from typing import Union
2+
from typing import Union
33

44
from oslo_config import cfg
55

6-
from aprsd.packets import core
76
from aprsd import packets
8-
from aprsd.utils import trace
9-
7+
from aprsd.packets import core
108

119
CONF = cfg.CONF
12-
LOG = logging.getLogger("APRSD")
10+
LOG = logging.getLogger('APRSD')
1311

1412

1513
class DupePacketFilter:
1614
"""This is a packet filter to detect duplicate packets.
1715
1816
This Uses the PacketList object to see if a packet exists
19-
already. If it does exist in the PacketList, then we need to
17+
already. If it does exist in the PacketList, then we need to
2018
check the flag on the packet to see if it's been processed before.
21-
If the packet has been processed already within the allowed
19+
If the packet has been processed already within the allowed
2220
timeframe, then it's a dupe.
2321
"""
22+
2423
def filter(self, packet: type[core.Packet]) -> Union[type[core.Packet], None]:
25-
#LOG.debug(f"{self.__class__.__name__}.filter called for packet {packet}")
24+
# LOG.debug(f"{self.__class__.__name__}.filter called for packet {packet}")
2625
"""Filter a packet out if it's already been seen and processed."""
2726
if isinstance(packet, core.AckPacket):
2827
# We don't need to drop AckPackets, those should be
@@ -51,19 +50,19 @@ def filter(self, packet: type[core.Packet]) -> Union[type[core.Packet], None]:
5150
if not found:
5251
# We haven't seen this packet before, so we process it.
5352
return packet
54-
53+
5554
if not packet.processed:
5655
# We haven't processed this packet through the plugins.
5756
return packet
5857
elif packet.timestamp - found.timestamp < CONF.packet_dupe_timeout:
5958
# If the packet came in within N seconds of the
6059
# Last time seeing the packet, then we drop it as a dupe.
6160
LOG.warning(
62-
f"Packet {packet.from_call}:{packet.msgNo} already tracked, dropping."
61+
f'Packet {packet.from_call}:{packet.msgNo} already tracked, dropping.'
6362
)
6463
else:
6564
LOG.warning(
66-
f"Packet {packet.from_call}:{packet.msgNo} already tracked "
67-
f"but older than {CONF.packet_dupe_timeout} seconds. processing.",
65+
f'Packet {packet.from_call}:{packet.msgNo} already tracked '
66+
f'but older than {CONF.packet_dupe_timeout} seconds. processing.',
6867
)
6968
return packet

0 commit comments

Comments
 (0)