(self)
| 17 | self.state = state |
| 18 | |
| 19 | def Do(self): |
| 20 | pyfalog.debug('Doing addition of command fit {} for fit {}'.format(self.commandFitID, self.fitID)) |
| 21 | sFit = Fit.getInstance() |
| 22 | fit = sFit.getFit(self.fitID) |
| 23 | commandFit = sFit.getFit(self.commandFitID) |
| 24 | |
| 25 | # Command fit could have been deleted if we are redoing |
| 26 | if commandFit is None: |
| 27 | pyfalog.debug('Command fit is not available') |
| 28 | return False |
| 29 | # Already commanding this ship |
| 30 | if commandFit in fit.commandFits: |
| 31 | pyfalog.debug('Command fit had been applied already') |
| 32 | return False |
| 33 | if commandFit.ID in fit.commandFitDict: |
| 34 | pyfalog.debug('Commanding fit is in command dict already') |
| 35 | return False |
| 36 | fit.commandFitDict[commandFit.ID] = commandFit |
| 37 | # This bit is required, see issue #83 |
| 38 | eos.db.saveddata_session.flush() |
| 39 | eos.db.saveddata_session.refresh(commandFit) |
| 40 | |
| 41 | if self.state is not None: |
| 42 | fitCommandInfo = commandFit.getCommandInfo(self.fitID) |
| 43 | if fitCommandInfo is None: |
| 44 | pyfalog.warning('Fit command info is not available') |
| 45 | self.Undo() |
| 46 | return False |
| 47 | fitCommandInfo.active = self.state |
| 48 | |
| 49 | return True |
| 50 | |
| 51 | def Undo(self): |
| 52 | pyfalog.debug('Undoing addition of command fit {} for fit {}'.format(self.commandFitID, self.fitID)) |
no test coverage detected