From c8f98a3c592d85b2c5dedcace509cd77772d57d3 Mon Sep 17 00:00:00 2001 From: Jeffrey Phillips Freeman <jeffrey.freeman@syncleus.com> Date: Wed, 28 Sep 2016 14:41:22 -0400 Subject: [PATCH] Pulled configuration stage out into its own method. --- src/apex/cli.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/apex/cli.py b/src/apex/cli.py index 4bc8abd..72bb320 100644 --- a/src/apex/cli.py +++ b/src/apex/cli.py @@ -53,6 +53,8 @@ __license__ = 'Apache License, Version 2.0' __copyright__ = 'Copyright 2016, Syncleus, Inc. and contributors' __credits__ = [] +config = None +aprsis = None port_map = {} running = True plugin_modules = [] @@ -89,14 +91,8 @@ def find_config(config_paths, verbose): return None -@click.command(context_settings=dict(auto_envvar_prefix='APEX')) -@click.option('-c', - '--configfile', - type=click.Path(exists=True, file_okay=True, dir_okay=False, readable=True, resolve_path=True), - help='Configuration file for APEX.') -@click.option('-v', '--verbose', is_flag=True, help='Enables verbose mode.') -def main(verbose, configfile): - +def configure(configfile, verbose=False): + global config config = find_config(configfile, verbose) if config is None: echo_colorized_error('No apex configuration found, can not continue.') @@ -145,6 +141,7 @@ def main(verbose, configfile): port_map[port_name] = {'identifier': port_identifier, 'net': port_net, 'tnc': aprs_tnc, 'tnc_port': tnc_port} + global aprsis aprsis = None if config.has_section('APRS-IS'): aprsis_callsign = config.get('APRS-IS', 'callsign') @@ -157,6 +154,16 @@ def main(verbose, configfile): aprsis = apex.aprs.ReconnectingPacketBuffer(apex.aprs.IGate(aprsis_callsign, aprsis_password)) aprsis.connect(aprsis_server, int(aprsis_server_port)) + +@click.command(context_settings=dict(auto_envvar_prefix='APEX')) +@click.option('-c', + '--configfile', + type=click.Path(exists=True, file_okay=True, dir_okay=False, readable=True, resolve_path=True), + help='Configuration file for APEX.') +@click.option('-v', '--verbose', is_flag=True, help='Enables verbose mode.') +def main(verbose, configfile): + configure(configfile, verbose) + click.echo("Press ctrl + c at any time to exit") packet_cache = cachetools.TTLCache(10000, 5) -- GitLab