def GetPriceHistory(self, typeID): old = self.GetMarketProxy().GetOldPriceHistory(typeID) new = self.GetMarketProxy().GetNewPriceHistory(typeID) history = dbutil.RowList((new.header, [])) lastTime = blue.os.GetWallclockTimeNow() midnightToday = lastTime / const.DAY * const.DAY lastPrice = 0.0 for entry in old: while lastTime + const.DAY < entry.historyDate: lastTime += const.DAY history.append( blue.DBRow( history.header, [lastTime, lastPrice, lastPrice, lastPrice, 0, 0])) history.append(entry) lastTime = entry.historyDate lastPrice = entry.avgPrice while lastTime < midnightToday - const.DAY: lastTime += const.DAY history.append( blue.DBRow(history.header, [lastTime, lastPrice, lastPrice, lastPrice, 0, 0])) if len(new): history.extend(new) else: history.append( blue.DBRow(history.header, [ blue.os.GetWallclockTimeNow(), lastPrice, lastPrice, lastPrice, 0, 0 ])) return history
def OnCorporationVoteCaseOptionChanged(self, corporationID, voteCaseID, optionID, change): try: if corporationID in self.__voteCaseOptionsByCorporation: bAdd, bRemove = self.GetAddRemoveFromChange(change) if bAdd: header = self.__voteCaseOptionsRD if header is None: self.GetVoteCaseOptions(voteCaseID, corporationID) header = self.__voteCaseOptionsRD if voteCaseID not in self.__voteCaseOptionsByCorporation[corporationID]: self.__voteCaseOptionsByCorporation[corporationID][voteCaseID] = dbutil.CIndexedRowset(header, 'optionID') line = blue.DBRow(header) for columnName in header.Keys(): setattr(line, columnName, change[columnName][1]) self.__voteCaseOptionsByCorporation[corporationID][voteCaseID][optionID] = line elif bRemove: if self.__voteCaseOptionsByCorporation[corporationID].has_key(voteCaseID): if self.__voteCaseOptionsByCorporation[corporationID][voteCaseID].has_key(optionID): del self.__voteCaseOptionsByCorporation[corporationID][voteCaseID][optionID] elif self.__voteCaseOptionsByCorporation[corporationID].has_key(voteCaseID): row = self.__voteCaseOptionsByCorporation[corporationID][voteCaseID][optionID] for columnName, oldAndNewValue in change.iteritems(): oldValue, newValue = oldAndNewValue setattr(row, columnName, newValue) finally: uthread.new(self.OnCorporationVoteCaseOptionChanged_thread, corporationID, voteCaseID, optionID, change).context = 'svc.corp.OnCorporationVoteCaseOptionChanged'
def OnLockedItemChange(self, itemID, ownerID, locationID, change): try: if self.itemsByLocationID is None: return if not self.itemsByLocationID.has_key(locationID): self.itemsByLocationID[locationID] = None return if self.itemsByLocationID[locationID] == None: return bAdd, bRemove = self.GetAddRemoveFromChange(change) items = self.itemsByLocationID[locationID] if bAdd: row = blue.DBRow(items.header) for columnName, changes in change.iteritems(): setattr(row, columnName, changes[1]) items[itemID] = row elif bRemove: if items.has_key(itemID): del items[itemID] elif items.has_key(itemID): item = items[itemID] for columnName in change.iterkeys(): setattr(item, columnName, change[columnName][1]) items[itemID] = item finally: sm.ScatterEvent('OnLockedItemChangeUI', itemID, ownerID, locationID, change)
def OnCorporationVoteCaseChanged(self, corporationID, voteCaseID, change): try: if self.__voteCasesByCorporation.has_key(corporationID): bAdd, bRemove = self.GetAddRemoveFromChange(change) if bAdd: row = blue.DBRow( self.__voteCasesByCorporation[corporationID].header) for columnName, values in change.iteritems(): setattr(row, columnName, change[columnName][1]) self.__voteCasesByCorporation[corporationID][ voteCaseID] = row if self.__voteCasesByCorporation[corporationID][ voteCaseID].voteType == const.voteCEO: self.corp__members.MemberCanRunForCEO_ = None elif bRemove: if self.__voteCasesByCorporation[corporationID].has_key( voteCaseID): del self.__voteCasesByCorporation[corporationID][ voteCaseID] elif self.__voteCasesByCorporation[corporationID].has_key( voteCaseID): row = self.__voteCasesByCorporation[corporationID][ voteCaseID] for columnName, oldAndNewValue in change.iteritems(): oldValue, newValue = oldAndNewValue setattr(row, columnName, newValue) finally: uthread.new( self.OnCorporationVoteCaseChanged_thread, corporationID, voteCaseID, change).context = 'svc.corp.OnCorporationVoteCaseChanged'
def OnAllianceRelationshipChanged(self, allianceID, toID, change): if allianceID != eve.session.allianceid: return bAdd, bRemove = self.GetAddRemoveFromChange(change) if self.relationships is not None: if bAdd: if len(change) != len(self.relationships.columns): self.LogWarn( 'IncorrectNumberOfColumns ignoring change as Add change:', change) return line = [] for columnName in self.relationships.columns: line.append(change[columnName][1]) self.relationships[toID] = blue.DBRow( self.relationships.header, line) else: if not self.relationships.has_key(toID): return if bRemove: del self.relationships[toID] else: member = self.relationships[toID] for columnName in change.iterkeys(): setattr(member, columnName[0], change[columnName][1]) sm.GetService('corpui').OnAllianceRelationshipChanged( allianceID, toID, change)
def OnAllianceChanged(self, allianceID, change): bAdd, bRemove = self.GetAddRemoveFromChange(change) if self.alliancesByAllianceID is not None: if bAdd: if len(change) != len(self.alliancesByAllianceID.columns): self.LogWarn('IncorrectNumberOfColumns ignoring change as Add change:', change) return line = [] for columnName in self.alliancesByAllianceID.columns: line.append(change[columnName][1]) self.alliancesByAllianceID[allianceID] = blue.DBRow(self.alliancesByAllianceID.header, line) else: if not self.alliancesByAllianceID.has_key(allianceID): return if bRemove: del self.alliancesByAllianceID[allianceID] else: alliance = self.alliancesByAllianceID[allianceID] for columnName in change.iterkeys(): setattr(alliance, columnName, change[columnName][1]) if cfg.allianceshortnames.data.has_key(allianceID): header = cfg.allianceshortnames.header line = cfg.allianceshortnames.data[allianceID] i = -1 for columnName in header: i = i + 1 if not change.has_key(columnName): continue line[i] = change[columnName][1] sm.GetService('corpui').OnAllianceChanged(allianceID, change)
def __getitem__(self, key): ret = dbutil.CIndexedRowset.__getitem__(self, key) if isinstance(self.rowClass, types.MethodType) or not isinstance(ret, self.rowClass): if not isinstance(ret, blue.DBRow): ret = blue.DBRow(self.header, ret) ret = self.rowClass(self.header, ret) return ret
def OnAllianceApplicationChanged(self, allianceID, corpID, change): try: if corpID == eve.session.corpid: bAdd, bRemove = self.GetAddRemoveFromChange(change) if self.__applicationsByAllianceID is not None: if bAdd: if len(change) != len( self.__applicationsByAllianceID.columns): self.LogWarn( 'IncorrectNumberOfColumns ignoring change as Add change:', change) return line = [] for columnName in self.__applicationsByAllianceID.columns: line.append(change[columnName][1]) self.__applicationsByAllianceID[ allianceID] = blue.DBRow( self.__applicationsByAllianceID.header, line) else: if not self.__applicationsByAllianceID.has_key( allianceID): return if bRemove: del self.__applicationsByAllianceID[allianceID] else: application = self.__applicationsByAllianceID[ allianceID] for columnName in change.iterkeys(): setattr(application, columnName, change[columnName][1]) finally: sm.GetService('corpui').OnAllianceApplicationChanged( allianceID, corpID, change)
def __getitem__(self, key): ret = dbutil.CFilterRowset.__getitem__(self, key) if isinstance(ret, dict): if not isinstance(ret, util.GodmaIndexedRowset): return util.GodmaIndexedRowset(self.header, self.indexName, ret, rowClass=self.rowClass) return ret if isinstance(self.rowClass, types.MethodType) or not isinstance(ret, self.rowClass): if not isinstance(ret, blue.DBRow): print ' _!_ GodmaFilteredRowset storing non-DBRow as leaf-element:', type(ret) ret = blue.DBRow(self.header, ret) return self.rowClass(self.header, ret) return ret
def GetOnlineStatus(self, charID, fetch = True): if util.IsNPC(charID): return False if fetch: self.Prime() if charID not in (self.onlineStatus or {}): if fetch: self.onlineStatus[charID] = blue.DBRow(self.onlineStatus.header, [charID, sm.RemoteSvc('onlineStatus').GetOnlineStatus(charID)]) else: raise IndexError('GetOnlineStatus', charID) if charID in self.onlineStatus: return self.onlineStatus[charID].online else: return None
def __getitem__(self, key): if key in self.loaded: self.loaded[key][1] = blue.os.GetWallclockTime() self.loaded[key][2] += 1 return dict.__getitem__(self, key) pos, size = self.offsets[key] self.dataFile.Seek(pos) blob = self.dataFile.Read(size) data = blue.marshal.Load(blob) if self.cdata: row = blue.DBRow(self.header) row.__cdata__ = data else: row = data self[key] = row self.loaded[key] = [blue.os.GetWallclockTime(), blue.os.GetWallclockTime(), 1] return row
def InsertNew(self, listOfValues): self.append(blue.DBRow(self.header, listOfValues))
def OnContactLoggedOff(self, charID): self.Prime() self.onlineStatus[charID] = blue.DBRow(self.onlineStatus.header, [charID, False])
def OnItemChange(self, item, change): self.LogInfo('OnItemChange', change, item) self.ClearItemClipboard() fancyChange = {} for k, v in change.iteritems(): fancyChange[item.__columns__[k]] = (v, '->', item[k]) self.LogInfo('OnItemChange (fancy)', fancyChange, item) old = blue.DBRow(item) for k, v in change.iteritems(): if k == const.ixSingleton and v == 0: v = 1 if k in (const.ixStackSize, const.ixSingleton): k = const.ixQuantity old[k] = v closeContainer = 0 containerCookie = None containerName = '' if item.groupID in (const.groupWreck, const.groupCargoContainer, const.groupSecureCargoContainer, const.groupAuditLogSecureContainer, const.groupFreightContainer) and item.singleton: if const.ixLocationID in change or const.ixOwnerID in change or const.ixFlag in change: closeContainer = 1 containerName = 'loot_%s' % item.itemID for cookie, wr in self.regs.items(): ob = wr() if not ob or ob.destroyed: self.Unregister(cookie) continue if closeContainer == 1: if getattr(ob, 'id', 0) == item.itemID: containerCookie = cookie continue if getattr(ob, 'name', '') == containerName: containerCookie = cookie continue if hasattr(ob, 'invController'): if ob.invController is None: continue wasHere = old.stacksize != 0 and ob.invController.IsItemHere( old) isHere = item.stacksize != 0 and ob.invController.IsItemHere( item) else: wasHere = old.stacksize != 0 and ob.IsItemHere(old) isHere = item.stacksize != 0 and ob.IsItemHere(item) try: if getattr(ob, 'OnInvChangeAny', None): ob.OnInvChangeAny(item, change) if not wasHere and not isHere: continue if wasHere and isHere and getattr(ob, 'UpdateItem', None): ob.UpdateItem(item, change) elif wasHere and not isHere and getattr( ob, 'RemoveItem', None): ob.RemoveItem(item) elif not wasHere and isHere and getattr(ob, 'AddItem', None): ob.AddItem(item) if getattr(ob, 'OnInvChange', None): ob.OnInvChange(item, change) except: self.Unregister(cookie) log.LogException('svc.inv') sys.exc_clear() if closeContainer == 1: if containerCookie is not None: self.Unregister(containerCookie) sm.GetService('window').CloseContainer(item.itemID)
def OnSanctionedActionChanged(self, corpID, voteCaseID, change): bAdd, bRemove = self.GetAddRemoveFromChange(change) if bAdd: if change.has_key('inEffect'): inEffect = change['inEffect'][1] state = inEffect if inEffect == 0: if change.has_key('expires'): if change['expires'][1] > blue.os.GetWallclockTime(): state = 2 if corpID not in self.__sanctionedActionsByCorpID[state]: rowset = self.GetCorpRegistry( ).GetSanctionedActionsByCorporation(corpID, state) self.__sanctionedActionsByCorpID[state][ corpID] = rowset.Index('voteCaseID') line = [] for columnName in rowset.columns: line.append(change[columnName][1]) self.__sanctionedActionsByCorpID[state][corpID][ voteCaseID] = blue.DBRow( self.__sanctionedActionsByCorpID[state] [corpID].header, line) else: line = [] for columnName in self.__sanctionedActionsByCorpID[state][ corpID].columns: line.append(change[columnName][1]) self.__sanctionedActionsByCorpID[state][corpID][ voteCaseID] = blue.DBRow( self.__sanctionedActionsByCorpID[state] [corpID].header, line) elif bRemove: if self.__sanctionedActionsByCorpID[1].has_key(corpID): if self.__sanctionedActionsByCorpID[1][corpID].has_key( voteCaseID): del self.__sanctionedActionsByCorpID[1][corpID][voteCaseID] elif self.__sanctionedActionsByCorpID[2].has_key(corpID): if self.__sanctionedActionsByCorpID[2][corpID].has_key( voteCaseID): del self.__sanctionedActionsByCorpID[2][corpID][voteCaseID] elif self.__sanctionedActionsByCorpID[0].has_key(corpID): if self.__sanctionedActionsByCorpID[0][corpID].has_key( voteCaseID): del self.__sanctionedActionsByCorpID[0][corpID][voteCaseID] elif change.has_key('inEffect'): oldRow = None oldEffect, newEffect = change['inEffect'] if oldEffect == 0: if self.__sanctionedActionsByCorpID[2].has_key(corpID): if self.__sanctionedActionsByCorpID[2][corpID].has_key( voteCaseID): oldRow = copy.deepcopy( self.__sanctionedActionsByCorpID[2][corpID] [voteCaseID]) del self.__sanctionedActionsByCorpID[2][corpID][ voteCaseID] elif self.__sanctionedActionsByCorpID[0].has_key(corpID): if self.__sanctionedActionsByCorpID[0][corpID].has_key( voteCaseID): oldRow = copy.deepcopy( self.__sanctionedActionsByCorpID[0][corpID] [voteCaseID]) del self.__sanctionedActionsByCorpID[0][corpID][ voteCaseID] else: if self.__sanctionedActionsByCorpID[1].has_key(corpID): if self.__sanctionedActionsByCorpID[1][corpID].has_key( voteCaseID): oldRow = copy.deepcopy( self.__sanctionedActionsByCorpID[1][corpID] [voteCaseID]) del self.__sanctionedActionsByCorpID[1][corpID][ voteCaseID] newEffect = 0 if oldRow is None: oldRow = self.GetCorpRegistry( ).GetSanctionedActionsByCorporation( corpID, newEffect).Index('voteCaseID')[voteCaseID] if corpID not in self.__sanctionedActionsByCorpID[newEffect]: self.__sanctionedActionsByCorpID[newEffect][ corpID] = dbutil.CIndexedRowset(oldRow.header, 'voteCaseID') self.__sanctionedActionsByCorpID[newEffect][corpID][ voteCaseID] = oldRow row = self.__sanctionedActionsByCorpID[newEffect][corpID][ voteCaseID] for columnName, oldAndNewValue in change.iteritems(): oldValue, newValue = oldAndNewValue setattr(row, columnName, newValue) else: row = None if self.__sanctionedActionsByCorpID[1].has_key(corpID): if self.__sanctionedActionsByCorpID[1][corpID].has_key( voteCaseID): row = self.__sanctionedActionsByCorpID[1][corpID][ voteCaseID] elif self.__sanctionedActionsByCorpID[2].has_key(corpID): if self.__sanctionedActionsByCorpID[2][corpID].has_key( voteCaseID): row = self.__sanctionedActionsByCorpID[2][corpID][ voteCaseID] elif self.__sanctionedActionsByCorpID[0].has_key(corpID): if self.__sanctionedActionsByCorpID[0][corpID].has_key( voteCaseID): row = self.__sanctionedActionsByCorpID[0][corpID][ voteCaseID] if row: for columnName, oldAndNewValue in change.iteritems(): oldValue, newValue = oldAndNewValue setattr(row, columnName, newValue) uthread.new(self.OnSanctionedActionChanged_thread, corpID, voteCaseID, change).context = 'svc.corp.OnSanctionedActionChanged'
def OnItemChange(self, item, change): self.LogInfo('OnItemChange', change, item) self.ClearItemClipboard() fancyChange = {} for k, v in change.iteritems(): fancyChange[item.__columns__[k]] = (v, '->', item[k]) self.LogInfo('OnItemChange (fancy)', fancyChange, item) old = blue.DBRow(item) for k, v in change.iteritems(): if k == const.ixSingleton and v == 0: v = 1 if k in (const.ixStackSize, const.ixSingleton): k = const.ixQuantity old[k] = v containerName = '' containerCookie = None closeContainer = self._ShouldCloseContainer(item, change) if closeContainer: containerName = 'loot_%s' % item.itemID for cookie, wr in self.regs.items(): ob = wr() if not ob or ob.destroyed: self.Unregister(cookie) continue if closeContainer == 1: if getattr(ob, 'id', 0) == item.itemID: containerCookie = cookie continue if getattr(ob, 'name', '') == containerName: containerCookie = cookie continue if hasattr(ob, 'invController'): if ob.invController is None: continue wasHere = old.stacksize != 0 and ob.invController.IsItemHere( old) isHere = item.stacksize != 0 and ob.invController.IsItemHere( item) else: wasHere = old.stacksize != 0 and ob.IsItemHere(old) isHere = item.stacksize != 0 and ob.IsItemHere(item) try: if getattr(ob, 'OnInvChangeAny', None): ob.OnInvChangeAny(item, change) if not wasHere and not isHere: continue if wasHere and isHere and getattr(ob, 'UpdateItem', None): ob.UpdateItem(item, change) elif wasHere and not isHere and getattr( ob, 'RemoveItem', None): ob.RemoveItem(item) elif not wasHere and isHere and getattr(ob, 'AddItem', None): ob.AddItem(item) if getattr(ob, 'OnInvChange', None): ob.OnInvChange(item, change) except: self.Unregister(cookie) log.LogException('svc.inv') sys.exc_clear() if closeContainer == 1: if containerCookie is not None: self.Unregister(containerCookie) sm.GetService('window').CloseContainer(item.itemID) if const.ixFlag in change: if change[ const. ixFlag] in invConst.fittingFlags and item.flagID not in invConst.fittingFlags: sm.ScatterEvent('OnModuleUnfitted')
def InsertNew(self, listOfValues): """Create a blue.DBRow from a list of values and append it to the rowset.""" self.append(blue.DBRow(self.header, listOfValues))