def LoadMessages_(self): if self.messagePackage is None: self.LoadLabelsAndTcIDs() import dbutil hd, it = self.messagePackage['messages'] rowDescriptor = blue.DBRowDescriptor( (('messageKey', const.DBTYPE_STR), ('messageType', const.DBTYPE_STR), ('messageText', const.DBTYPE_WSTR), ('urlAudio', const.DBTYPE_STR), ('urlIcon', const.DBTYPE_STR), ('dataID', const.DBTYPE_I4))) rowset = dbutil.CRowset(rowDescriptor, []) for li in it.itervalues(): rowset.InsertNew(li) messages = rowset.Index('messageKey') if messages is None: raise RuntimeError( "Mls::LoadMessages: Can't continue without text messages") if prefs.languageID == 'EN': return messages if prefs.languageID not in self.langPacks: translations = self.LoadTranslations(prefs.languageID) else: translations = self.langPacks[prefs.languageID] tcID = self.constants['eve.messages.messageText'] for msg in messages.itervalues(): if not msg.messageText: continue trID = (tcID, msg.dataID) if trID not in translations: if len(translations) >= WARNING_LOG_THRESHOLD: LogTr( "Translation not found for eveMessage '%s'" % msg.dataID, prefs.languageID) else: transText = translations[trID] error = ValidateTranslation(prefs.languageID, (tcID, msg.dataID), msg.messageText, transText) if not error: msg.messageText = transText self.messagePackage = None Log('LoadMessages [%s]: %s entries' % (prefs.languageID, len(messages))) return messages
def GetUnsubmittedChanges(self): if not self.allowUnsubmitted: self.LogInfo( 'Server is not configured to allow fetching of unsubmitted BSD data' ) return self.LogInfo('Updating cfg with unsubmitted BSD data') unsubmitted = self.bulkMgr.GetUnsubmittedChanges() if unsubmitted is None: self.LogInfo('Server had no unsubmitted BSD data for us') return toBeChanged = unsubmitted['toBeChanged'] toBeDeleted = unsubmitted['toBeDeleted'] changedTablesKeys = unsubmitted['changedTablesKeys'] chunkCount = unsubmitted['chunkCount'] for chunkNumber in xrange(0, chunkCount): self.LogInfo('Starting on unsubmitted chunk ', chunkNumber + 1, 'of', chunkCount) if chunkNumber != 0: toBeChanged = self.bulkMgr.GetUnsubmittedChunk(chunkNumber) for bulkID, changes in toBeChanged.iteritems(): if bulkID in cfg.bulkIDsToCfgNames: for cfgName in cfg.bulkIDsToCfgNames[bulkID]: cfgEntry = getattr(cfg, cfgName, None) if isinstance(cfgEntry, sys.Recordset): keyNames = changedTablesKeys[bulkID] for row in changes: try: keyValues = self.GetKeyValues( keyNames, row) except KeyError as e: self.LogError( 'Error in GetUnsubmittedChanges. Key does not exist in the row we wanted to update.', keyNames, row) continue cfgEntry.data[keyValues] = row elif isinstance(cfgEntry, dbutil.CFilterRowset): filterColumnName = cfgEntry.columnName if cfgEntry.indexName is not None: self.LogError( 'BulkSvc.GetUnsubmittedChanges() - Unsupported cfgEntry', cfgName.len(changes)) continue for changedRow in changes: keyValue = changedRow[filterColumnName] if keyValue in cfgEntry: cfgRows = cfgEntry[keyValue] for i, cfgRow in enumerate(cfgRows): for keyName in changedTablesKeys[ bulkID]: if cfgRow[keyName] != changedRow[ keyName]: break else: cfgEntry[keyValue][i] = changedRow break else: cfgEntry[keyValue].append(changedRow) else: if len(cfgEntry) == 0: rowDescriptor = changedRow.__header__ else: rowDescriptor = cfgEntry.itervalues( ).next().header cfgEntry[keyValue] = dbutil.CRowset( rowDescriptor, [changedRow]) elif isinstance(cfgEntry, dbutil.CRowset): toDelete = [] keyNames = changedTablesKeys[bulkID] for i, row in enumerate(cfgEntry): rowKey = self.GetKeyValues(keyNames, row) if rowKey in changes: toDelete.append(i) toDelete.sort(reverse=True) for i in toDelete: del cfgEntry[i] else: self.LogWarn( 'cfgEntry not of type: Recordset, CFilterRowset or CRowset. not updating unsubmitted revisions for it.', cfgName, bulkID) else: self.LogWarn( 'There is an unsubmitted change in bulk', bulkID, "and I don't know what cfg entry it belongs to. Skipping it" ) for bulkID, changes in toBeDeleted.iteritems(): if bulkID not in cfg.bulkIDsToCfgNames: self.LogWarn( 'There is unsubmitted delete change in bulk', bulkID, " that I don't know what cfg entry it belongs to. Skipping it" ) continue for cfgName in cfg.bulkIDsToCfgNames[bulkID]: cfgEntry = getattr(cfg, cfgName, None) if isinstance(cfgEntry, sys.Recordset): for key in changes: if key in cfgEntry.data: del cfgEntry.data[key] else: self.LogWarn( "Can't find revision for an unsubmitted revisions I wanted to delete", cfgName) elif isinstance(cfgEntry, dbutil.CFilterRowset): if cfgEntry.indexName is not None: self.LogError( 'BulkSvc.GetUnsubmittedChanges() - Unsupported cfgEntry', cfgName, len(changes)) continue filterColumnName = cfgEntry.columnName keyNames = changedTablesKeys[bulkID] toDelete = [] for filterKey, filterRows in cfgEntry.iteritems(): for i, filterRow in enumerate(filterRows): key = tuple((getattr(filterRow, keyName, None) for keyName in keyNames)) if key in changes: toDelete.append((i, filterKey)) toDelete.sort(reverse=True) for ix, filterKey in toDelete: del cfgEntry[filterKey][ix] if len(cfgEntry[filterKey]) == 0: del cfgEntry[filterKey] elif isinstance(cfgEntry, dbutil.CRowset): toDelete = [] keyNames = changedTablesKeys[bulkID] for i, row in enumerate(cfgEntry): rowKey = self.GetKeyValues(keyNames, row) if rowKey in changes: toDelete.append(i) toDelete.sort(reverse=True) for i in toDelete: del cfgEntry[i] else: self.LogWarn( 'cfgEntry not of type: Recordset, CFilterRowset or CRowset. not deleting unsubmitted revisions for it.', cfgName, bulkID)
def OnConfigRevisionChange(self, uniqueRefName, cfgEntryName, cacheID, keyIDs, keyCols, oldRow, newRow, source): cfgEntry = getattr(cfg, cfgEntryName, None) keyID, keyID2, keyID3 = keyIDs keyCol1, keyCol2, keyCol3 = keyCols if isinstance(cfgEntry, sys.Recordset): if cfgEntry.keycolumn == keyCol1: if newRow is None: if keyID in cfgEntry.data: del cfgEntry.data[keyID] else: cfgEntry.data[keyID] = newRow else: if oldRow: specialID = oldRow[cfgEntry.keycolumn] if specialID in cfgEntry.data: del cfgEntry.data[specialID] if newRow: specialID = newRow[cfgEntry.keycolumn] cfgEntry.data[specialID] = newRow elif isinstance(cfgEntry, dbutil.CFilterRowset): if oldRow: filterID = oldRow[cfgEntry.columnName] if cfgEntry.indexName: if filterID in cfgEntry: indexID = oldRow[cfgEntry.indexName] if indexID in cfgEntry[filterID]: if cfgEntry.allowDuplicateCompoundKeys: rs = cfgEntry[filterID][indexID] if source == 'local': if oldRow in rs: rs.remove(oldRow) else: self.DeleteRowTheHardWay( rs, keyIDs, keyCols) if len(rs) == 0: del cfgEntry[filterID][indexID] else: del cfgEntry[filterID][indexID] if len(cfgEntry[filterID]) == 0: del cfgEntry[filterID] elif filterID in cfgEntry: rs = cfgEntry[filterID] if source == 'local': if oldRow in rs: rs.remove(oldRow) else: self.DeleteRowTheHardWay(rs, keyIDs, keyCols) if len(rs) == 0: del cfgEntry[filterID] if newRow: filterID = newRow[cfgEntry.columnName] if cfgEntry.indexName: indexID = newRow[cfgEntry.indexName] if cfgEntry.allowDuplicateCompoundKeys: if filterID in cfgEntry: if indexID in cfgEntry[filterID]: cfgEntry[filterID][indexID].append(newRow) else: rs = dbutil.CRowset(cfgEntry.header, [newRow]) cfgEntry[filterID][indexID] = rs else: rs = dbutil.CRowset(cfgEntry.header, [newRow]) cfgEntry[filterID] = {indexID: rs} elif filterID in cfgEntry: cfgEntry[filterID][indexID] = newRow else: cfgEntry[filterID] = {indexID: newRow} elif filterID in cfgEntry: rs = cfgEntry[filterID] rs.append(newRow) else: rs = dbutil.CRowset(cfgEntry.header, [newRow]) cfgEntry[filterID] = rs elif isinstance(cfgEntry, dbutil.CRowset): if source == 'remote': if oldRow: self.DeleteRowTheHardWay(cfgEntry, keyIDs, keyCols) if newRow: cfgEntry.append(newRow) if cfgEntryName == 'worldspaces': cfg._worldspacesDistrictsCache = {} sm.ScatterEvent('OnCfgRevisionChange', uniqueRefName, cfgEntryName, cacheID, keyIDs, keyCols, oldRow, newRow)
def LoadAlliance(self, alliance): if self.alliancesByAllianceID is None: self.alliancesByAllianceID = dbutil.CRowset( alliance.__header__, []).Index('allianceID') self.alliancesByAllianceID[alliance.allianceID] = alliance