diff --git a/eos/effectHandlerHelpers.py b/eos/effectHandlerHelpers.py index d4ac07bb3..025ef2701 100644 --- a/eos/effectHandlerHelpers.py +++ b/eos/effectHandlerHelpers.py @@ -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): diff --git a/gui/fitCommands/calc/booster/add.py b/gui/fitCommands/calc/booster/add.py index 2b1b5eca4..6342e84d5 100644 --- a/gui/fitCommands/calc/booster/add.py +++ b/gui/fitCommands/calc/booster/add.py @@ -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( diff --git a/gui/fitCommands/calc/cargo/add.py b/gui/fitCommands/calc/cargo/add.py index f36014e2b..2d78cf793 100644 --- a/gui/fitCommands/calc/cargo/add.py +++ b/gui/fitCommands/calc/cargo/add.py @@ -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: diff --git a/gui/fitCommands/calc/drone/localAdd.py b/gui/fitCommands/calc/drone/localAdd.py index 9122fb059..23b0980ae 100644 --- a/gui/fitCommands/calc/drone/localAdd.py +++ b/gui/fitCommands/calc/drone/localAdd.py @@ -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: diff --git a/gui/fitCommands/calc/drone/localRemove.py b/gui/fitCommands/calc/drone/localRemove.py index e3fb2e359..8ba45905a 100644 --- a/gui/fitCommands/calc/drone/localRemove.py +++ b/gui/fitCommands/calc/drone/localRemove.py @@ -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: diff --git a/gui/fitCommands/calc/drone/projectedAdd.py b/gui/fitCommands/calc/drone/projectedAdd.py index 45563422e..59dfeda10 100644 --- a/gui/fitCommands/calc/drone/projectedAdd.py +++ b/gui/fitCommands/calc/drone/projectedAdd.py @@ -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: diff --git a/gui/fitCommands/calc/fighter/localAdd.py b/gui/fitCommands/calc/fighter/localAdd.py index f336282f2..dbaedaecf 100644 --- a/gui/fitCommands/calc/fighter/localAdd.py +++ b/gui/fitCommands/calc/fighter/localAdd.py @@ -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: diff --git a/gui/fitCommands/calc/fighter/projectedAdd.py b/gui/fitCommands/calc/fighter/projectedAdd.py index 91a3bdbed..8fb16a30c 100644 --- a/gui/fitCommands/calc/fighter/projectedAdd.py +++ b/gui/fitCommands/calc/fighter/projectedAdd.py @@ -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() diff --git a/gui/fitCommands/calc/implant/add.py b/gui/fitCommands/calc/implant/add.py index 666377b53..23426b08d 100644 --- a/gui/fitCommands/calc/implant/add.py +++ b/gui/fitCommands/calc/implant/add.py @@ -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( diff --git a/gui/fitCommands/calc/module/localAdd.py b/gui/fitCommands/calc/module/localAdd.py index aa3d34088..388870b7a 100644 --- a/gui/fitCommands/calc/module/localAdd.py +++ b/gui/fitCommands/calc/module/localAdd.py @@ -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: diff --git a/gui/fitCommands/calc/module/localClone.py b/gui/fitCommands/calc/module/localClone.py index 9c953d48d..54acd6a3d 100644 --- a/gui/fitCommands/calc/module/localClone.py +++ b/gui/fitCommands/calc/module/localClone.py @@ -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() diff --git a/gui/fitCommands/calc/module/localReplace.py b/gui/fitCommands/calc/module/localReplace.py index 7524f74ce..dfdf7a261 100644 --- a/gui/fitCommands/calc/module/localReplace.py +++ b/gui/fitCommands/calc/module/localReplace.py @@ -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() diff --git a/gui/fitCommands/calc/module/localSwap.py b/gui/fitCommands/calc/module/localSwap.py index 6ff666fb5..ce516a04f 100644 --- a/gui/fitCommands/calc/module/localSwap.py +++ b/gui/fitCommands/calc/module/localSwap.py @@ -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) diff --git a/gui/fitCommands/calc/module/projectedAdd.py b/gui/fitCommands/calc/module/projectedAdd.py index 15c5aaac6..6836c4a43 100644 --- a/gui/fitCommands/calc/module/projectedAdd.py +++ b/gui/fitCommands/calc/module/projectedAdd.py @@ -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()