From 57433efe800cd49d410b89a8c0d4b947a3fd261f Mon Sep 17 00:00:00 2001 From: aacn500 Date: Wed, 16 Mar 2016 20:12:26 +0000 Subject: [PATCH 1/3] Check that modules fit on imported fits #512 #522 --- service/port.py | 71 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 57 insertions(+), 14 deletions(-) diff --git a/service/port.py b/service/port.py index 9f98b8383..a1831ddb7 100644 --- a/service/port.py +++ b/service/port.py @@ -123,7 +123,10 @@ class Port(object): # If XML-style start of tag encountered, detect as XML if re.match("<", firstLine): - return "XML", cls.importXml(string, callback, encoding) + if encoding: + return "XML", cls.importXml(string, callback, encoding) + else: + return "XML", cls.importXml(string, callback) # If JSON-style start, parse os CREST/JSON if firstLine[0] == '{': @@ -176,13 +179,21 @@ class Port(object): # When item can't be added to any slot (unknown item or just charge), ignore it except ValueError: continue - if m.isValidState(State.ACTIVE): - m.state = State.ACTIVE + if m.fits(f): + m.owner = f + if m.isValidState(State.ACTIVE): + m.state = State.ACTIVE + + f.modules.append(m) - f.modules.append(m) except: continue + # Check that the states of all modules are valid + sFit = service.Fit.getInstance() + sFit.recalc(f) + sFit.checkStates(f, None) + return f @staticmethod @@ -219,12 +230,19 @@ class Port(object): for i in xrange(int(amount)): try: m = Module(item) - f.modules.append(m) + if m.fits(f): + f.modules.append(m) except: pass + m.owner = f if m.isValidState(State.ACTIVE): m.state = State.ACTIVE + # Check that the states of all modules are valid + sFit = service.Fit.getInstance() + sFit.recalc(f) + sFit.checkStates(f, None) + return f @staticmethod @@ -315,12 +333,15 @@ class Port(object): except: pass - if setOffline is True and m.isValidState(State.OFFLINE): - m.state = State.OFFLINE - elif m.isValidState(State.ACTIVE): - m.state = State.ACTIVE + if m.fits(fit): + m.owner = fit + if setOffline is True and m.isValidState(State.OFFLINE): + m.state = State.OFFLINE + elif m.isValidState(State.ACTIVE): + m.state = State.ACTIVE + + fit.modules.append(m) - fit.modules.append(m) for droneName in droneMap: d = Drone(sMkt.getItem(droneName)) @@ -332,6 +353,11 @@ class Port(object): c.amount = cargoMap[cargoName] fit.cargo.append(c) + # Check that there are no conflicts between active modules + sFit = service.Fit.getInstance() + sFit.recalc(fit) + sFit.checkStates(fit, None) + return fit @staticmethod @@ -467,6 +493,7 @@ class Port(object): # Create module and activate it if it's activable m = Module(modItem) + m.owner = f if m.isValidState(State.ACTIVE): m.state = State.ACTIVE # Add charge to mod if applicable, on any errors just don't add anything @@ -478,7 +505,14 @@ class Port(object): except: pass # Append module to fit - f.modules.append(m) + if m.fits(f): + f.modules.append(m) + + # Check that there are no conflicts between active modules + sFit = service.Fit.getInstance() + sFit.recalc(f) + sFit.checkStates(f, None) + # Append fit to list of fits fits.append(f) @@ -534,12 +568,21 @@ class Port(object): # When item can't be added to any slot (unknown item or just charge), ignore it except ValueError: continue - if m.isValidState(State.ACTIVE): - m.state = State.ACTIVE + if m.fits(f): + m.owner = f + if m.isValidState(State.ACTIVE): + m.state = State.ACTIVE + + f.modules.append(m) - f.modules.append(m) except KeyboardInterrupt: continue + + # Check that the states of all modules are valid + sFit = service.Fit.getInstance() + sFit.recalc(f) + sFit.checkStates(f, None) + fits.append(f) if callback: wx.CallAfter(callback, None) From 18775286c0f062deaf702404a88493f0d049908f Mon Sep 17 00:00:00 2001 From: aacn500 Date: Thu, 17 Mar 2016 11:56:00 +0000 Subject: [PATCH 2/3] only check states when first loading a fit from db --- service/fit.py | 5 +++++ service/port.py | 25 ------------------------- 2 files changed, 5 insertions(+), 25 deletions(-) diff --git a/service/fit.py b/service/fit.py index 085748e85..3761bfc09 100644 --- a/service/fit.py +++ b/service/fit.py @@ -261,6 +261,11 @@ class Fit(object): self.recalc(fit, withBoosters=True) fit.fill() + # Check that the states of all modules are valid + sFit = Fit.getInstance() + sFit.recalc(fit) + sFit.checkStates(fit, None) + eos.db.commit() fit.inited = True return fit diff --git a/service/port.py b/service/port.py index a1831ddb7..8f922ac8d 100644 --- a/service/port.py +++ b/service/port.py @@ -189,11 +189,6 @@ class Port(object): except: continue - # Check that the states of all modules are valid - sFit = service.Fit.getInstance() - sFit.recalc(f) - sFit.checkStates(f, None) - return f @staticmethod @@ -238,11 +233,6 @@ class Port(object): if m.isValidState(State.ACTIVE): m.state = State.ACTIVE - # Check that the states of all modules are valid - sFit = service.Fit.getInstance() - sFit.recalc(f) - sFit.checkStates(f, None) - return f @staticmethod @@ -353,11 +343,6 @@ class Port(object): c.amount = cargoMap[cargoName] fit.cargo.append(c) - # Check that there are no conflicts between active modules - sFit = service.Fit.getInstance() - sFit.recalc(fit) - sFit.checkStates(fit, None) - return fit @staticmethod @@ -508,11 +493,6 @@ class Port(object): if m.fits(f): f.modules.append(m) - # Check that there are no conflicts between active modules - sFit = service.Fit.getInstance() - sFit.recalc(f) - sFit.checkStates(f, None) - # Append fit to list of fits fits.append(f) @@ -578,11 +558,6 @@ class Port(object): except KeyboardInterrupt: continue - # Check that the states of all modules are valid - sFit = service.Fit.getInstance() - sFit.recalc(f) - sFit.checkStates(f, None) - fits.append(f) if callback: wx.CallAfter(callback, None) From 0b858d6e94219b8cdf170226a704c9055da84d78 Mon Sep 17 00:00:00 2001 From: blitzmann Date: Fri, 18 Mar 2016 23:51:55 -0400 Subject: [PATCH 3/3] Clean up call to checkStates --- service/fit.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/service/fit.py b/service/fit.py index 3761bfc09..590651abe 100644 --- a/service/fit.py +++ b/service/fit.py @@ -262,9 +262,7 @@ class Fit(object): fit.fill() # Check that the states of all modules are valid - sFit = Fit.getInstance() - sFit.recalc(fit) - sFit.checkStates(fit, None) + self.checkStates(fit, None) eos.db.commit() fit.inited = True