diff --git a/src/apex/__init__.py b/src/apex/__init__.py index 4e0c3c322e33ff5810c76def4e95c90ce9b1a71f..8907edad46fb7d642de71ebccdd5744b94466a7a 100644 --- a/src/apex/__init__.py +++ b/src/apex/__init__.py @@ -7,6 +7,8 @@ from __future__ import absolute_import from __future__ import division from __future__ import print_function +from .util import * + __author__ = 'Jeffrey Phillips Freeman (WI2ARD)' __maintainer__ = 'Jeffrey Phillips Freeman (WI2ARD)' __email__ = 'jeffrey.freeman@syncleus.com' diff --git a/src/apex/cli.py b/src/apex/cli.py index 501cfa4a572da3035a74326a6ba3e872e4219e08..266bb2ca4227b4ef0dc779ba0975a5b6b1cf2071 100644 --- a/src/apex/cli.py +++ b/src/apex/cli.py @@ -30,6 +30,7 @@ import cachetools import click import apex.aprs +from .util import * from apex.kiss import constants as kissConstants from apex.plugin_loader import get_plugins from apex.plugin_loader import load_plugin @@ -209,16 +210,7 @@ def main(verbose, configfile): port = port_map[port_name] frame = port['tnc'].read() if frame: - formatted_aprs = '>'.join([click.style(frame['source'], fg='green'), click.style(frame['destination'], fg='blue')]) - paths = [] - for path in frame['path']: - paths.append(click.style(path, fg='cyan')) - paths = ','.join(paths) - if frame['path']: - formatted_aprs = ','.join([formatted_aprs, paths]) - formatted_aprs += ':' - formatted_aprs += frame['text'] - click.echo(click.style(port_name + ' << ', fg='magenta') + formatted_aprs) + print_colorized_frame(frame, port_name, True) for plugin_module in plugin_modules: something_read = True diff --git a/src/apex/plugins/apexparadigm/__init__.py b/src/apex/plugins/apexparadigm/__init__.py index 675a166391cd39a1611f4e3d36144745a0355307..57c2ecdb019768cfdd2344051dcc4ffa2aa58f62 100644 --- a/src/apex/plugins/apexparadigm/__init__.py +++ b/src/apex/plugins/apexparadigm/__init__.py @@ -7,6 +7,7 @@ import copy import re import click +import apex import apex.aprs.util __author__ = 'Jeffrey Phillips Freeman (WI2ARD)' @@ -90,7 +91,7 @@ class ApexParadigmPlugin(object): self.packet_cache[str(frame_hash)] = frame_hash port['tnc'].write(frame, port['tnc_port']) self.aprsis.write(frame) - click.echo(port_name + ' >> ' + apex.aprs.util.encode_frame(frame)) + apex.print_colorized_frame(frame, port_name, False) return else: if port['net'].startswith(node): @@ -101,7 +102,7 @@ class ApexParadigmPlugin(object): self.packet_cache[str(frame_hash)] = frame_hash port['tnc'].write(frame, port['tnc_port']) self.aprsis.write(frame) - click.echo(port_name + ' >> ' + apex.aprs.util.encode_frame(frame)) + apex.print_colorized_frame(frame, port_name, False) return if node == port_callsign and ssid == port_ssid: if ssid is 0: @@ -113,7 +114,7 @@ class ApexParadigmPlugin(object): self.packet_cache[str(frame_hash)] = frame_hash port['tnc'].write(frame, port['tnc_port']) self.aprsis.write(frame) - click.echo(port_name + ' >> ' + apex.aprs.util.encode_frame(frame)) + apex.print_colorized_frame(frame, port_name, False) return elif node == 'GATE' and port['net'].startswith('2M'): frame['path'] = frame['path'][:hop_index] + [recv_port['identifier'] + '*'] + [node + '*'] +\ @@ -123,7 +124,7 @@ class ApexParadigmPlugin(object): self.packet_cache[str(frame_hash)] = frame_hash port['tnc'].write(frame, port['tnc_port']) self.aprsis.write(frame) - click.echo(port_name + ' >> ' + apex.aprs.util.encode_frame(frame)) + apex.print_colorized_frame(frame, port_name, False) return if node.startswith('WIDE') and ssid > 1: frame['path'] = frame['path'][:hop_index] + [recv_port['identifier'] + '*'] +\ @@ -133,7 +134,7 @@ class ApexParadigmPlugin(object): self.packet_cache[str(frame_hash)] = frame_hash recv_port['tnc'].write(frame, recv_port['tnc_port']) self.aprsis.write(frame) - click.echo(recv_port_name + ' >> ' + apex.aprs.util.encode_frame(frame)) + apex.print_colorized_frame(frame, port_name, False) return elif node.startswith('WIDE') and ssid is 1: frame['path'] = frame['path'][:hop_index] + [recv_port['identifier'] + '*'] + [node + '*'] + frame['path'][hop_index+1:] @@ -142,7 +143,7 @@ class ApexParadigmPlugin(object): self.packet_cache[str(frame_hash)] = frame_hash recv_port['tnc'].write(frame, recv_port['tnc_port']) self.aprsis.write(frame) - click.echo(recv_port_name + ' >> ' + apex.aprs.util.encode_frame(frame)) + apex.print_colorized_frame(frame, port_name, False) return elif node.startswith('WIDE') and ssid is 0: frame['path'][hop_index] = node + '*' @@ -274,7 +275,7 @@ class ApexParadigmPlugin(object): self.packet_cache[str(frame_hash)] = frame_hash selected_hop['port']['tnc'].write(frame, selected_hop['port']['tnc_port']) self.aprsis.write(frame) - click.echo(selected_hop['port_name'] + ' >> ' + apex.aprs.util.encode_frame(frame)) + apex.print_colorized_frame(frame, port_name, False) return def stop(self): diff --git a/src/apex/plugins/beacon/__init__.py b/src/apex/plugins/beacon/__init__.py index 9dcbe0c56595fd53b9461eac27ce676a6aaa5098..dafbabcf5d4d24d765bd7e62ebd2e4b5700ea9b9 100644 --- a/src/apex/plugins/beacon/__init__.py +++ b/src/apex/plugins/beacon/__init__.py @@ -6,6 +6,7 @@ from __future__ import print_function import time import click +import apex import apex.aprs.util __author__ = 'Jeffrey Phillips Freeman (WI2ARD)' @@ -76,6 +77,6 @@ class BeaconPlugin(object): if frame_hash not in self.packet_cache.values(): self.packet_cache[str(frame_hash)] = frame_hash port['tnc'].write(beacon_frame, port['tnc_port']) - click.echo(port_name + ' >> ' + apex.aprs.util.encode_frame(beacon_frame)) + apex.print_colorized_frame(beacon_frame, port_name, False) else: time.sleep(1) diff --git a/src/apex/plugins/id/__init__.py b/src/apex/plugins/id/__init__.py index 7b240880266745f3c7716b3850eb1af398b364a5..362a686af213c13b47fc86422c510b9ba3f18a66 100644 --- a/src/apex/plugins/id/__init__.py +++ b/src/apex/plugins/id/__init__.py @@ -6,6 +6,7 @@ from __future__ import print_function import time import click +import apex import apex.aprs.util __author__ = 'Jeffrey Phillips Freeman (WI2ARD)' @@ -76,6 +77,6 @@ class IdPlugin(object): if frame_hash not in self.packet_cache.values(): self.packet_cache[str(frame_hash)] = frame_hash port['tnc'].write(id_frame, port['tnc_port']) - click.echo(port_name + ' >> ' + apex.aprs.util.encode_frame(id_frame)) + apex.print_colorized_frame(id_frame, port_name, False) else: time.sleep(1) diff --git a/src/apex/plugins/status/__init__.py b/src/apex/plugins/status/__init__.py index d88dfa8f8686d878ea5f521bde84dbfd35b92970..25f12cb53e374cb53b441937f8449df864f88922 100644 --- a/src/apex/plugins/status/__init__.py +++ b/src/apex/plugins/status/__init__.py @@ -5,6 +5,7 @@ from __future__ import print_function import time +import apex import apex.aprs.util __author__ = 'Jeffrey Phillips Freeman (WI2ARD)' @@ -78,6 +79,6 @@ class StatusPlugin(object): if frame_hash not in self.packet_cache.values(): self.packet_cache[str(frame_hash)] = frame_hash port['tnc'].write(status_frame, port['tnc_port']) - print(port_name + ' >> ' + apex.aprs.util.encode_frame(status_frame)) + apex.print_colorized_frame(status_frame, port_name, False) else: time.sleep(1) diff --git a/src/apex/util.py b/src/apex/util.py new file mode 100644 index 0000000000000000000000000000000000000000..5a115396e318cd671a2f2e5c18931589ffc865fb --- /dev/null +++ b/src/apex/util.py @@ -0,0 +1,22 @@ +# These imports are for python3 compatibility inside python2 +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import click + + +def print_colorized_frame(frame, port_name, direction_in): + formatted_aprs = '>'.join([click.style(frame['source'], fg='green'), click.style(frame['destination'], fg='blue')]) + paths = [] + for path in frame['path']: + paths.append(click.style(path, fg='cyan')) + paths = ','.join(paths) + if frame['path']: + formatted_aprs = ','.join([formatted_aprs, paths]) + formatted_aprs += ':' + formatted_aprs += frame['text'] + if direction_in: + click.echo(click.style(port_name + ' << ', fg='magenta') + formatted_aprs) + else: + click.echo(click.style(port_name + ' >> ', fg='magenta', bold=True, blink=True) + formatted_aprs)