1 | #!/usr/bin/env python |
---|
2 | # -*- coding: utf-8 -*- |
---|
3 | |
---|
4 | # file: test_systemd_journal_argparse.py |
---|
5 | |
---|
6 | # call with: |
---|
7 | # --loglevel debug --verbose all --systemd-journal --syslog user --my_option barfoobar |
---|
8 | # --loglevel debug --verbose all --systemd-journal --my_option barfoobar |
---|
9 | # --help |
---|
10 | # --verbose help |
---|
11 | # |
---|
12 | # watch journal with |
---|
13 | # $ journalctl -f |
---|
14 | |
---|
15 | import sys |
---|
16 | from MythTV import MythLog |
---|
17 | from argparse import ArgumentParser |
---|
18 | |
---|
19 | parser = ArgumentParser(usage=" %(prog)s [options]") |
---|
20 | |
---|
21 | parser.add_argument('--my_option', type=str, action="store", dest="my_option", |
---|
22 | help="Specify 'my special option'.") |
---|
23 | |
---|
24 | MythLog.loadArgParse(parser) |
---|
25 | |
---|
26 | try: |
---|
27 | args = parser.parse_args() |
---|
28 | except: |
---|
29 | #parser.print_help() |
---|
30 | sys.exit(1) |
---|
31 | |
---|
32 | if args.verbose: |
---|
33 | if args.verbose == 'help': |
---|
34 | print(MythLog.helptext) |
---|
35 | sys.exit(0) |
---|
36 | |
---|
37 | m = MythLog(module = 'test_systemd_journal_logging') |
---|
38 | |
---|
39 | m.log(MythLog.GENERAL, MythLog.DEBUG, 'test my_option: %s' %args.my_option) |
---|
40 | |
---|
41 | """ |
---|
42 | The command 'journalctl -f' shows: |
---|
43 | test_systemd_journal_argparse.py[6043]: [test_systemd_journal_logging]: test my_option: barfoobar |
---|
44 | """ |
---|
45 | |
---|