Add some sanity checks and validation of incoming data
This commit is contained in:
@@ -34,6 +34,8 @@ import service
|
|||||||
import config
|
import config
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from eos.saveddata.character import Character as es_Character
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
class CharacterImportThread(threading.Thread):
|
class CharacterImportThread(threading.Thread):
|
||||||
@@ -45,6 +47,12 @@ class CharacterImportThread(threading.Thread):
|
|||||||
def run(self):
|
def run(self):
|
||||||
paths = self.paths
|
paths = self.paths
|
||||||
sCharacter = Character.getInstance()
|
sCharacter = Character.getInstance()
|
||||||
|
all5_character = es_Character("All 5", 5)
|
||||||
|
all_skill_ids = []
|
||||||
|
for skill in all5_character.skills:
|
||||||
|
# Parse out the skill item IDs to make searching it easier later on
|
||||||
|
all_skill_ids.append(skill.itemID)
|
||||||
|
|
||||||
for path in paths:
|
for path in paths:
|
||||||
try:
|
try:
|
||||||
# we try to parse api XML data first
|
# we try to parse api XML data first
|
||||||
@@ -59,19 +67,28 @@ class CharacterImportThread(threading.Thread):
|
|||||||
charFile = open(path, mode='r').read()
|
charFile = open(path, mode='r').read()
|
||||||
doc = minidom.parseString(charFile)
|
doc = minidom.parseString(charFile)
|
||||||
if doc.documentElement.tagName not in ("SerializableCCPCharacter", "SerializableUriCharacter"):
|
if doc.documentElement.tagName not in ("SerializableCCPCharacter", "SerializableUriCharacter"):
|
||||||
|
logger.error("Incorrect EVEMon XML sheet")
|
||||||
raise RuntimeError("Incorrect EVEMon XML sheet")
|
raise RuntimeError("Incorrect EVEMon XML sheet")
|
||||||
name = doc.getElementsByTagName("name")[0].firstChild.nodeValue
|
name = doc.getElementsByTagName("name")[0].firstChild.nodeValue
|
||||||
skill_els = doc.getElementsByTagName("skill")
|
skill_els = doc.getElementsByTagName("skill")
|
||||||
skills = []
|
skills = []
|
||||||
for skill in skill_els:
|
for skill in skill_els:
|
||||||
skills.append({
|
if int(skill.getAttribute("typeID")) in all_skill_ids and (0 <= int(skill.getAttribute("level")) <= 5):
|
||||||
"typeID": int(skill.getAttribute("typeID")),
|
skills.append({
|
||||||
"level": int(skill.getAttribute("level")),
|
"typeID": int(skill.getAttribute("typeID")),
|
||||||
})
|
"level": int(skill.getAttribute("level")),
|
||||||
|
})
|
||||||
|
else:
|
||||||
|
logger.error("Attempted to import unknown skill %s (ID: %s) (Level: %s)",
|
||||||
|
skill.getAttribute("name"),
|
||||||
|
skill.getAttribute("typeID"),
|
||||||
|
skill.getAttribute("level"),
|
||||||
|
)
|
||||||
char = sCharacter.new(name+" (EVEMon)")
|
char = sCharacter.new(name+" (EVEMon)")
|
||||||
sCharacter.apiUpdateCharSheet(char.ID, skills)
|
sCharacter.apiUpdateCharSheet(char.ID, skills)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
print e.message
|
logger.error("Exception on character import:")
|
||||||
|
logger.error(e)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
wx.CallAfter(self.callback)
|
wx.CallAfter(self.callback)
|
||||||
|
|||||||
Reference in New Issue
Block a user