Raise exceptions on failures to add module to module list
This commit is contained in:
@@ -18,6 +18,8 @@
|
||||
# ===============================================================================
|
||||
|
||||
from logbook import Logger
|
||||
|
||||
from eos.exception import HandledListActionError
|
||||
from utils.deprecated import deprecated
|
||||
|
||||
pyfalog = Logger(__name__)
|
||||
@@ -125,11 +127,11 @@ class HandledModuleList(HandledList):
|
||||
emptyPosition = currPos
|
||||
|
||||
if emptyPosition < len(self):
|
||||
del self[emptyPosition]
|
||||
mod.position = emptyPosition
|
||||
HandledList.insert(self, emptyPosition, mod)
|
||||
self.__toModule(emptyPosition, mod)
|
||||
if mod.isInvalid:
|
||||
self.remove(mod)
|
||||
self.__toDummy(mod.position)
|
||||
raise HandledListActionError(mod)
|
||||
return
|
||||
|
||||
self.appendIgnoreEmpty(mod)
|
||||
@@ -139,7 +141,17 @@ class HandledModuleList(HandledList):
|
||||
HandledList.append(self, mod)
|
||||
if mod.isInvalid:
|
||||
self.remove(mod)
|
||||
return
|
||||
raise HandledListActionError(mod)
|
||||
|
||||
def replace(self, idx, mod):
|
||||
try:
|
||||
oldMod = self[idx]
|
||||
except IndexError:
|
||||
raise HandledListActionError(mod)
|
||||
self.__toModule(idx, mod)
|
||||
if mod.isInvalid:
|
||||
self.__toModule(idx, oldMod)
|
||||
raise HandledListActionError(mod)
|
||||
|
||||
def replaceRackPosition(self, rackPosition, mod):
|
||||
listPositions = []
|
||||
@@ -152,19 +164,24 @@ class HandledModuleList(HandledList):
|
||||
except IndexError:
|
||||
self.appendIgnoreEmpty(mod)
|
||||
else:
|
||||
self.toDummy(modListPosition)
|
||||
self.__toDummy(modListPosition)
|
||||
if not mod.isEmpty:
|
||||
self.toModule(modListPosition, mod)
|
||||
self.__toModule(modListPosition, mod)
|
||||
if mod.isInvalid:
|
||||
self.toDummy(modListPosition)
|
||||
self.__toDummy(modListPosition)
|
||||
raise HandledListActionError(mod)
|
||||
|
||||
def insert(self, index, mod):
|
||||
mod.position = index
|
||||
i = index
|
||||
def insert(self, idx, mod):
|
||||
mod.position = idx
|
||||
i = idx
|
||||
while i < len(self):
|
||||
self[i].position += 1
|
||||
i += 1
|
||||
HandledList.insert(self, index, mod)
|
||||
HandledList.insert(self, idx, mod)
|
||||
if mod.isInvalid:
|
||||
self.remove(mod)
|
||||
raise HandledListActionError(mod)
|
||||
|
||||
|
||||
def remove(self, mod):
|
||||
HandledList.remove(self, mod)
|
||||
@@ -174,14 +191,17 @@ class HandledModuleList(HandledList):
|
||||
for i in range(oldPos, len(self)):
|
||||
self[i].position -= 1
|
||||
|
||||
def toDummy(self, index):
|
||||
def free(self, idx):
|
||||
self.__toDummy(idx)
|
||||
|
||||
def __toDummy(self, index):
|
||||
mod = self[index]
|
||||
if not mod.isEmpty:
|
||||
dummy = mod.buildEmpty(mod.slot)
|
||||
dummy.position = index
|
||||
self[index] = dummy
|
||||
|
||||
def toModule(self, index, mod):
|
||||
def __toModule(self, index, mod):
|
||||
mod.position = index
|
||||
self[index] = mod
|
||||
|
||||
@@ -190,7 +210,7 @@ class HandledModuleList(HandledList):
|
||||
for i in range(len(self)):
|
||||
mod = self[i]
|
||||
if mod.getModifiedItemAttr("subSystemSlot") == slot:
|
||||
self.toDummy(i)
|
||||
self.__toDummy(i)
|
||||
break
|
||||
|
||||
|
||||
|
||||
2
eos/exception.py
Normal file
2
eos/exception.py
Normal file
@@ -0,0 +1,2 @@
|
||||
class HandledListActionError(Exception):
|
||||
...
|
||||
@@ -25,7 +25,7 @@ class FitRemoveModuleCommand(wx.Command):
|
||||
mod = fit.modules[position]
|
||||
if not mod.isEmpty:
|
||||
self.oldModInfos[position] = ModuleInfo.fromModule(mod)
|
||||
fit.modules.toDummy(position)
|
||||
fit.modules.free(position)
|
||||
|
||||
# If no modules were removed, report that command was not completed
|
||||
if not len(self.oldModInfos) > 0:
|
||||
|
||||
@@ -29,13 +29,13 @@ class FitReplaceModuleCommand(wx.Command):
|
||||
if newMod is None:
|
||||
return False
|
||||
# Dummy it out in case the next bit fails
|
||||
fit.modules.toDummy(self.position)
|
||||
fit.modules.free(self.position)
|
||||
if not newMod.fits(fit):
|
||||
pyfalog.warning('Module does not fit')
|
||||
self.Undo()
|
||||
return False
|
||||
newMod.owner = fit
|
||||
fit.modules.toModule(self.position, newMod)
|
||||
fit.modules.replace(self.position, newMod)
|
||||
sFit.checkStates(fit, newMod)
|
||||
eos.db.commit()
|
||||
return True
|
||||
@@ -53,13 +53,13 @@ class FitReplaceModuleCommand(wx.Command):
|
||||
oldMod = self.oldModInfo.toModule()
|
||||
if oldMod is None:
|
||||
return False
|
||||
fit.modules.toDummy(self.position)
|
||||
fit.modules.free(self.position)
|
||||
if not oldMod.fits(fit):
|
||||
pyfalog.warning('Module does not fit')
|
||||
self.Do()
|
||||
return False
|
||||
oldMod.owner = fit
|
||||
fit.modules.toModule(self.position, oldMod)
|
||||
fit.modules.replace(self.position, oldMod)
|
||||
sFit.checkStates(fit, oldMod)
|
||||
eos.db.commit()
|
||||
return True
|
||||
|
||||
@@ -408,7 +408,7 @@ class FitDeprecated(object):
|
||||
modulesChanged = False
|
||||
for x in positions:
|
||||
if not fit.modules[x].isEmpty:
|
||||
fit.modules.toDummy(x)
|
||||
fit.modules.free(x)
|
||||
modulesChanged = True
|
||||
|
||||
# if no modules have changes, report back None
|
||||
@@ -438,7 +438,7 @@ class FitDeprecated(object):
|
||||
item = eos.db.getItem(newItemID, eager=("attributes", "group.category"))
|
||||
|
||||
# Dummy it out in case the next bit fails
|
||||
fit.modules.toDummy(position)
|
||||
fit.modules.free(position)
|
||||
|
||||
try:
|
||||
m = es_Module(item)
|
||||
@@ -448,7 +448,7 @@ class FitDeprecated(object):
|
||||
|
||||
if m.fits(fit):
|
||||
m.owner = fit
|
||||
fit.modules.toModule(position, m)
|
||||
fit.modules.replace(position, m)
|
||||
if m.isValidState(FittingModuleState.ACTIVE):
|
||||
m.state = FittingModuleState.ACTIVE
|
||||
|
||||
|
||||
Reference in New Issue
Block a user