-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathconfig.py
71 lines (55 loc) · 1.54 KB
/
config.py
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# -*- coding: utf-8 -*-
"""
File for dealing with the configuration of rtl_osv21.py.
"""
import os
import re
__version__ = '0.1'
__all__ = ['CONFIG_FILE', 'loadConfig', '__version__', '__all__']
# Files
## Base path for the various files needed/generated by rlt_osv21.py
_BASE_PATH = os.path.dirname(os.path.abspath(__file__))
## Wunderground Configuration
CONFIG_FILE = os.path.join(_BASE_PATH, 'rtl_osv21.config')
def loadConfig(filename):
"""
Read in the configuration file and return a dictionary of the
parameters.
"""
# RegEx for parsing the configuration file lines
configRE = re.compile(r'\s*:\s*')
# Initial values
config = {'verbose': False,
'rtlsdr': None,
'duration': 90.0,
'retainData': False,
'useTimeout': False,
'includeIndoor': False,
'elevation': 0.0}
# Parse the file
try:
fh = open(filename, 'r')
for line in fh:
line = line.replace('\n', '')
## Skip blank lines
if len(line) < 3:
continue
## Skip comments
if line[0] == '#':
continue
## Update the dictionary
key, value = configRE.split(line, 1)
config[key] = value
fh.close()
# Float type conversion
config['duration'] = float(config['duration'])
config['elevation'] = float(config['elevation'])
# Boolean type conversions
config['verbose'] = bool(config['verbose'])
config['useTimeout'] = bool(config['useTimeout'])
config['retainData'] = bool(config['retainData'])
config['includeIndoor'] = bool(config['includeIndoor'])
except IOError:
pass
# Done
return config