From 5717504f1172c863e01e724afe1b5918fca64455 Mon Sep 17 00:00:00 2001 From: "Walter A. Boring IV" Date: Wed, 21 Nov 2018 15:20:11 -0800 Subject: [PATCH 1/4] Added reading of a config file This patch adds support to read a ~/.aprsd/config.yml file. If one doesn't exist, it puts out an example yaml string to stdout that can be copied into a file and edited. Since this patch adds a new external requirement (pyyaml) you need to re-install the app for dev with pip install -e . --- aprsd/main.py | 6 +++++- aprsd/utils.py | 32 ++++++++++++++++++++++++++++++++ requirements.txt | 1 + 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/aprsd/main.py b/aprsd/main.py index 5192c33..8539154 100644 --- a/aprsd/main.py +++ b/aprsd/main.py @@ -43,7 +43,7 @@ import pprint from imapclient import IMAPClient, SEEN # local imports here -from fuzzyclock import fuzzy +from aprsd.fuzzyclock import fuzzy import utils # localization, please edit: @@ -107,6 +107,10 @@ else: BASECALLSIGN = args.callsign +# Now read the ~/.aprds/config.yml +config = utils.get_config() +shortcuts = config['shortcuts'] + try: tn = telnetlib.Telnet(HOST, 14580) except Exception, e: diff --git a/aprsd/utils.py b/aprsd/utils.py index c51b982..0665297 100644 --- a/aprsd/utils.py +++ b/aprsd/utils.py @@ -3,7 +3,27 @@ import os import pprint import sys +import yaml +# an example of what should be in the ~/.aprsd/config.yml +example_config = ''' +shortcuts: + 'aa': '5551239999@vtext.com' + 'cl': 'craiglamparter@somedomain.org' + 'wb': '555309@vtext.com' + +smtp: + login: something + password: some lame password + +imap: + login: imapuser + password: something dumb + +ham: + callsign: something + basename: somebasename +''' def env(*vars, **kwargs): """This returns the first environment variable set. @@ -14,3 +34,15 @@ def env(*vars, **kwargs): if value: return value return kwargs.get('default', '') + + +def get_config(): + """This tries to read the yaml config from ~/.aprsd/config.yml.""" + config_file = os.path.expanduser("~/.aprsd/config.yml") + if os.path.exists(config_file): + with open(config_file, "r") as stream: + config = yaml.load(stream) + return config + else: + print("%s is missing, please create a config file" % config_file) + print("example config is\n %s" % example_config) diff --git a/requirements.txt b/requirements.txt index bd92dae..c171ede 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ pbr imapclient +pyyaml From e3964c5426245e71a9689196b9e0402fdab376d5 Mon Sep 17 00:00:00 2001 From: "Walter A. Boring IV" Date: Wed, 21 Nov 2018 15:23:06 -0800 Subject: [PATCH 2/4] added exit if missing config file --- aprsd/utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/aprsd/utils.py b/aprsd/utils.py index 0665297..5dd4953 100644 --- a/aprsd/utils.py +++ b/aprsd/utils.py @@ -46,3 +46,4 @@ def get_config(): else: print("%s is missing, please create a config file" % config_file) print("example config is\n %s" % example_config) + sys.exit(-1) From 8d1d2933e886abb9b2ce72d364413b86917f7e63 Mon Sep 17 00:00:00 2001 From: "Walter A. Boring IV" Date: Wed, 21 Nov 2018 15:25:31 -0800 Subject: [PATCH 3/4] added test to ensure shortcuts in config.yml This patch adds a simple test to ensure that 'shortcuts' is part of the config.yml --- aprsd/main.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/aprsd/main.py b/aprsd/main.py index 8539154..d4e2451 100644 --- a/aprsd/main.py +++ b/aprsd/main.py @@ -109,7 +109,11 @@ else: # Now read the ~/.aprds/config.yml config = utils.get_config() -shortcuts = config['shortcuts'] +if 'shortcuts' in config: + shortcuts = config['shortcuts'] +else: + print("missing 'shortcuts' section of config.yml") + sys.exit(-1) try: tn = telnetlib.Telnet(HOST, 14580) From 4eff52f24589852404f7a6cd1581fd58c110ae43 Mon Sep 17 00:00:00 2001 From: "Walter A. Boring IV" Date: Wed, 21 Nov 2018 15:27:35 -0800 Subject: [PATCH 4/4] updated README for install and usage instructions --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3c49d4a..4c0c593 100644 --- a/README.md +++ b/README.md @@ -28,9 +28,14 @@ email server, and associated logins, passwords. search for "yourdomain", "password". Search for "shortcuts" to setup email aliases as well. +Installation: +``` +pip install aprsd +``` + Example usage: ``` -./aprsd.py +aprsd -h ``` Example output: