settings: Catch any exceptions, regardless of their stupidity.
This commit is contained in:
parent
b4642a4ba1
commit
6dddaa9940
1 changed files with 9 additions and 9 deletions
|
@ -4,19 +4,19 @@ class Settings:
|
|||
"""
|
||||
This is the class that reads JSON formatted settings files, and
|
||||
returns the values back to whatever requested them.
|
||||
|
||||
|
||||
This class should be generated in the OTPBase, and then accessed
|
||||
via base.settings
|
||||
"""
|
||||
|
||||
|
||||
def __init__(self):
|
||||
self.fileName = 'settings.json'
|
||||
try:
|
||||
with open(self.fileName, 'r') as file:
|
||||
self.settings = json.load(file)
|
||||
except IOError:
|
||||
except:
|
||||
self.settings = {}
|
||||
|
||||
|
||||
def updateSetting(self, type, attribute, value):
|
||||
"""
|
||||
Update the json file with the new data specified.
|
||||
|
@ -26,13 +26,13 @@ class Settings:
|
|||
self.settings[type] = {}
|
||||
self.settings[type][attribute] = value
|
||||
json.dump(self.settings, file)
|
||||
|
||||
|
||||
def getOption(self, type, attribute, default):
|
||||
"""
|
||||
Generic method to fetch the saved configuration settings.
|
||||
"""
|
||||
return self.settings.get(type, {}).get(attribute, default)
|
||||
|
||||
|
||||
def getString(self, type, attribute, default=''):
|
||||
"""
|
||||
Fetch a string type from the json file, but use default if it
|
||||
|
@ -43,7 +43,7 @@ class Settings:
|
|||
return value
|
||||
else:
|
||||
return default
|
||||
|
||||
|
||||
def getInt(self, type, attribute, default=0):
|
||||
"""
|
||||
Fetch a integer type from the json file, but use default if it
|
||||
|
@ -54,7 +54,7 @@ class Settings:
|
|||
return int(value)
|
||||
else:
|
||||
return default
|
||||
|
||||
|
||||
def getBool(self, type, attribute, default=False):
|
||||
"""
|
||||
Fetch a boolean type from the json file, but use default if it
|
||||
|
@ -65,7 +65,7 @@ class Settings:
|
|||
return value
|
||||
else:
|
||||
return default
|
||||
|
||||
|
||||
def getList(self, type, attribute, default=[], expectedLength=2):
|
||||
"""
|
||||
Fetch a list type from the json file, but use default if it
|
||||
|
|
Loading…
Reference in a new issue