-
Notifications
You must be signed in to change notification settings - Fork 21
/
weakargs.py
47 lines (38 loc) · 1.19 KB
/
weakargs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#
# standard argument parsing
#
import argparse
import sys
import weakaudio
import weakcat
import time
#
# set up for argument parsing, with standard arguments.
# caller can then optionally call parser.add_argument()
# for non-standard arguments, then weakargs.parse_args().
#
def stdparse(description):
parser = argparse.ArgumentParser(description=description)
parser.add_argument("-card", nargs=2, metavar=('CARD', 'CHAN'))
parser.add_argument("-cat", nargs=2, metavar=('TYPE', 'DEV'))
parser.add_argument("-levels", action='store_true')
parser.add_argument("-v", action='store_true')
def myerror(message):
parser.print_usage(sys.stderr)
weakaudio.usage()
weakcat.usage()
parser.exit(2, ('%s: error: %s\n') % (parser.prog, message))
parser.error = myerror
return parser
#
# parse, and standard post-parsing actions.
#
def parse_args(parser):
args = parser.parse_args()
# don't require -cat if the "card" is really a controllable
# radio itself.
if args.card != None and args.card[0] in [ "sdrip", "sdriq", "eb200", "sdrplay" ] and args.cat == None:
args.cat = args.card
if args.levels == True:
weakaudio.levels(args.card)
return args