-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
invalidThis doesn't seem rightThis doesn't seem right
Milestone
Description
It works and make sure the config file is loaded correctly, but there's too many "Try Excepts" without any comment.
I wrote it and I can't read sh!#
def load(self, config = ''):
if(config):
self.name = config
try:
with open(str(Config.dir) + '/' + str(self.name) + '.json') as config:
configjson = json.load(config)
loaded = 0
if(self == configjson):
config.close()
return True
if(self.log):
self.log << '\nConfig File: ' + json.dumps(configjson, indent = 4)
try:
self.dict['SleepTime'] = configjson['SleepTime']
loaded += 1
except KeyError:
if(self.log):
self.log.warn(self.name + '.json does not have a "SleepTime" key', False)
try:
self.dict['File'] = configjson['File']
loaded += 1
except KeyError:
if(self.log):
self.log.warn(self.name + '.json does not have a "File" key', False)
try:
self.dict['Directory'] = configjson['Directory']
loaded += 1
except KeyError:
if(self.log):
self.log.warn(self.name + '.json does not have a "Directory" key', False)
try:
self.dict['Filter'] = configjson['Filter']
loaded += 1
except KeyError:
if(self.log):
self.log.warn(self.name + '.json does not have a "Filter" key', False)
if(not loaded):
if(self.log):
self.log.error("Configuration Couldn't be Loaded", True)
elif(loaded < 4):
if(self.log):
self.log.warn('Configuration Partially Loaded, SleepTime: ' + str(self.sleepTime()) + 's.', True)
else:
if(self.log):
self.log.info('Configuration Loaded, SleepTime: ' + str(self.sleepTime()) + 's.', False)
config.close()
return loaded == 4
except FileNotFoundError:
if(self.log):
self.log.warn(self.name + '.json not found', False)
return False```
Metadata
Metadata
Assignees
Labels
invalidThis doesn't seem rightThis doesn't seem right
Projects
Status
Scheduled