From 2b24f14122e3756ac2dac36f5223d97d381b7d64 Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Fri, 3 May 2019 03:36:47 +0300 Subject: [PATCH] Change interface between commands and item containers once again --- eos/effectHandlerHelpers.py | 147 ++++--------------- eos/exception.py | 2 - gui/fitCommands/calc/booster/add.py | 11 +- gui/fitCommands/calc/cargo/add.py | 6 +- gui/fitCommands/calc/drone/localAdd.py | 6 +- gui/fitCommands/calc/drone/localRemove.py | 6 +- gui/fitCommands/calc/drone/projectedAdd.py | 6 +- gui/fitCommands/calc/fighter/localAdd.py | 11 +- gui/fitCommands/calc/fighter/projectedAdd.py | 11 +- gui/fitCommands/calc/implant/add.py | 11 +- gui/fitCommands/calc/module/localAdd.py | 6 +- gui/fitCommands/calc/module/localClone.py | 6 +- gui/fitCommands/calc/module/localReplace.py | 11 +- gui/fitCommands/calc/module/localSwap.py | 11 +- gui/fitCommands/calc/module/projectedAdd.py | 11 +- 15 files changed, 70 insertions(+), 192 deletions(-) delete mode 100644 eos/exception.py diff --git a/eos/effectHandlerHelpers.py b/eos/effectHandlerHelpers.py index 025ef2701..81cd07f19 100644 --- a/eos/effectHandlerHelpers.py +++ b/eos/effectHandlerHelpers.py @@ -17,9 +17,8 @@ # along with eos. If not, see . # =============================================================================== -from logbook import Logger -from eos.exception import HandledListActionError +from logbook import Logger pyfalog = Logger(__name__) @@ -122,7 +121,7 @@ class HandledList(list): class HandledModuleList(HandledList): - def append(self, mod, raiseFailure=False): + def append(self, mod): emptyPosition = float("Inf") for i in range(len(self)): currMod = self[i] @@ -136,41 +135,25 @@ class HandledModuleList(HandledList): self.__toModule(emptyPosition, mod) if mod.isInvalid: self.__toDummy(mod.position) - if raiseFailure: - raise HandledListActionError(mod) - else: - return - return + else: + self.appendIgnoreEmpty(mod) - self.appendIgnoreEmpty(mod, raiseFailure=raiseFailure) - - def appendIgnoreEmpty(self, mod, raiseFailure=False): + def appendIgnoreEmpty(self, mod): mod.position = len(self) HandledList.append(self, mod) if mod.isInvalid: self.remove(mod) - if raiseFailure: - raise HandledListActionError(mod) - else: - return - def replace(self, idx, mod, raiseFailure=False): + def replace(self, idx, mod): try: oldMod = self[idx] except IndexError: - if raiseFailure: - raise HandledListActionError(mod) - else: - return + return self.__toModule(idx, mod) if mod.isInvalid: self.__toModule(idx, oldMod) - if raiseFailure: - raise HandledListActionError(mod) - else: - return - def replaceRackPosition(self, rackPosition, mod, raiseFailure=False): + def replaceRackPosition(self, rackPosition, mod): listPositions = [] for currPos in range(len(self)): currMod = self[currPos] @@ -180,7 +163,7 @@ class HandledModuleList(HandledList): try: modListPosition = listPositions[rackPosition] except IndexError: - self.appendIgnoreEmpty(mod, raiseFailure=raiseFailure) + self.appendIgnoreEmpty(mod) else: oldMod = self[modListPosition] if mod.isEmpty: @@ -193,12 +176,8 @@ class HandledModuleList(HandledList): self.__toDummy(modListPosition) else: self.__toModule(modListPosition, oldMod) - if raiseFailure: - raise HandledListActionError(mod) - else: - return - def insert(self, idx, mod, raiseFailure=False): + def insert(self, idx, mod): mod.position = idx i = idx while i < len(self): @@ -207,10 +186,6 @@ class HandledModuleList(HandledList): HandledList.insert(self, idx, mod) if mod.isInvalid: self.remove(mod) - if raiseFailure: - raise HandledListActionError(mod) - else: - return def remove(self, mod): HandledList.remove(self, mod) @@ -248,59 +223,39 @@ class HandledDroneCargoList(HandledList): for o in self.find(item): return o - def append(self, thing, raiseFailure=False): + def append(self, thing): HandledList.append(self, thing) if thing.isInvalid: self.remove(thing) - if raiseFailure: - raise HandledListActionError(thing) - else: - return - def insert(self, idx, thing, raiseFailure=False): + def insert(self, idx, thing): HandledList.insert(self, idx, thing) if thing.isInvalid: self.remove(thing) - if raiseFailure: - raise HandledListActionError(thing) - else: - return class HandledImplantList(HandledList): - def append(self, implant, raiseFailure=False): + def append(self, implant): if implant.isInvalid: HandledList.append(self, implant) self.remove(implant) - if raiseFailure: - raise HandledListActionError(implant) - else: - return + return if self.__slotCheck(implant): HandledList.append(self, implant) self.remove(implant) - if raiseFailure: - raise HandledListActionError(implant) - else: - return + return HandledList.append(self, implant) - def insert(self, idx, implant, raiseFailure=False): + def insert(self, idx, implant): if implant.isInvalid: HandledList.insert(self, idx, implant) self.remove(implant) - if raiseFailure: - raise HandledListActionError(implant) - else: - return + return if self.__slotCheck(implant): HandledList.insert(self, idx, implant) self.remove(implant) - if raiseFailure: - raise HandledListActionError(implant) - else: - return + return HandledList.insert(self, idx, implant) def makeRoom(self, implant): @@ -322,38 +277,26 @@ class HandledImplantList(HandledList): class HandledBoosterList(HandledList): - def append(self, booster, raiseFailure=False): + def append(self, booster): if booster.isInvalid: HandledList.append(self, booster) self.remove(booster) - if raiseFailure: - raise HandledListActionError(booster) - else: - return + return if self.__slotCheck(booster): HandledList.append(self, booster) self.remove(booster) - if raiseFailure: - raise HandledListActionError(booster) - else: - return + return HandledList.append(self, booster) - def insert(self, idx, booster, raiseFailure=False): + def insert(self, idx, booster): if booster.isInvalid: HandledList.insert(self, idx, booster) self.remove(booster) - if raiseFailure: - raise HandledListActionError(booster) - else: - return + return if self.__slotCheck(booster): HandledList.insert(self, idx, booster) self.remove(booster) - if raiseFailure: - raise HandledListActionError(booster) - else: - return + return HandledList.insert(self, idx, booster) def makeRoom(self, booster): @@ -386,51 +329,31 @@ class HandledSsoCharacterList(list): class HandledProjectedModList(HandledList): - def append(self, proj, raiseFailure=False): + def append(self, proj): 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) - if raiseFailure: - raise HandledListActionError(proj) - else: - return - + return proj.projected = True - HandledList.append(self, proj) - # Remove non-projectable modules if not proj.item.isType("projected") and not proj.isExclusiveSystemEffect: self.remove(proj) - if raiseFailure: - raise HandledListActionError(proj) - else: - return - def insert(self, idx, proj, raiseFailure=False): + def insert(self, idx, proj): 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) - if raiseFailure: - raise HandledListActionError(proj) - else: - return - + return proj.projected = True - HandledList.insert(self, idx, proj) - # Remove non-projectable modules if not proj.item.isType("projected") and not proj.isExclusiveSystemEffect: self.remove(proj) - if raiseFailure: - raise HandledListActionError(proj) - else: - return @property def currentSystemEffect(self): @@ -454,31 +377,21 @@ class HandledProjectedModList(HandledList): class HandledProjectedDroneList(HandledDroneCargoList): - def append(self, proj, raiseFailure=False): + def append(self, proj): proj.projected = True HandledList.append(self, proj) - # Remove invalid or non-projectable drones if proj.isInvalid or not proj.item.isType("projected"): self.remove(proj) proj.projected = False - if raiseFailure: - raise HandledListActionError(proj) - else: - return - def insert(self, idx, proj, raiseFailure=False): + def insert(self, idx, proj): proj.projected = True HandledList.insert(self, idx, proj) - # Remove invalid or non-projectable drones if proj.isInvalid or not proj.item.isType("projected"): self.remove(proj) proj.projected = False - if raiseFailure: - raise HandledListActionError(proj) - else: - return class HandledItem(object): diff --git a/eos/exception.py b/eos/exception.py deleted file mode 100644 index b3bb90a29..000000000 --- a/eos/exception.py +++ /dev/null @@ -1,2 +0,0 @@ -class HandledListActionError(Exception): - ... diff --git a/gui/fitCommands/calc/booster/add.py b/gui/fitCommands/calc/booster/add.py index 6342e84d5..aa0c89443 100644 --- a/gui/fitCommands/calc/booster/add.py +++ b/gui/fitCommands/calc/booster/add.py @@ -2,7 +2,6 @@ import wx from logbook import Logger import eos.db -from eos.exception import HandledListActionError from service.fit import Fit @@ -35,9 +34,8 @@ class CalcAddBoosterCommand(wx.Command): self.oldPosition, self.oldBoosterInfo = fit.boosters.makeRoom(newBooster) if self.newPosition is not None: - try: - fit.boosters.insert(self.newPosition, newBooster, raiseFailure=True) - except HandledListActionError: + fit.boosters.insert(self.newPosition, newBooster) + if newBooster not in fit.boosters: pyfalog.warning('Failed to insert to list') cmd = CalcAddBoosterCommand( fitID=self.fitID, @@ -47,9 +45,8 @@ class CalcAddBoosterCommand(wx.Command): cmd.Do() return False else: - try: - fit.boosters.append(newBooster, raiseFailure=True) - except HandledListActionError: + fit.boosters.append(newBooster) + if newBooster not in fit.boosters: pyfalog.warning('Failed to append to list') cmd = CalcAddBoosterCommand( fitID=self.fitID, diff --git a/gui/fitCommands/calc/cargo/add.py b/gui/fitCommands/calc/cargo/add.py index 2d78cf793..260451469 100644 --- a/gui/fitCommands/calc/cargo/add.py +++ b/gui/fitCommands/calc/cargo/add.py @@ -2,7 +2,6 @@ import wx from logbook import Logger import eos.db -from eos.exception import HandledListActionError from service.fit import Fit @@ -25,9 +24,8 @@ class CalcAddCargoCommand(wx.Command): cargo.amount += self.cargoInfo.amount else: cargo = self.cargoInfo.toCargo() - try: - fit.cargo.append(cargo, raiseFailure=True) - except HandledListActionError: + fit.cargo.append(cargo) + if cargo not in fit.cargo: pyfalog.warning('Failed to append to list') if self.commit: eos.db.commit() diff --git a/gui/fitCommands/calc/drone/localAdd.py b/gui/fitCommands/calc/drone/localAdd.py index 23b0980ae..c24db3af8 100644 --- a/gui/fitCommands/calc/drone/localAdd.py +++ b/gui/fitCommands/calc/drone/localAdd.py @@ -3,7 +3,6 @@ import wx from logbook import Logger import eos.db -from eos.exception import HandledListActionError from gui.fitCommands.helpers import DroneInfo, droneStackLimit from service.fit import Fit from service.market import Market @@ -50,9 +49,8 @@ class CalcAddLocalDroneCommand(wx.Command): if not self.ignoreRestrictions and not drone.fits(fit): pyfalog.warning('Drone does not fit') return False - try: - fit.drones.append(drone, raiseFailure=True) - except HandledListActionError: + fit.drones.append(drone) + if drone not in fit.drones: pyfalog.warning('Failed to append to list') if self.commit: eos.db.commit() diff --git a/gui/fitCommands/calc/drone/localRemove.py b/gui/fitCommands/calc/drone/localRemove.py index 8ba45905a..5425a934d 100644 --- a/gui/fitCommands/calc/drone/localRemove.py +++ b/gui/fitCommands/calc/drone/localRemove.py @@ -2,7 +2,6 @@ import wx from logbook import Logger import eos.db -from eos.exception import HandledListActionError from gui.fitCommands.helpers import DroneInfo from service.fit import Fit @@ -48,9 +47,8 @@ class CalcRemoveLocalDroneCommand(wx.Command): drone = self.savedDroneInfo.toDrone() if drone is None: return False - try: - fit.drones.insert(self.position, drone, raiseFailure=True) - except HandledListActionError: + fit.drones.insert(self.position, drone) + if drone not in fit.drones: pyfalog.warning('Failed to insert to list') if self.commit: eos.db.commit() diff --git a/gui/fitCommands/calc/drone/projectedAdd.py b/gui/fitCommands/calc/drone/projectedAdd.py index 59dfeda10..d54bc1447 100644 --- a/gui/fitCommands/calc/drone/projectedAdd.py +++ b/gui/fitCommands/calc/drone/projectedAdd.py @@ -4,7 +4,6 @@ import wx from logbook import Logger import eos.db -from eos.exception import HandledListActionError from gui.fitCommands.helpers import DroneInfo from service.fit import Fit @@ -43,9 +42,8 @@ class CalcAddProjectedDroneCommand(wx.Command): if not drone.item.isType('projected'): pyfalog.debug('Drone is not projectable') return False - try: - fit.projectedDrones.append(drone, raiseFailure=True) - except HandledListActionError: + fit.projectedDrones.append(drone) + if drone not in fit.projectedDrones: pyfalog.warning('Failed to append to list') if self.commit: eos.db.commit() diff --git a/gui/fitCommands/calc/fighter/localAdd.py b/gui/fitCommands/calc/fighter/localAdd.py index dbaedaecf..39e2103d1 100644 --- a/gui/fitCommands/calc/fighter/localAdd.py +++ b/gui/fitCommands/calc/fighter/localAdd.py @@ -2,7 +2,6 @@ import wx from logbook import Logger import eos.db -from eos.exception import HandledListActionError from service.fit import Fit @@ -41,18 +40,16 @@ class CalcAddLocalFighterCommand(wx.Command): fighter.active = True if self.position is None: - try: - fit.fighters.append(fighter, raiseFailure=True) - except HandledListActionError: + fit.fighters.append(fighter) + if fighter not in fit.fighters: pyfalog.warning('Failed to append to list') if self.commit: eos.db.commit() return False self.position = fit.fighters.index(fighter) else: - try: - fit.fighters.insert(self.position, fighter, raiseFailure=True) - except HandledListActionError: + fit.fighters.insert(self.position, fighter) + if fighter not in fit.fighters: pyfalog.warning('Failed to insert to list') if self.commit: eos.db.commit() diff --git a/gui/fitCommands/calc/fighter/projectedAdd.py b/gui/fitCommands/calc/fighter/projectedAdd.py index 8fb16a30c..714ed9143 100644 --- a/gui/fitCommands/calc/fighter/projectedAdd.py +++ b/gui/fitCommands/calc/fighter/projectedAdd.py @@ -2,7 +2,6 @@ import wx from logbook import Logger import eos.db -from eos.exception import HandledListActionError from service.fit import Fit @@ -25,16 +24,14 @@ class CalcAddProjectedFighterCommand(wx.Command): return False fit = Fit.getInstance().getFit(self.fitID) if self.position is not None: - try: - fit.projectedFighters.insert(self.position, fighter, raiseFailure=True) - except HandledListActionError: + fit.projectedFighters.insert(self.position, fighter) + if fighter not in fit.projectedFighters: if self.commit: eos.db.commit() return False else: - try: - fit.projectedFighters.append(fighter, raiseFailure=True) - except HandledListActionError: + fit.projectedFighters.append(fighter) + if fighter not in fit.projectedFighters: if self.commit: eos.db.commit() return False diff --git a/gui/fitCommands/calc/implant/add.py b/gui/fitCommands/calc/implant/add.py index 23426b08d..5418ad7ad 100644 --- a/gui/fitCommands/calc/implant/add.py +++ b/gui/fitCommands/calc/implant/add.py @@ -2,7 +2,6 @@ import wx from logbook import Logger import eos.db -from eos.exception import HandledListActionError from service.fit import Fit @@ -35,9 +34,8 @@ class CalcAddImplantCommand(wx.Command): self.oldPosition, self.oldImplantInfo = fit.implants.makeRoom(newImplant) if self.newPosition is not None: - try: - fit.implants.insert(self.newPosition, newImplant, raiseFailure=True) - except HandledListActionError: + fit.implants.insert(self.newPosition, newImplant) + if newImplant not in fit.implants: pyfalog.warning('Failed to insert to list') cmd = CalcAddImplantCommand( fitID=self.fitID, @@ -47,9 +45,8 @@ class CalcAddImplantCommand(wx.Command): cmd.Do() return False else: - try: - fit.implants.append(newImplant, raiseFailure=True) - except HandledListActionError: + fit.implants.append(newImplant) + if newImplant not in fit.implants: pyfalog.warning('Failed to append to list') cmd = CalcAddImplantCommand( fitID=self.fitID, diff --git a/gui/fitCommands/calc/module/localAdd.py b/gui/fitCommands/calc/module/localAdd.py index 388870b7a..1d130aa11 100644 --- a/gui/fitCommands/calc/module/localAdd.py +++ b/gui/fitCommands/calc/module/localAdd.py @@ -2,7 +2,6 @@ import wx from logbook import Logger import eos.db -from eos.exception import HandledListActionError from gui.fitCommands.helpers import restoreCheckedStates, stateLimit from service.fit import Fit @@ -55,9 +54,8 @@ class CalcAddLocalModuleCommand(wx.Command): if not newMod.fits(fit): pyfalog.warning('Module does not fit') return False - try: - fit.modules.append(newMod, raiseFailure=True) - except HandledListActionError: + fit.modules.append(newMod) + if newMod not in fit.modules: pyfalog.warning('Failed to append to list') if self.commit: eos.db.commit() diff --git a/gui/fitCommands/calc/module/localClone.py b/gui/fitCommands/calc/module/localClone.py index 54acd6a3d..36d3334c0 100644 --- a/gui/fitCommands/calc/module/localClone.py +++ b/gui/fitCommands/calc/module/localClone.py @@ -4,7 +4,6 @@ import wx from logbook import Logger import eos.db -from eos.exception import HandledListActionError from gui.fitCommands.helpers import restoreCheckedStates from service.fit import Fit @@ -31,9 +30,8 @@ class CalcCloneLocalModuleCommand(wx.Command): return False if not fit.modules[self.dstPosition].isEmpty: return False - try: - fit.modules.replace(self.dstPosition, copyMod, raiseFailure=True) - except HandledListActionError: + fit.modules.replace(self.dstPosition, copyMod) + if copyMod not in fit.modules: pyfalog.warning('Failed to replace module') eos.db.commit() return False diff --git a/gui/fitCommands/calc/module/localReplace.py b/gui/fitCommands/calc/module/localReplace.py index dfdf7a261..c4f5517f0 100644 --- a/gui/fitCommands/calc/module/localReplace.py +++ b/gui/fitCommands/calc/module/localReplace.py @@ -2,7 +2,6 @@ import wx from logbook import Logger import eos.db -from eos.exception import HandledListActionError from gui.fitCommands.helpers import ModuleInfo, restoreCheckedStates, stateLimit from service.fit import Fit @@ -53,9 +52,8 @@ class CalcReplaceLocalModuleCommand(wx.Command): pyfalog.warning('Invalid charge') self.Undo() return False - try: - fit.modules.replace(self.position, newMod, raiseFailure=True) - except HandledListActionError: + fit.modules.replace(self.position, newMod) + if newMod not in fit.modules: pyfalog.warning('Failed to replace in list') self.Undo() return False @@ -87,9 +85,8 @@ class CalcReplaceLocalModuleCommand(wx.Command): if oldMod is None: return False fit.modules.free(self.position) - try: - fit.modules.replace(self.position, oldMod, raiseFailure=True) - except HandledListActionError: + fit.modules.replace(self.position, oldMod) + if oldMod not in fit.modules: pyfalog.warning('Failed to replace in list') self.Do() return False diff --git a/gui/fitCommands/calc/module/localSwap.py b/gui/fitCommands/calc/module/localSwap.py index ce516a04f..580e7fc48 100644 --- a/gui/fitCommands/calc/module/localSwap.py +++ b/gui/fitCommands/calc/module/localSwap.py @@ -2,7 +2,6 @@ import wx from logbook import Logger import eos.db -from eos.exception import HandledListActionError from service.fit import Fit @@ -33,16 +32,14 @@ class CalcSwapLocalModuleCommand(wx.Command): mod2 = fit.modules[position2] fit.modules.free(position1) fit.modules.free(position2) - try: - fit.modules.replace(position2, mod1, raiseFailure=True) - except HandledListActionError: + fit.modules.replace(position2, mod1) + if len(fit.modules) <= position2 or fit.modules[position2] is not mod1: fit.modules.replace(position1, mod1) fit.modules.replace(position2, mod2) eos.db.commit() return False - try: - fit.modules.replace(position1, mod2, raiseFailure=True) - except HandledListActionError: + fit.modules.replace(position1, mod2) + if len(fit.modules) <= position1 or fit.modules[position1] is not mod2: fit.modules.free(position2) fit.modules.replace(position1, mod1) fit.modules.replace(position2, mod2) diff --git a/gui/fitCommands/calc/module/projectedAdd.py b/gui/fitCommands/calc/module/projectedAdd.py index 6836c4a43..9d23e6a26 100644 --- a/gui/fitCommands/calc/module/projectedAdd.py +++ b/gui/fitCommands/calc/module/projectedAdd.py @@ -3,7 +3,6 @@ from logbook import Logger import eos.db from eos.const import FittingModuleState -from eos.exception import HandledListActionError from gui.fitCommands.helpers import restoreCheckedStates from service.fit import Fit @@ -39,16 +38,14 @@ class CalcAddProjectedModuleCommand(wx.Command): self.oldPosition, self.oldModInfo = fit.projectedModules.makeRoom(newMod) if self.newPosition is not None: - try: - fit.projectedModules.insert(self.newPosition, newMod, raiseFailure=True) - except HandledListActionError: + fit.projectedModules.insert(self.newPosition, newMod) + if newMod not in fit.projectedModules: if self.commit: eos.db.commit() return False else: - try: - fit.projectedModules.append(newMod, raiseFailure=True) - except HandledListActionError: + fit.projectedModules.append(newMod) + if newMod not in fit.projectedModules: if self.commit: eos.db.commit() return False