Do not crash when facing unknown module in saved fit
This commit is contained in:
@@ -20,7 +20,6 @@
|
||||
from logbook import Logger
|
||||
|
||||
from eos.exception import HandledListActionError
|
||||
from utils.deprecated import deprecated
|
||||
|
||||
|
||||
pyfalog = Logger(__name__)
|
||||
@@ -123,7 +122,7 @@ class HandledList(list):
|
||||
|
||||
class HandledModuleList(HandledList):
|
||||
|
||||
def append(self, mod):
|
||||
def append(self, mod, raiseFailure=False):
|
||||
emptyPosition = float("Inf")
|
||||
for i in range(len(self)):
|
||||
currMod = self[i]
|
||||
@@ -137,29 +136,41 @@ class HandledModuleList(HandledList):
|
||||
self.__toModule(emptyPosition, mod)
|
||||
if mod.isInvalid:
|
||||
self.__toDummy(mod.position)
|
||||
raise HandledListActionError(mod)
|
||||
if raiseFailure:
|
||||
raise HandledListActionError(mod)
|
||||
else:
|
||||
return
|
||||
return
|
||||
|
||||
self.appendIgnoreEmpty(mod)
|
||||
self.appendIgnoreEmpty(mod, raiseFailure=raiseFailure)
|
||||
|
||||
def appendIgnoreEmpty(self, mod):
|
||||
def appendIgnoreEmpty(self, mod, raiseFailure=False):
|
||||
mod.position = len(self)
|
||||
HandledList.append(self, mod)
|
||||
if mod.isInvalid:
|
||||
self.remove(mod)
|
||||
raise HandledListActionError(mod)
|
||||
if raiseFailure:
|
||||
raise HandledListActionError(mod)
|
||||
else:
|
||||
return
|
||||
|
||||
def replace(self, idx, mod):
|
||||
def replace(self, idx, mod, raiseFailure=False):
|
||||
try:
|
||||
oldMod = self[idx]
|
||||
except IndexError:
|
||||
raise HandledListActionError(mod)
|
||||
if raiseFailure:
|
||||
raise HandledListActionError(mod)
|
||||
else:
|
||||
return
|
||||
self.__toModule(idx, mod)
|
||||
if mod.isInvalid:
|
||||
self.__toModule(idx, oldMod)
|
||||
raise HandledListActionError(mod)
|
||||
if raiseFailure:
|
||||
raise HandledListActionError(mod)
|
||||
else:
|
||||
return
|
||||
|
||||
def replaceRackPosition(self, rackPosition, mod):
|
||||
def replaceRackPosition(self, rackPosition, mod, raiseFailure=False):
|
||||
listPositions = []
|
||||
for currPos in range(len(self)):
|
||||
currMod = self[currPos]
|
||||
@@ -169,7 +180,7 @@ class HandledModuleList(HandledList):
|
||||
try:
|
||||
modListPosition = listPositions[rackPosition]
|
||||
except IndexError:
|
||||
self.appendIgnoreEmpty(mod)
|
||||
self.appendIgnoreEmpty(mod, raiseFailure=raiseFailure)
|
||||
else:
|
||||
oldMod = self[modListPosition]
|
||||
if mod.isEmpty:
|
||||
@@ -182,9 +193,12 @@ class HandledModuleList(HandledList):
|
||||
self.__toDummy(modListPosition)
|
||||
else:
|
||||
self.__toModule(modListPosition, oldMod)
|
||||
raise HandledListActionError(mod)
|
||||
if raiseFailure:
|
||||
raise HandledListActionError(mod)
|
||||
else:
|
||||
return
|
||||
|
||||
def insert(self, idx, mod):
|
||||
def insert(self, idx, mod, raiseFailure=False):
|
||||
mod.position = idx
|
||||
i = idx
|
||||
while i < len(self):
|
||||
@@ -193,8 +207,10 @@ class HandledModuleList(HandledList):
|
||||
HandledList.insert(self, idx, mod)
|
||||
if mod.isInvalid:
|
||||
self.remove(mod)
|
||||
raise HandledListActionError(mod)
|
||||
|
||||
if raiseFailure:
|
||||
raise HandledListActionError(mod)
|
||||
else:
|
||||
return
|
||||
|
||||
def remove(self, mod):
|
||||
HandledList.remove(self, mod)
|
||||
@@ -232,41 +248,59 @@ class HandledDroneCargoList(HandledList):
|
||||
for o in self.find(item):
|
||||
return o
|
||||
|
||||
def append(self, thing):
|
||||
def append(self, thing, raiseFailure=False):
|
||||
HandledList.append(self, thing)
|
||||
if thing.isInvalid:
|
||||
self.remove(thing)
|
||||
raise HandledListActionError(thing)
|
||||
if raiseFailure:
|
||||
raise HandledListActionError(thing)
|
||||
else:
|
||||
return
|
||||
|
||||
def insert(self, idx, thing):
|
||||
def insert(self, idx, thing, raiseFailure=False):
|
||||
HandledList.insert(self, idx, thing)
|
||||
if thing.isInvalid:
|
||||
self.remove(thing)
|
||||
raise HandledListActionError(thing)
|
||||
if raiseFailure:
|
||||
raise HandledListActionError(thing)
|
||||
else:
|
||||
return
|
||||
|
||||
|
||||
class HandledImplantList(HandledList):
|
||||
|
||||
def append(self, implant):
|
||||
def append(self, implant, raiseFailure=False):
|
||||
if implant.isInvalid:
|
||||
HandledList.append(self, implant)
|
||||
self.remove(implant)
|
||||
raise HandledListActionError(implant)
|
||||
if raiseFailure:
|
||||
raise HandledListActionError(implant)
|
||||
else:
|
||||
return
|
||||
if self.__slotCheck(implant):
|
||||
HandledList.append(self, implant)
|
||||
self.remove(implant)
|
||||
raise HandledListActionError(implant)
|
||||
if raiseFailure:
|
||||
raise HandledListActionError(implant)
|
||||
else:
|
||||
return
|
||||
HandledList.append(self, implant)
|
||||
|
||||
def insert(self, idx, implant):
|
||||
def insert(self, idx, implant, raiseFailure=False):
|
||||
if implant.isInvalid:
|
||||
HandledList.insert(self, idx, implant)
|
||||
self.remove(implant)
|
||||
raise HandledListActionError(implant)
|
||||
if raiseFailure:
|
||||
raise HandledListActionError(implant)
|
||||
else:
|
||||
return
|
||||
if self.__slotCheck(implant):
|
||||
HandledList.insert(self, idx, implant)
|
||||
self.remove(implant)
|
||||
raise HandledListActionError(implant)
|
||||
if raiseFailure:
|
||||
raise HandledListActionError(implant)
|
||||
else:
|
||||
return
|
||||
HandledList.insert(self, idx, implant)
|
||||
|
||||
def makeRoom(self, implant):
|
||||
@@ -288,26 +322,38 @@ class HandledImplantList(HandledList):
|
||||
|
||||
class HandledBoosterList(HandledList):
|
||||
|
||||
def append(self, booster):
|
||||
def append(self, booster, raiseFailure=False):
|
||||
if booster.isInvalid:
|
||||
HandledList.append(self, booster)
|
||||
self.remove(booster)
|
||||
raise HandledListActionError(booster)
|
||||
if raiseFailure:
|
||||
raise HandledListActionError(booster)
|
||||
else:
|
||||
return
|
||||
if self.__slotCheck(booster):
|
||||
HandledList.append(self, booster)
|
||||
self.remove(booster)
|
||||
raise HandledListActionError(booster)
|
||||
if raiseFailure:
|
||||
raise HandledListActionError(booster)
|
||||
else:
|
||||
return
|
||||
HandledList.append(self, booster)
|
||||
|
||||
def insert(self, idx, booster):
|
||||
def insert(self, idx, booster, raiseFailure=False):
|
||||
if booster.isInvalid:
|
||||
HandledList.insert(self, idx, booster)
|
||||
self.remove(booster)
|
||||
raise HandledListActionError(booster)
|
||||
if raiseFailure:
|
||||
raise HandledListActionError(booster)
|
||||
else:
|
||||
return
|
||||
if self.__slotCheck(booster):
|
||||
HandledList.insert(self, idx, booster)
|
||||
self.remove(booster)
|
||||
raise HandledListActionError(booster)
|
||||
if raiseFailure:
|
||||
raise HandledListActionError(booster)
|
||||
else:
|
||||
return
|
||||
HandledList.insert(self, idx, booster)
|
||||
|
||||
def makeRoom(self, booster):
|
||||
@@ -340,13 +386,16 @@ class HandledSsoCharacterList(list):
|
||||
|
||||
class HandledProjectedModList(HandledList):
|
||||
|
||||
def append(self, proj):
|
||||
def append(self, proj, raiseFailure=False):
|
||||
if proj.isInvalid:
|
||||
# we must include it before we remove it. doing it this way ensures
|
||||
# rows and relationships in database are removed as well
|
||||
HandledList.append(self, proj)
|
||||
self.remove(proj)
|
||||
raise HandledListActionError(proj)
|
||||
if raiseFailure:
|
||||
raise HandledListActionError(proj)
|
||||
else:
|
||||
return
|
||||
|
||||
proj.projected = True
|
||||
|
||||
@@ -355,15 +404,21 @@ class HandledProjectedModList(HandledList):
|
||||
# Remove non-projectable modules
|
||||
if not proj.item.isType("projected") and not proj.isExclusiveSystemEffect:
|
||||
self.remove(proj)
|
||||
raise HandledListActionError(proj)
|
||||
if raiseFailure:
|
||||
raise HandledListActionError(proj)
|
||||
else:
|
||||
return
|
||||
|
||||
def insert(self, idx, proj):
|
||||
def insert(self, idx, proj, raiseFailure=False):
|
||||
if proj.isInvalid:
|
||||
# we must include it before we remove it. doing it this way ensures
|
||||
# rows and relationships in database are removed as well
|
||||
HandledList.insert(self, idx, proj)
|
||||
self.remove(proj)
|
||||
raise HandledListActionError(proj)
|
||||
if raiseFailure:
|
||||
raise HandledListActionError(proj)
|
||||
else:
|
||||
return
|
||||
|
||||
proj.projected = True
|
||||
|
||||
@@ -372,7 +427,10 @@ class HandledProjectedModList(HandledList):
|
||||
# Remove non-projectable modules
|
||||
if not proj.item.isType("projected") and not proj.isExclusiveSystemEffect:
|
||||
self.remove(proj)
|
||||
raise HandledListActionError(proj)
|
||||
if raiseFailure:
|
||||
raise HandledListActionError(proj)
|
||||
else:
|
||||
return
|
||||
|
||||
@property
|
||||
def currentSystemEffect(self):
|
||||
@@ -396,7 +454,7 @@ class HandledProjectedModList(HandledList):
|
||||
|
||||
class HandledProjectedDroneList(HandledDroneCargoList):
|
||||
|
||||
def append(self, proj):
|
||||
def append(self, proj, raiseFailure=False):
|
||||
proj.projected = True
|
||||
HandledList.append(self, proj)
|
||||
|
||||
@@ -404,10 +462,12 @@ class HandledProjectedDroneList(HandledDroneCargoList):
|
||||
if proj.isInvalid or not proj.item.isType("projected"):
|
||||
self.remove(proj)
|
||||
proj.projected = False
|
||||
raise HandledListActionError(proj)
|
||||
return True
|
||||
if raiseFailure:
|
||||
raise HandledListActionError(proj)
|
||||
else:
|
||||
return
|
||||
|
||||
def insert(self, idx, proj):
|
||||
def insert(self, idx, proj, raiseFailure=False):
|
||||
proj.projected = True
|
||||
HandledList.insert(self, idx, proj)
|
||||
|
||||
@@ -415,8 +475,10 @@ class HandledProjectedDroneList(HandledDroneCargoList):
|
||||
if proj.isInvalid or not proj.item.isType("projected"):
|
||||
self.remove(proj)
|
||||
proj.projected = False
|
||||
raise HandledListActionError(proj)
|
||||
return True
|
||||
if raiseFailure:
|
||||
raise HandledListActionError(proj)
|
||||
else:
|
||||
return
|
||||
|
||||
|
||||
class HandledItem(object):
|
||||
|
||||
@@ -36,7 +36,7 @@ class CalcAddBoosterCommand(wx.Command):
|
||||
|
||||
if self.newPosition is not None:
|
||||
try:
|
||||
fit.boosters.insert(self.newPosition, newBooster)
|
||||
fit.boosters.insert(self.newPosition, newBooster, raiseFailure=True)
|
||||
except HandledListActionError:
|
||||
pyfalog.warning('Failed to insert to list')
|
||||
cmd = CalcAddBoosterCommand(
|
||||
@@ -48,7 +48,7 @@ class CalcAddBoosterCommand(wx.Command):
|
||||
return False
|
||||
else:
|
||||
try:
|
||||
fit.boosters.append(newBooster)
|
||||
fit.boosters.append(newBooster, raiseFailure=True)
|
||||
except HandledListActionError:
|
||||
pyfalog.warning('Failed to append to list')
|
||||
cmd = CalcAddBoosterCommand(
|
||||
|
||||
@@ -26,7 +26,7 @@ class CalcAddCargoCommand(wx.Command):
|
||||
else:
|
||||
cargo = self.cargoInfo.toCargo()
|
||||
try:
|
||||
fit.cargo.append(cargo)
|
||||
fit.cargo.append(cargo, raiseFailure=True)
|
||||
except HandledListActionError:
|
||||
pyfalog.warning('Failed to append to list')
|
||||
if self.commit:
|
||||
|
||||
@@ -51,7 +51,7 @@ class CalcAddLocalDroneCommand(wx.Command):
|
||||
pyfalog.warning('Drone does not fit')
|
||||
return False
|
||||
try:
|
||||
fit.drones.append(drone)
|
||||
fit.drones.append(drone, raiseFailure=True)
|
||||
except HandledListActionError:
|
||||
pyfalog.warning('Failed to append to list')
|
||||
if self.commit:
|
||||
|
||||
@@ -49,7 +49,7 @@ class CalcRemoveLocalDroneCommand(wx.Command):
|
||||
if drone is None:
|
||||
return False
|
||||
try:
|
||||
fit.drones.insert(self.position, drone)
|
||||
fit.drones.insert(self.position, drone, raiseFailure=True)
|
||||
except HandledListActionError:
|
||||
pyfalog.warning('Failed to insert to list')
|
||||
if self.commit:
|
||||
|
||||
@@ -44,7 +44,7 @@ class CalcAddProjectedDroneCommand(wx.Command):
|
||||
pyfalog.debug('Drone is not projectable')
|
||||
return False
|
||||
try:
|
||||
fit.projectedDrones.append(drone)
|
||||
fit.projectedDrones.append(drone, raiseFailure=True)
|
||||
except HandledListActionError:
|
||||
pyfalog.warning('Failed to append to list')
|
||||
if self.commit:
|
||||
|
||||
@@ -42,7 +42,7 @@ class CalcAddLocalFighterCommand(wx.Command):
|
||||
|
||||
if self.position is None:
|
||||
try:
|
||||
fit.fighters.append(fighter)
|
||||
fit.fighters.append(fighter, raiseFailure=True)
|
||||
except HandledListActionError:
|
||||
pyfalog.warning('Failed to append to list')
|
||||
if self.commit:
|
||||
@@ -51,7 +51,7 @@ class CalcAddLocalFighterCommand(wx.Command):
|
||||
self.position = fit.fighters.index(fighter)
|
||||
else:
|
||||
try:
|
||||
fit.fighters.insert(self.position, fighter)
|
||||
fit.fighters.insert(self.position, fighter, raiseFailure=True)
|
||||
except HandledListActionError:
|
||||
pyfalog.warning('Failed to insert to list')
|
||||
if self.commit:
|
||||
|
||||
@@ -26,14 +26,14 @@ class CalcAddProjectedFighterCommand(wx.Command):
|
||||
fit = Fit.getInstance().getFit(self.fitID)
|
||||
if self.position is not None:
|
||||
try:
|
||||
fit.projectedFighters.insert(self.position, fighter)
|
||||
fit.projectedFighters.insert(self.position, fighter, raiseFailure=True)
|
||||
except HandledListActionError:
|
||||
if self.commit:
|
||||
eos.db.commit()
|
||||
return False
|
||||
else:
|
||||
try:
|
||||
fit.projectedFighters.append(fighter)
|
||||
fit.projectedFighters.append(fighter, raiseFailure=True)
|
||||
except HandledListActionError:
|
||||
if self.commit:
|
||||
eos.db.commit()
|
||||
|
||||
@@ -36,7 +36,7 @@ class CalcAddImplantCommand(wx.Command):
|
||||
|
||||
if self.newPosition is not None:
|
||||
try:
|
||||
fit.implants.insert(self.newPosition, newImplant)
|
||||
fit.implants.insert(self.newPosition, newImplant, raiseFailure=True)
|
||||
except HandledListActionError:
|
||||
pyfalog.warning('Failed to insert to list')
|
||||
cmd = CalcAddImplantCommand(
|
||||
@@ -48,7 +48,7 @@ class CalcAddImplantCommand(wx.Command):
|
||||
return False
|
||||
else:
|
||||
try:
|
||||
fit.implants.append(newImplant)
|
||||
fit.implants.append(newImplant, raiseFailure=True)
|
||||
except HandledListActionError:
|
||||
pyfalog.warning('Failed to append to list')
|
||||
cmd = CalcAddImplantCommand(
|
||||
|
||||
@@ -56,7 +56,7 @@ class CalcAddLocalModuleCommand(wx.Command):
|
||||
pyfalog.warning('Module does not fit')
|
||||
return False
|
||||
try:
|
||||
fit.modules.append(newMod)
|
||||
fit.modules.append(newMod, raiseFailure=True)
|
||||
except HandledListActionError:
|
||||
pyfalog.warning('Failed to append to list')
|
||||
if self.commit:
|
||||
|
||||
@@ -32,7 +32,7 @@ class CalcCloneLocalModuleCommand(wx.Command):
|
||||
if not fit.modules[self.dstPosition].isEmpty:
|
||||
return False
|
||||
try:
|
||||
fit.modules.replace(self.dstPosition, copyMod)
|
||||
fit.modules.replace(self.dstPosition, copyMod, raiseFailure=True)
|
||||
except HandledListActionError:
|
||||
pyfalog.warning('Failed to replace module')
|
||||
eos.db.commit()
|
||||
|
||||
@@ -54,7 +54,7 @@ class CalcReplaceLocalModuleCommand(wx.Command):
|
||||
self.Undo()
|
||||
return False
|
||||
try:
|
||||
fit.modules.replace(self.position, newMod)
|
||||
fit.modules.replace(self.position, newMod, raiseFailure=True)
|
||||
except HandledListActionError:
|
||||
pyfalog.warning('Failed to replace in list')
|
||||
self.Undo()
|
||||
@@ -88,7 +88,7 @@ class CalcReplaceLocalModuleCommand(wx.Command):
|
||||
return False
|
||||
fit.modules.free(self.position)
|
||||
try:
|
||||
fit.modules.replace(self.position, oldMod)
|
||||
fit.modules.replace(self.position, oldMod, raiseFailure=True)
|
||||
except HandledListActionError:
|
||||
pyfalog.warning('Failed to replace in list')
|
||||
self.Do()
|
||||
|
||||
@@ -34,14 +34,14 @@ class CalcSwapLocalModuleCommand(wx.Command):
|
||||
fit.modules.free(position1)
|
||||
fit.modules.free(position2)
|
||||
try:
|
||||
fit.modules.replace(position2, mod1)
|
||||
fit.modules.replace(position2, mod1, raiseFailure=True)
|
||||
except HandledListActionError:
|
||||
fit.modules.replace(position1, mod1)
|
||||
fit.modules.replace(position2, mod2)
|
||||
eos.db.commit()
|
||||
return False
|
||||
try:
|
||||
fit.modules.replace(position1, mod2)
|
||||
fit.modules.replace(position1, mod2, raiseFailure=True)
|
||||
except HandledListActionError:
|
||||
fit.modules.free(position2)
|
||||
fit.modules.replace(position1, mod1)
|
||||
|
||||
@@ -40,14 +40,14 @@ class CalcAddProjectedModuleCommand(wx.Command):
|
||||
|
||||
if self.newPosition is not None:
|
||||
try:
|
||||
fit.projectedModules.insert(self.newPosition, newMod)
|
||||
fit.projectedModules.insert(self.newPosition, newMod, raiseFailure=True)
|
||||
except HandledListActionError:
|
||||
if self.commit:
|
||||
eos.db.commit()
|
||||
return False
|
||||
else:
|
||||
try:
|
||||
fit.projectedModules.append(newMod)
|
||||
fit.projectedModules.append(newMod, raiseFailure=True)
|
||||
except HandledListActionError:
|
||||
if self.commit:
|
||||
eos.db.commit()
|
||||
|
||||
Reference in New Issue
Block a user