summaryrefslogtreecommitdiff
path: root/examples/read_conf.py
blob: 4f6bf5604675c5630a769458344919357caac42c (plain)
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
# Put root of repository in sys.path
# (Ordinarily you won't want to do this — this is only
#  needed to make this example work without pom_parser installed.)
from pathlib import Path
import sys
sys.path.append(str(Path(__file__).parent.parent))

import pom_parser

filename = 'examples/conf.pom' if len(sys.argv) < 2 else sys.argv[1]
try:
	# Load configuration from file
	conf = pom_parser.load_path(filename)
except pom_parser.Error as e:
	# Handle error due to invalid configuration file
	print('Parse error:\n' + str(e))
	sys.exit(1)

# Get value of key in configuration
indentation_type = conf.get('indentation-type')
if indentation_type is not None:
	# Key is set
	print('Indenting with', indentation_type)
else:
	# Key is not set
	print('No indentation type specified')