Merge pull request #1300 from MycroftAI/feature/meta-crashes
Protect against bad settingsmeta.jsonpull/1309/head
commit
0bbb05ddd2
|
@ -101,16 +101,19 @@ class SkillSettings(dict):
|
||||||
self.load_skill_settings()
|
self.load_skill_settings()
|
||||||
|
|
||||||
# TODO: break this up into two classes
|
# TODO: break this up into two classes
|
||||||
def initiatlize_remote_settings(self):
|
def initialize_remote_settings(self):
|
||||||
""" initializes the remote settings to the server """
|
""" initializes the remote settings to the server """
|
||||||
# if settingsmeta.json exists
|
# if settingsmeta.json exists (and is valid)
|
||||||
# this block of code is a control flow for
|
# this block of code is a control flow for
|
||||||
# different scenarios that may arises with settingsmeta
|
# different scenarios that may arises with settingsmeta
|
||||||
|
settings_meta = self._load_settings_meta()
|
||||||
|
if not settings_meta:
|
||||||
|
return
|
||||||
|
|
||||||
self._device_identity = self.api.identity.uuid
|
self._device_identity = self.api.identity.uuid
|
||||||
self._api_path = "/" + self._device_identity + "/skill"
|
self._api_path = "/" + self._device_identity + "/skill"
|
||||||
self._user_identity = self.api.get()['user']['uuid']
|
self._user_identity = self.api.get()['user']['uuid']
|
||||||
LOG.info("settingsmeta.json exist for {}".format(self.name))
|
LOG.info("settingsmeta.json exist for {}".format(self.name))
|
||||||
settings_meta = self._load_settings_meta()
|
|
||||||
hashed_meta = self._get_meta_hash(str(settings_meta))
|
hashed_meta = self._get_meta_hash(str(settings_meta))
|
||||||
skill_settings = self._request_other_settings(hashed_meta)
|
skill_settings = self._request_other_settings(hashed_meta)
|
||||||
# if hash is new then there is a diff version of settingsmeta
|
# if hash is new then there is a diff version of settingsmeta
|
||||||
|
@ -158,9 +161,14 @@ class SkillSettings(dict):
|
||||||
def _load_settings_meta(self):
|
def _load_settings_meta(self):
|
||||||
""" Loads settings metadata from skills path. """
|
""" Loads settings metadata from skills path. """
|
||||||
if isfile(self._meta_path):
|
if isfile(self._meta_path):
|
||||||
with open(self._meta_path) as f:
|
try:
|
||||||
data = json.load(f)
|
with open(self._meta_path) as f:
|
||||||
return data
|
data = json.load(f)
|
||||||
|
return data
|
||||||
|
except Exception as e:
|
||||||
|
LOG.error("Failed to load setting file: "+self._meta_path)
|
||||||
|
LOG.error(repr(e))
|
||||||
|
return None
|
||||||
else:
|
else:
|
||||||
LOG.info("settingemeta.json does not exist")
|
LOG.info("settingemeta.json does not exist")
|
||||||
return None
|
return None
|
||||||
|
@ -361,7 +369,9 @@ class SkillSettings(dict):
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
if not self._complete_intialization:
|
if not self._complete_intialization:
|
||||||
self.initiatlize_remote_settings()
|
self.initialize_remote_settings()
|
||||||
|
if not self._complete_intialization:
|
||||||
|
return # unable to do remote sync
|
||||||
else:
|
else:
|
||||||
self.update_remote()
|
self.update_remote()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
Loading…
Reference in New Issue