Ticket #13487: test_systemd_journal_argparse.py

File test_systemd_journal_argparse.py, 1.1 KB (added by rcrdnalor, 5 years ago)
Line 
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
15import sys
16from MythTV import MythLog
17from argparse import ArgumentParser
18
19parser = ArgumentParser(usage=" %(prog)s [options]")
20
21parser.add_argument('--my_option', type=str, action="store", dest="my_option",
22            help="Specify 'my special option'.")
23
24MythLog.loadArgParse(parser)
25
26try:
27    args = parser.parse_args()
28except:
29    #parser.print_help()
30    sys.exit(1)
31
32if args.verbose:
33    if args.verbose == 'help':
34        print(MythLog.helptext)
35        sys.exit(0)
36
37m = MythLog(module = 'test_systemd_journal_logging')
38
39m.log(MythLog.GENERAL, MythLog.DEBUG, 'test my_option: %s' %args.my_option)
40
41"""
42The command 'journalctl -f' shows:
43test_systemd_journal_argparse.py[6043]: [test_systemd_journal_logging]: test my_option: barfoobar
44"""
45