From 45c3533501af3d3b51fe95335bbbc576f607f0d5 Mon Sep 17 00:00:00 2001 From: Ryan Holmes Date: Tue, 30 May 2017 22:57:52 -0400 Subject: [PATCH] Make some extra logging statements and stuff to troubleshoot fit deletion bugs (#1199) --- gui/builtinViewColumns/baseName.py | 8 ++++++++ gui/builtinViews/fittingView.py | 4 +++- gui/projectedView.py | 5 +++++ gui/shipBrowser.py | 7 +++++-- service/fit.py | 13 ++++++++----- 5 files changed, 29 insertions(+), 8 deletions(-) diff --git a/gui/builtinViewColumns/baseName.py b/gui/builtinViewColumns/baseName.py index 6939b8e21..aeae8339f 100644 --- a/gui/builtinViewColumns/baseName.py +++ b/gui/builtinViewColumns/baseName.py @@ -20,6 +20,7 @@ # noinspection PyPackageRequirements import wx +from logbook import Logger from eos.saveddata.cargo import Cargo from eos.saveddata.implant import Implant from eos.saveddata.drone import Drone @@ -30,6 +31,8 @@ from service.fit import Fit as FitSvc from gui.viewColumn import ViewColumn import gui.mainFrame +pyfalog = Logger(__name__) + class BaseName(ViewColumn): name = "Base Name" @@ -56,8 +59,13 @@ class BaseName(ViewColumn): # we need a little more information for the projected view fitID = self.mainFrame.getActiveFit() info = stuff.getProjectionInfo(fitID) + if info: return "%dx %s (%s)" % (stuff.getProjectionInfo(fitID).amount, stuff.name, stuff.ship.item.name) + + pyfalog.warning("Projected View trying to display things that aren't there. stuff: {}, info: {}", repr(stuff), + info) + return "" else: return "%s (%s)" % (stuff.name, stuff.ship.item.name) elif isinstance(stuff, Rack): diff --git a/gui/builtinViews/fittingView.py b/gui/builtinViews/fittingView.py index cc82acdbe..41d3df87f 100644 --- a/gui/builtinViews/fittingView.py +++ b/gui/builtinViews/fittingView.py @@ -278,7 +278,9 @@ class FittingView(d.Display): We also refresh the fit of the new current page in case delete fit caused change in stats (projected) """ + pyfalog.debug("FittingView::fitRemoved") if event.fitID == self.getActiveFit(): + pyfalog.debug(" Deleted fit is currently active") self.parent.DeletePage(self.parent.GetPageIndex(self)) try: @@ -287,7 +289,7 @@ class FittingView(d.Display): sFit.refreshFit(self.getActiveFit()) wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.activeFitID)) except wx._core.PyDeadObjectError: - pyfalog.error("Caught dead object") + pyfalog.warning("Caught dead object") pass event.Skip() diff --git a/gui/projectedView.py b/gui/projectedView.py index e131b88a4..9a772e6ab 100644 --- a/gui/projectedView.py +++ b/gui/projectedView.py @@ -19,6 +19,7 @@ # noinspection PyPackageRequirements import wx +from logbook import Logger import gui.display as d import gui.globalEvents as GE import gui.droneView @@ -31,6 +32,8 @@ from eos.saveddata.drone import Drone as es_Drone from eos.saveddata.fighter import Fighter as es_Fighter from eos.saveddata.module import Module as es_Module +pyfalog = Logger(__name__) + class DummyItem(object): def __init__(self, txt): @@ -174,6 +177,7 @@ class ProjectedView(d.Display): def fitChanged(self, event): sFit = Fit.getInstance() fit = sFit.getFit(event.fitID) + pyfalog.debug("ProjectedView::fitChanged: {}", repr(fit)) self.Parent.Parent.DisablePage(self, not fit or fit.isStructure) @@ -186,6 +190,7 @@ class ProjectedView(d.Display): stuff = [] if fit is not None: + pyfalog.debug(" Collecting list of stuff to display in ProjectedView") self.modules = fit.projectedModules[:] self.drones = fit.projectedDrones[:] self.fighters = fit.projectedFighters[:] diff --git a/gui/shipBrowser.py b/gui/shipBrowser.py index 7570b2aa5..2e5233acb 100644 --- a/gui/shipBrowser.py +++ b/gui/shipBrowser.py @@ -1811,6 +1811,11 @@ class FitItem(SFItem.SFBrowserItem): sFit = Fit.getInstance() fit = sFit.getFit(self.fitID) + # need to delete from import cache before actually deleting fit + if self.shipBrowser.GetActiveStage() == 5: + if fit in self.shipBrowser.lastdata: # remove fit from import cache + self.shipBrowser.lastdata.remove(fit) + sFit.deleteFit(self.fitID) # Notify other areas that a fit has been deleted @@ -1818,8 +1823,6 @@ class FitItem(SFItem.SFBrowserItem): # todo: would a simple RefreshList() work here instead of posting that a stage has been selected? if self.shipBrowser.GetActiveStage() == 5: - if fit in self.shipBrowser.lastdata: # remove fit from import cache - self.shipBrowser.lastdata.remove(fit) wx.PostEvent(self.shipBrowser, ImportSelected(fits=self.shipBrowser.lastdata)) elif self.shipBrowser.GetActiveStage() == 4: wx.PostEvent(self.shipBrowser, SearchSelected(text=self.shipBrowser.navpanel.lastSearch, back=True)) diff --git a/service/fit.py b/service/fit.py index 0031a137d..896ca689d 100644 --- a/service/fit.py +++ b/service/fit.py @@ -166,10 +166,8 @@ class Fit(object): @staticmethod def deleteFit(fitID): - pyfalog.debug("Deleting fit for fit ID: {0}", fitID) fit = eos.db.getFit(fitID) - - eos.db.remove(fit) + pyfalog.debug("Fit::deleteFit - Deleting fit: {}", fit) # refresh any fits this fit is projected onto. Otherwise, if we have # already loaded those fits, they will not reflect the changes @@ -180,16 +178,21 @@ class Fit(object): # error during the command loop refreshFits = set() for projection in fit.projectedOnto.values(): - if projection.victim_fit in eos.db.saveddata_session: # GH issue #359 + if projection.victim_fit != fit and projection.victim_fit in eos.db.saveddata_session: # GH issue #359 refreshFits.add(projection.victim_fit) for booster in fit.boostedOnto.values(): - if booster.boosted_fit in eos.db.saveddata_session: # GH issue #359 + if booster.boosted_fit != fit and booster.boosted_fit in eos.db.saveddata_session: # GH issue #359 refreshFits.add(booster.boosted_fit) + eos.db.saveddata_session.delete(fit) + + pyfalog.debug(" Need to refresh {} fits: {}", len(refreshFits), refreshFits) for fit in refreshFits: eos.db.saveddata_session.refresh(fit) + eos.db.saveddata_session.commit() + @staticmethod def copyFit(fitID): pyfalog.debug("Creating copy of fit ID: {0}", fitID)