1234567891011121314151617181920212223 |
- #!/usr/bin/env python3
- import sys
- import configparser
- import io
-
- filename = sys.argv[1]
- section = sys.argv[2]
- variable = sys.argv[3]
-
-
- try:
- with open(filename, "r") as f:
- stream = io.StringIO()
- stream.write("[DEFAULT]\n")
- stream.write(f.read())
-
- cfg = configparser.ConfigParser(strict=False)
- cfg.read_string(stream.getvalue())
- sys.stdout.write(cfg.get(section, variable))
- exit(0)
- except:
- sys.stdout.write("")
- exit(1)
|