1
0
mirror of https://github.com/craigerl/aprsd.git synced 2024-11-28 10:59:04 -05:00

Added argparse for cli options

This patch adds the argparser to collect the user/callsign
from the command line, so it doesn't have to be hard coded.

It can be passed on the command line or set
in an environment var
python aprsd.py --user KCAMEL1

or

export APRS_USER=KCAMEL1
python aprsd.py
This commit is contained in:
Walter A. Boring IV 2018-11-21 12:55:14 -08:00
parent 60fa3ffcd4
commit 8b61116fce
3 changed files with 44 additions and 2 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.pyc

View File

@ -19,7 +19,8 @@
# License GPLv2 # License GPLv2
# #
from fuzzyclock import fuzzy # python included libs
import argparse
import json import json
import urllib import urllib
import sys import sys
@ -33,12 +34,18 @@ from email.mime.text import MIMEText
import subprocess import subprocess
import datetime import datetime
import calendar import calendar
from imapclient import IMAPClient, SEEN
import email import email
import threading import threading
import signal import signal
import pprint import pprint
# external lib imports
from imapclient import IMAPClient, SEEN
# local imports here
from fuzzyclock import fuzzy
import utils
# localization, please edit: # localization, please edit:
HOST = "noam.aprs2.net" # north america tier2 servers round robin HOST = "noam.aprs2.net" # north america tier2 servers round robin
USER = "KM6XXX-9" # callsign of this aprs client with SSID USER = "KM6XXX-9" # callsign of this aprs client with SSID
@ -54,6 +61,24 @@ shortcuts = {
email_sent_dict = {} # message_number:time combos so we don't resend the same email in five mins {int:int} email_sent_dict = {} # message_number:time combos so we don't resend the same email in five mins {int:int}
ack_dict = {} # message_nubmer:ack combos so we stop sending a message after an ack from radio {int:int} ack_dict = {} # message_nubmer:ack combos so we stop sending a message after an ack from radio {int:int}
message_number = 0 # current aprs radio message number, increments for each message we send over rf {int} message_number = 0 # current aprs radio message number, increments for each message we send over rf {int}
# command line args
parser = argparse.ArgumentParser()
parser.add_argument("--user",
metavar="<user>",
default=utils.env("APRS_USER"),
help="The callsign of this ARPS client with SSID"
" Default=env[APRS_USER]")
args = parser.parse_args()
if not args.user:
print("Missing the aprs user")
parser.print_help()
parser.exit()
else:
USER = args.user
try: try:
tn = telnetlib.Telnet(HOST, 14580) tn = telnetlib.Telnet(HOST, 14580)
except Exception, e: except Exception, e:

16
utils.py Normal file
View File

@ -0,0 +1,16 @@
"""Utilities and helper functions."""
import os
import pprint
import sys
def env(*vars, **kwargs):
"""This returns the first environment variable set.
if none are non-empty, defaults to '' or keyword arg default
"""
for v in vars:
value = os.environ.get(v, None)
if value:
return value
return kwargs.get('default', '')