-
Notifications
You must be signed in to change notification settings - Fork 0
/
ParamValueStore.py
65 lines (49 loc) · 1.85 KB
/
ParamValueStore.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
#!/usr/bin/env python
##
# @package ParamValueStore This package contains the class that reads and stores the parameters values
# required for further calculation on the disk
#
import logging
from os import listdir, path
import simplejson as json
class ParamValueStore:
LOG = logging.getLogger( __name__ )
class __ParamValueStore:
def __init__( self ):
pass
## Path where the file containing the param values is stored on disk
FILE_PATH = '/fw/DataLogger/logs/value_store.json'
## Dictionary containing the contents read from the file
valueStore = {}
## Function to read the value file
#
def readParamValues( self ):
with open( self.FILE_PATH ) as f:
self.valueStore = json.load(f)
##
# Function to return the values dictionary
# @return config dictionary: Dictionary containing the stored values
#
def getValueStore( self ):
return self.valueStore
##
# Function to store the values dictionary on the disk
#
def storeValues( self, vs ):
try:
with open( self.FILE_PATH, 'w' ) as f:
json.dump( vs, f, indent=4 )
except Exception as e:
pass
## Singleton instance of the private __ParamValueStore class
instance = None
def __init__( self ):
if not ParamValueStore.instance:
ParamValueStore.instance = ParamValueStore.__ParamValueStore()
try:
ParamValueStore.instance.readParamValues()
except Exception as e:
self.LOG.error( 'Error reading the main configuration: %s', e )
# TODO: Figure out why it doesn't work without name argument
def __getattr__( self, name ):
return getattr( self.instance, name )