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
Example #2
0
def init(achievesMappingXmlPath):
    global BATTLE_APPROACHABLE_ACHIEVES
    global BATTLE_ACHIEVES_WITH_RIBBON
    global BATTLE_ACHIEVES_RIGHT
    global FORT_BATTLE_ACHIEVES_RIGHT
    raise achievesMappingXmlPath or AssertionError("Invalid achievements mapping file")
    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 Exception("Unknown block name", (block, name))
            if "type" not in item.value or item.value["type"] not in ACHIEVEMENT_TYPE.ALL:
                raise Exception("Unknown achievement type", (block, name), item.value)
            if "section" not in item.value or item.value["section"] not in ACHIEVEMENT_SECTION.ALL:
                raise Exception("Unknown achievement section", (block, name), item.value)
            if "mode" not in item.value or item.value["mode"] not in _MODE_CONVERTER:
                raise Exception("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)
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
Example #4
0
def init(achievesMappingXmlPath):
    global BATTLE_APPROACHABLE_ACHIEVES
    global BATTLE_ACHIEVES_WITH_RIBBON
    global BATTLE_ACHIEVES_RIGHT
    global FORT_BATTLE_ACHIEVES_RIGHT
    raise achievesMappingXmlPath or AssertionError('Invalid achievements mapping file')
    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 Exception('Unknown block name', (block, name))
            if 'type' not in item.value or item.value['type'] not in ACHIEVEMENT_TYPE.ALL:
                raise Exception('Unknown achievement type', (block, name), item.value)
            if 'section' not in item.value or item.value['section'] not in ACHIEVEMENT_SECTION.ALL:
                raise Exception('Unknown achievement section', (block, name), item.value)
            if 'mode' not in item.value or item.value['mode'] not in _MODE_CONVERTER:
                raise Exception('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)
Example #5
0
def init(achievesMappingXmlPath):
    global BATTLE_APPROACHABLE_ACHIEVES
    global BATTLE_ACHIEVES_WITH_RIBBON
    global BATTLE_ACHIEVES_RIGHT
    global FORT_BATTLE_ACHIEVES_RIGHT
    raise achievesMappingXmlPath or AssertionError('Invalid achievements mapping file')
    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 Exception('Unknown block name', (block, name))
            if 'type' not in item.value or item.value['type'] not in ACHIEVEMENT_TYPE.ALL:
                raise Exception('Unknown achievement type', (block, name), item.value)
            if 'section' not in item.value or item.value['section'] not in ACHIEVEMENT_SECTION.ALL:
                raise Exception('Unknown achievement section', (block, name), item.value)
            if 'mode' not in item.value or item.value['mode'] not in _MODE_CONVERTER:
                raise Exception('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)
Example #6
0
 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)
Example #7
0
def readXML(path):
    global _cache
    if path in _cache:
        return _cache[path]
    ctx, root = resource_helper.getRoot(path)
    settings = _readSettings(ctx, root)
    messages = _readMessages(ctx, root)
    _cache[path] = (settings, messages)
    return (settings, messages)
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 readXML(path):
    global _cache
    if path in _cache:
        return _cache[path]
    ctx, root = resource_helper.getRoot(path)
    settings = _readSettings(ctx, root)
    styles = _readStyles(ctx, root)
    messages = _readMessages(ctx, root)
    _cache[path] = (settings, styles, messages)
    return (settings, styles, messages)
Example #10
0
 def __readSettingsTemplate(self):
     LOG_DEBUG_DEV_BOOTCAMP('Reading BootCamp template settings')
     ctx, section = resource_helper.getRoot(
         'gui/bootcamp_blocked_settings.xml')
     self.__disabledSettings = []
     for ctx, subSection in resource_helper.getIterator(ctx, section):
         item = resource_helper.readItem(ctx, subSection).value
         if 'controlPath' in item:
             path = item['controlPath'].split('/')
             self.__disabledSettings.append(path)
Example #11
0
    def __loadTweenConstraintsXML(self):
        if ResMgr.isFile(TWEEN_CONSTRAINTS_FILE_PATH):
            ctx, section = resource_helper.getRoot(TWEEN_CONSTRAINTS_FILE_PATH)
            settings = {}
            for ctx, subSection in resource_helper.getIterator(ctx, section):
                item = resource_helper.readItem(ctx, subSection, name='setting')
                settings[item.name] = item.value

            self.__settings.update(settings)
            self.__checkRequiredValues(self.__settings)
        else:
            LOG_ERROR(ERROR_NOT_SUCH_FILE, TWEEN_CONSTRAINTS_FILE_PATH)
Example #12
0
def _readHintsLayouts():
    result = {}
    ctx, section = resource_helper.getRoot(_HINTS_LAYOUT_FILE_PATH)
    for ctx, subSection in resource_helper.getIterator(ctx, section):
        item = resource_helper.readItem(ctx, subSection, name='layout')
        if item.name == 'hints':
            value = _convertHints(item.value)
        else:
            value = item.value
        value['hintID'] = item.name
        result[item.name] = value

    return result
Example #13
0
def _readHintsLayouts():
    result = {}
    ctx, section = resource_helper.getRoot(_HINTS_LAYOUT_FILE_PATH)
    for ctx, subSection in resource_helper.getIterator(ctx, section):
        item = resource_helper.readItem(ctx, subSection, name='layout')
        if item.name == 'hints':
            value = _convertHints(item.value)
        else:
            value = item.value
        value['hintID'] = item.name
        result[item.name] = value

    return result
Example #14
0
    def __loadTweenConstraintsXML(self):
        if ResMgr.isFile(TWEEN_CONSTRAINTS_FILE_PATH):
            ctx, section = resource_helper.getRoot(TWEEN_CONSTRAINTS_FILE_PATH)
            settings = {}
            for ctx, subSection in resource_helper.getIterator(ctx, section):
                item = resource_helper.readItem(ctx,
                                                subSection,
                                                name='setting')
                settings[item.name] = item.value

            self.__settings.update(settings)
            self.__checkRequiredValues(self.__settings)
        else:
            LOG_ERROR(ERROR_NOT_SUCH_FILE, TWEEN_CONSTRAINTS_FILE_PATH)
Example #15
0
 def read(self, path):
     """
     Reads video setting from file.
     @param path: path to file with video setting.
     """
     ctx, section = resource_helper.getRoot(path, safe=True)
     if section is None:
         LOG_WARNING('File with video settings not found. Uses default values', path)
         return
     subCtx, subSection = resource_helper.getSubSection(ctx, section, 'audio', safe=True)
     if subSection:
         self.__setting['audio'] = self.__readTracks(subCtx, subSection)
     subCtx, subSection = resource_helper.getSubSection(ctx, section, 'subtitles', safe=True)
     if subSection:
         self.__setting['subtitles'] = self.__readTracks(subCtx, subSection, offset=1)
     return self
Example #16
0
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
Example #17
0
def readBootcampManagerConfig(xmlPath):
    observers = []
    ctx, section = resource_helper.getRoot(xmlPath)
    for ctx, subSection in resource_helper.getIterator(ctx,
                                                       section['observers']):
        item = resource_helper.readItem(ctx, subSection)
        if not item.name:
            continue
        if 'observerClassName' not in item.value or not item.value[
                'observerClassName']:
            raise Exception('Empty observer class name', item)
        if 'daapiAlias' not in item.value or not item.value['daapiAlias']:
            raise Exception('Empty daapiAlias', item)
        observer = _BootcampManagerObserverConfig(
            item.name, item.value['observerClassName'],
            item.value['daapiAlias'])
        observers.append(observer)

    return {'observers': observers}
Example #18
0
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
Example #19
0
def _readBadges(xmlPath):
    result = {}
    ctx, section = resource_helper.getRoot(xmlPath)
    for ctx, subSection in resource_helper.getIterator(ctx, section['badges']):
        try:
            item = resource_helper.readItem(ctx, subSection, name='badge')
            if not item.name:
                raise Exception('No name for badge is provided', item.name)
            if 'id' not in item.value:
                raise Exception('No ID for badge is provided', item.value)
            value = dict(item.value)
            if 'weight' not in value:
                value['weight'] = -1.0
            if 'type' not in value:
                value['type'] = 0
            value['name'] = item.name
            result[value['id']] = value
        except:
            LOG_CURRENT_EXCEPTION()

    return result
Example #20
0
    def __init__(self):
        """
        constructs GuiSettings instance using values from guiPresetsResource
        """
        self.__settings = _DEFAULT_SETTINGS.copy()
        ctx, section = resource_helper.getRoot(GUI_SETTINGS_FILE_PATH)
        settings = {}
        for ctx, subSection in resource_helper.getIterator(ctx, section):
            item = resource_helper.readItem(ctx, subSection, name='setting')
            if item.name in _SETTING_CONVERTERS:
                setting = _DEFAULT_SETTINGS[item.name]
                converter = _SETTING_CONVERTERS[item.name]
                value = converter(setting, item)
            else:
                value = item.value
            settings[item.name] = value

        if constants.IS_DEVELOPMENT:
            diff = set(self.__settings.keys()) - set(settings.keys())
            if len(diff):
                LOG_NOTE('Settings are not in {0}:'.format(GUI_SETTINGS_FILE_PATH), diff)
        self.__settings.update(settings)
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
Example #22
0
    def __init__(self):
        """
        constructs GuiSettings instance using values from guiPresetsResource
        """
        self.__settings = _DEFAULT_SETTINGS.copy()
        ctx, section = resource_helper.getRoot(GUI_SETTINGS_FILE_PATH)
        settings = {}
        for ctx, subSection in resource_helper.getIterator(ctx, section):
            item = resource_helper.readItem(ctx, subSection, name='setting')
            if item.name in _SETTING_CONVERTERS:
                setting = _DEFAULT_SETTINGS[item.name]
                converter = _SETTING_CONVERTERS[item.name]
                value = converter(setting, item)
            else:
                value = item.value
            settings[item.name] = value

        if constants.IS_DEVELOPMENT:
            diff = set(self.__settings.keys()) - set(settings.keys())
            if len(diff):
                LOG_NOTE(
                    'Settings are not in {0}:'.format(GUI_SETTINGS_FILE_PATH),
                    diff)
        self.__settings.update(settings)
 def parse(self, section):
     ctx, _ = resource_helper.getRoot('')
     return actions.CustomAction(action_name=self._readString(
         'name', section),
                                 **self.__parse(ctx, section))