def _readPreBattleTips(): filters = dict() tips = dict() ctx, root = resource_helper.getRoot(_PREBATTLE_TIPS_XML_PATH) for _, filterSection in resource_helper.getIterator(ctx, root['filters']): filterId = filterSection.readString('id') filters[filterId] = { 'minBattles': filterSection.readInt('minBattles', 0), 'maxBattles': filterSection.readInt('maxBattles', sys.maxint), 'arenaTypes': _readPossibleValues(filterSection, 'arenaTypes'), 'nations': _readPossibleValues(filterSection, 'nations'), 'levels': _readPossibleValues(filterSection, 'levels'), 'vehicleClass': _readPossibleValues(filterSection, 'vehicleClass'), 'tags': _readPossibleValues(filterSection, 'tags'), 'realms': _readPossibleValues(filterSection, 'realms'), 'preceding': _readPrecedingData(filterSection), 'chassisType': filterSection.readInt('chassisType', -1) } for key in _OPTIONAL_FILTER_FLAGS: if filterSection.has_key(key): filters[filterId][key] = filterSection.readBool(key) for _, tipsSection in resource_helper.getIterator(ctx, root['tips']): filterId = tipsSection.readString('filter') tipId = tipsSection.readString('id') status = tipsSection.readString('status', DEFAULT_STATUS) group = tipsSection.readString('group', DEFAULT_GROUP) tipConfig = filters.get(filterId) tips[tipId] = {'filter': tipConfig, 'status': status, 'group': group} resource_helper.purgeResource(_PREBATTLE_TIPS_XML_PATH) return tips
def _readBadges(): result = {} ctx, section = resource_helper.getRoot(_BADGES_XML_PATH) for ctx, subSection in resource_helper.getIterator(ctx, section['badges']): item = resource_helper.readItem(ctx, subSection, name='badge') if not item.name: raise SoftException('No name for badge is provided', item.name) if 'id' not in item.value: raise SoftException('No ID for badge is provided', item.value) value = dict(item.value) realms = value.pop('realm', None) if realms is not None: if CURRENT_REALM in realms.get( 'exclude', []) or 'include' in realms and CURRENT_REALM not in realms.get( 'include', []): continue if 'weight' not in value: value['weight'] = -1.0 if 'type' not in value: value['type'] = 0 if 'layout' not in value: value['layout'] = BadgeLayouts.PREFIX else: layout = value['layout'] if layout not in BadgeLayouts.ALL(): raise SoftException( 'Invalid badge layout type "{}" is provided'.format( layout)) value['name'] = item.name result[value['id']] = value resource_helper.purgeResource(_BADGES_XML_PATH) return result
def load(self, arenaType): if arenaType not in self.__configStorage: if arenaType in _CONF_STORAGES: confStorage = _CONF_STORAGES[arenaType]() self.__configStorage[arenaType] = confStorage _, section = resource_helper.getRoot(_CONFIG_PATH) confStorage.init(section) resource_helper.purgeResource(_CONFIG_PATH)
def _readBattleRoyaleSettings(): _, section = resource_helper.getRoot(_BATTLE_ROYALE_CONFIG_XML_PATH) result = _BRSettings(_readRadarSettings(section['radar']), _readSpawnSettings(section['spawn']), _readTechTreeSettings(section['techTree']), _readVehicleProperties(section['vehicleProperties']), section['upgradeAttentionTime'].asFloat, _readSoundSettings(section['sounds'])) resource_helper.purgeResource(_BATTLE_ROYALE_CONFIG_XML_PATH) return result
def init(achievesMappingXmlPath): global BATTLE_APPROACHABLE_ACHIEVES global BATTLE_ACHIEVES_WITH_RIBBON global BATTLE_ACHIEVES_RIGHT global FORT_BATTLE_ACHIEVES_RIGHT if IS_WEB: return ctx, section = resource_helper.getRoot(achievesMappingXmlPath) for ctx, subSection in resource_helper.getIterator( ctx, section['achievements']): try: item = resource_helper.readItem(ctx, subSection, name='achievement') if not item.name: continue block, name = tuple(item.name.split(':')) if block not in ACHIEVEMENT_BLOCK.ALL: raise SoftException('Unknown block name', (block, name)) if 'type' not in item.value or item.value[ 'type'] not in ACHIEVEMENT_TYPE.ALL: raise SoftException('Unknown achievement type', (block, name), item.value) if 'section' not in item.value or item.value[ 'section'] not in ACHIEVEMENT_SECTION.ALL: raise SoftException('Unknown achievement section', (block, name), item.value) if 'mode' not in item.value or item.value[ 'mode'] not in _MODE_CONVERTER: raise SoftException('Unknown achievement mode', (block, name), item.value) value = dict(item.value) value['mode'] = _MODE_CONVERTER[item.value['mode']] if 'weight' not in value: value['weight'] = -1.0 ACHIEVEMENTS[block, name] = value except: LOG_CURRENT_EXCEPTION() BATTLE_ACHIEVES_WITH_RIBBON = tuple( resource_helper.readList(ctx, section['battleAchievesWithRibbon']).value) BATTLE_ACHIEVES_RIGHT = tuple( resource_helper.readList(ctx, section['battleResultsRight']).value) FORT_BATTLE_ACHIEVES_RIGHT = tuple( resource_helper.readList(ctx, section['fortBattleResultsRight']).value) BATTLE_APPROACHABLE_ACHIEVES = tuple( resource_helper.readList(ctx, section['approachableAchieves']).value) resource_helper.purgeResource(achievesMappingXmlPath)
def readXMLConfig(filename): config = {} ctx, root = resource_helper.getRoot(filename, safe=False) if root is None: return config else: sectionCtx, section = resource_helper.getSubSection(ctx, root, 'common', safe=False) if section is not None: config.update(resource_helper.readDict(sectionCtx, section).value) for key in ('filters', 'formatters', 'handlers', 'loggers'): config[key] = _readConfigItem(key, ctx, root) resource_helper.purgeResource(filename) return config
def readXMLConfig(filename): """ Reads XML file to load the logging configuration as dictionary. Note: Here is no any validation, validation will be applied if trying configure logging package. :param filename: string containing relative path to configuration file that is started from "res" directory. :return: dictionary containing logging configuration. """ config = {} ctx, root = resource_helper.getRoot(filename, safe=False) if root is None: return config else: sectionCtx, section = resource_helper.getSubSection(ctx, root, 'common', safe=False) if section is not None: config.update(resource_helper.readDict(sectionCtx, section).value) for key in ('filters', 'formatters', 'handlers', 'loggers'): config[key] = _readConfigItem(key, ctx, root) resource_helper.purgeResource(filename) return config
def _readSurveys(): result = {} ctx, root = resource_helper.getRoot(_SURVEYS_XML_PATH) for _, serveySection in resource_helper.getIterator(ctx, root['surveys']): bonusType = serveySection['bonusType'].asInt if not bonusType: raise SoftException('Incorrect bonusType for a survey') questionTypes = frozenset( serveySection['questionTypes'].asString.split(' ')) questions = [] for questionSection in serveySection['questions'].values(): if questionSection.has_key('alternatives'): qId = questionSection['questionId'].asString question = _readAlternativeQuestion(questionSection, questionTypes, qId) else: question = _readQuestion(questionSection, questionTypes) questions.append(question) result[bonusType] = questions resource_helper.purgeResource(_SURVEYS_XML_PATH) return result