1
|
#!/usr/bin/env python
|
2
|
# -*- coding: utf-8 -*-
|
3
|
|
4
|
import configparser
|
5
|
import os
|
6
|
|
7
|
|
8
|
class ConfigReader(object):
|
9
|
|
10
|
def __init__(self, config_path="config.ini"):
|
11
|
if not os.path.exists(config_path):
|
12
|
raise FileNotFoundError(f"Configuration file '{config_path}' not found!")
|
13
|
|
14
|
self.config = configparser.ConfigParser()
|
15
|
self.config.read(config_path)
|
16
|
|
17
|
def _get_value(self, section, key, default=None):
|
18
|
try:
|
19
|
return self.config[section][key]
|
20
|
except KeyError:
|
21
|
if default is None:
|
22
|
raise KeyError(f"Key '{key}' not found in section '{section}' of configuration!")
|
23
|
return default
|
24
|
|
25
|
def getProjectedImageWidth(self):
|
26
|
try:
|
27
|
return int(self._get_value('settings', 'imageWidthPx'))
|
28
|
except ValueError:
|
29
|
raise ValueError("Value for 'imageWidthPx' is not a valid integer!")
|
30
|
|
31
|
def getDistanceBetweenProjectors(self):
|
32
|
return "Placeholder"
|
33
|
|
34
|
def getImageWidth(self):
|
35
|
try:
|
36
|
return int(self._get_value('settings', 'imageWidthCm'))
|
37
|
except ValueError:
|
38
|
raise ValueError("Value for 'imageWidthCm' is not a valid integer!")
|
39
|
|
40
|
def getImageHeight(self):
|
41
|
return "Placeholder"
|
42
|
|
43
|
def getImageName(self):
|
44
|
return self._get_value('settings', 'imagePath')
|
45
|
|
46
|
def getSide(self):
|
47
|
return self._get_value('settings', 'projectorSide')
|
48
|
|
49
|
def getGamma(self):
|
50
|
try:
|
51
|
return float(self._get_value('settings', 'gamma'))
|
52
|
except ValueError:
|
53
|
raise ValueError("Value for 'gamma' is not a valid float!")
|
54
|
|
55
|
if __name__ == "__main__":
|
56
|
try:
|
57
|
reader = ConfigReader()
|
58
|
print(reader.getImageName())
|
59
|
print(reader.getSide())
|
60
|
print(reader.getGamma())
|
61
|
print(reader.getImageWidth())
|
62
|
print(reader.getProjectedImageWidth())
|
63
|
except (FileNotFoundError, KeyError, ValueError) as e:
|
64
|
print(f"Error: {e}")
|