conf: Replace deprecated OptionParser with ArgumentParser
This commit is contained in:
parent
a5b3c62091
commit
eea58222d5
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
#
|
#
|
||||||
# Copyright (C) 2014-2017 Tobias Brunner
|
# Copyright (C) 2014-2019 Tobias Brunner
|
||||||
# HSR Hochschule fuer Technik Rapperswil
|
# HSR Hochschule fuer Technik Rapperswil
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify it
|
# This program is free software; you can redistribute it and/or modify it
|
||||||
|
@ -67,7 +67,7 @@ charon.filelog./var/log/daemon\.log {}
|
||||||
import sys
|
import sys
|
||||||
import re
|
import re
|
||||||
from textwrap import TextWrapper
|
from textwrap import TextWrapper
|
||||||
from optparse import OptionParser
|
from argparse import ArgumentParser
|
||||||
from functools import cmp_to_key
|
from functools import cmp_to_key
|
||||||
|
|
||||||
class ConfigOption:
|
class ConfigOption:
|
||||||
|
@ -344,21 +344,22 @@ class ManFormatter:
|
||||||
else:
|
else:
|
||||||
self.__format_option(option)
|
self.__format_option(option)
|
||||||
|
|
||||||
options = OptionParser(usage = "Usage: %prog [options] file1 file2\n\n"
|
args = ArgumentParser()
|
||||||
"If no filenames are provided the input is read from stdin.")
|
args.add_argument('file', nargs='*',
|
||||||
options.add_option("-f", "--format", dest="format", type="choice", choices=["conf", "man"],
|
help="files to process, omit to read input from stdin")
|
||||||
help="output format: conf, man [default: %default]", default="conf")
|
args.add_argument("-f", "--format", dest="format", choices=["conf", "man"],
|
||||||
options.add_option("-r", "--root", dest="root", metavar="NAME",
|
help="output format (default: %(default)s)", default="conf")
|
||||||
help="root section of which options are printed, "
|
args.add_argument("-r", "--root", dest="root", metavar="NAME",
|
||||||
"if not found everything is printed")
|
help="root section of which options are printed; everything"
|
||||||
options.add_option("-n", "--nosort", action="store_false", dest="sort",
|
"is printed if not found")
|
||||||
|
args.add_argument("-n", "--nosort", action="store_false", dest="sort",
|
||||||
default=True, help="do not sort sections alphabetically")
|
default=True, help="do not sort sections alphabetically")
|
||||||
|
|
||||||
(opts, args) = options.parse_args()
|
opts = args.parse_args()
|
||||||
|
|
||||||
parser = Parser(opts.sort)
|
parser = Parser(opts.sort)
|
||||||
if len(args):
|
if len(opts.file):
|
||||||
for filename in args:
|
for filename in opts.file:
|
||||||
try:
|
try:
|
||||||
with open(filename, 'r') as file:
|
with open(filename, 'r') as file:
|
||||||
parser.parse(file)
|
parser.parse(file)
|
||||||
|
|
Loading…
Reference in New Issue