コード例 #1
0
    def __parse(self, ctx, section):
        res = {}
        for c, ss in resource_helper.getIterator(ctx, section):
            val = resource_helper.readItem(c, ss, ss.name).value
            res[self.__getKeyName(ss)] = val if val else self.__parse(c, ss)

        if not res:
            res[self.__getKeyName(section)] = resource_helper.readItem(
                ctx, section, section.name).value
        if 'action_class' not in res.keys():
            res['action_class'] = resource_helper.readItem(
                ctx, section, section.name).value
        return res
コード例 #2
0
ファイル: uiachievements.py プロジェクト: aevitas/wotsdk
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)
コード例 #3
0
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
コード例 #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)
コード例 #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)
コード例 #6
0
def __getCustomSectionValue(ctx, section, name, safe=False):
    valueCtx, valueSection = resource_helper.getSubSection(ctx, section, name, safe)
    result = None
    if valueSection is not None:
        item = resource_helper.readItem(valueCtx, valueSection, name)
        result = item.value
    return result
コード例 #7
0
def _readSettings(ctx, root):
    ctx, section = resource_helper.getSubSection(ctx, root, 'settings')
    settings = _getDefaultSettings()
    for xmlCtx, subSection in resource_helper.getIterator(ctx, section):
        item = resource_helper.readItem(xmlCtx, subSection, 'setting')
        settings[item.name] = item.value

    return settings
コード例 #8
0
def _readSettings(ctx, root):
    ctx, section = resource_helper.getSubSection(ctx, root, "settings")
    settings = _getDefaultSettings()
    for ctx, subSection in resource_helper.getIterator(ctx, section):
        item = resource_helper.readItem(ctx, subSection, "setting")
        settings[item.name] = item.value

    return settings
コード例 #9
0
def _readSettings(ctx, root):
    ctx, section = resource_helper.getSubSection(ctx, root, 'settings')
    settings = _getDefaultSettings()
    for ctx, subSection in resource_helper.getIterator(ctx, section):
        item = resource_helper.readItem(ctx, subSection, 'setting')
        settings[item.name] = item.value

    return _MessagesSettings(**settings)
コード例 #10
0
def _readInvokeGuiCmdSection(xmlCtx, section, _, conditions):
    commandID = parseID(xmlCtx, section, 'Specify a command ID')
    argOverrides = {}
    argsSection = _xml.getSubsection(xmlCtx, section, 'args', throwIfMissing=False)
    if argsSection is not None:
        for _, subSec in argsSection.items():
            arg = resource_helper.readItem(xmlCtx, subSec, 'arg')
            argOverrides[arg.name] = arg.value

    return effects.InvokeGuiCommand(commandID, argOverrides, conditions=conditions)
コード例 #11
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)
コード例 #12
0
def _readMessages(ctx, root):
    ctx, section = resource_helper.getSubSection(ctx, root, 'messages')
    messages = {}
    for xmlCtx, subSection in resource_helper.getIterator(ctx, section):
        item = resource_helper.readItem(xmlCtx, subSection, 'message')
        text, aliases = item.value
        aliases = aliases.split(',', 1)
        if len(aliases) == 1:
            aliases *= 2
        messages[item.name] = (html.translation(text), tuple(aliases))

    return messages
コード例 #13
0
def _readMessages(ctx, root):
    ctx, section = resource_helper.getSubSection(ctx, root, 'messages')
    messages = {}
    for ctx, subSection in resource_helper.getIterator(ctx, section):
        item = resource_helper.readItem(ctx, subSection, 'message')
        text, aliases = item.value
        aliases = aliases.split(',', 1)
        if len(aliases) == 1:
            aliases *= 2
        messages[item.name] = (html.translation(text), tuple(aliases))

    return messages
コード例 #14
0
def _readMacros(xmlCtx, section, valueName='value'):
    result = {}
    name = resource_helper.readItemName(xmlCtx, section)
    macros = _readItemMacros(xmlCtx, section)
    subCtx, subSection = resource_helper.getSubSection(xmlCtx, section, valueName)
    for nextCtx, nextSection in resource_helper.getIterator(subCtx, subSection):
        item = resource_helper.readItem(nextCtx, nextSection)
        if not item.name:
            raise resource_helper.ResourceError(nextCtx, '{0}: name is required in each item'.format(name))
        result[item.name] = item.value

    return resource_helper.ResourceItem('macros', name, _MacrosValue(macros, result))
コード例 #15
0
ファイル: guisettings.py プロジェクト: webiumsk/WOT-0.9.14-CT
def _readMacros(xmlCtx, section, valueName = 'value'):
    result = {}
    name = resource_helper.readItemName(xmlCtx, section)
    macros = _readItemMacros(xmlCtx, section)
    subCtx, subSection = resource_helper.getSubSection(xmlCtx, section, valueName)
    for nextCtx, nextSection in resource_helper.getIterator(subCtx, subSection):
        item = resource_helper.readItem(nextCtx, nextSection)
        if not item.name:
            raise resource_helper.ResourceError(nextCtx, '{0}: name is required in each item'.format(name))
        result[item.name] = item.value

    return resource_helper.ResourceItem('macros', name, _MacrosValue(macros, result))
コード例 #16
0
ファイル: tweensystem.py プロジェクト: webiumsk/WOT-0.9.12
    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)
コード例 #17
0
ファイル: hints_layout.py プロジェクト: kblw/wot_client
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
コード例 #18
0
def _readStyles(ctx, root):
    ctx, section = resource_helper.getSubSection(ctx, root, 'styles', safe=True)
    styles = {}
    if section is not None:
        for xmlCtx, subSection in resource_helper.getIterator(ctx, section):
            item = resource_helper.readItem(xmlCtx, subSection, 'style')
            expectedKeys = _EXPECTED_STYLES[item.name]
            for key in expectedKeys:
                pass

            styles[item.name] = item.value

    return styles
コード例 #19
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
コード例 #20
0
ファイル: gui_config.py プロジェクト: kblw/wot_client
def _readConfig(ctx, root, parentTag, childTag, itemClass):
    ctx, section = resource_helper.getSubSection(ctx, root, parentTag, safe=True)
    if not section:
        return {}
    config = {}
    for ctx, subSection in resource_helper.getIterator(ctx, section):
        item = resource_helper.readItem(ctx, subSection, childTag)
        assert item.type == _ITEM_TYPE.DICT, "Type of value should be dict"
        name = item.name
        if name in config:
            raise resource_helper.ResourceError(ctx, "Item {0} is duplicated.".format(name))
        config[name] = itemClass(**item.value)

    return config
コード例 #21
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)
コード例 #22
0
ファイル: gui_config.py プロジェクト: kusaku/wot_scripts
def _readConfig(ctx, root, parentTag, childTag, itemClass):
    ctx, section = resource_helper.getSubSection(ctx, root, parentTag, safe=True)
    if not section:
        return {}
    config = {}
    for xmlCtx, subSection in resource_helper.getIterator(ctx, section):
        item = resource_helper.readItem(xmlCtx, subSection, childTag)
        if not item.type == _ITEM_TYPE.DICT:
            raise AssertionError('Type of value should be dict')
            name = item.name
            raise name in config and resource_helper.ResourceError(xmlCtx, 'Item {0} is duplicated.'.format(name))
        config[name] = itemClass(**item.value)

    return config
コード例 #23
0
def _readStyles(ctx, root):
    ctx, section = resource_helper.getSubSection(ctx, root, 'styles', safe=True)
    styles = {}
    if section is not None:
        for xmlCtx, subSection in resource_helper.getIterator(ctx, section):
            item = resource_helper.readItem(xmlCtx, subSection, 'style')
            raise item.name in _EXPECTED_STYLES or AssertionError('Style section %s is not expected!' % item.name)
            expectedKeys = _EXPECTED_STYLES[item.name]
            for key in expectedKeys:
                raise key in item.value or AssertionError('Style option %s is expected in section %s!' % (key, item.name))

            styles[item.name] = item.value

    return styles
コード例 #24
0
def _readStyles(ctx, root):
    ctx, section = resource_helper.getSubSection(ctx, root, "styles", safe=True)
    styles = {}
    if section is not None:
        for ctx, subSection in resource_helper.getIterator(ctx, section):
            item = resource_helper.readItem(ctx, subSection, "style")
            raise item.name in _EXPECTED_STYLES or AssertionError("Style section %s is not expected!" % item.name)
            expectedKeys = _EXPECTED_STYLES[item.name]
            for key in expectedKeys:
                raise key in item.value or AssertionError(
                    "Style option %s is expected in section %s!" % (key, item.name)
                )

            styles[item.name] = item.value

    return styles
コード例 #25
0
def _readConfig(ctx, root, parentTag, childTag, itemClass):
    ctx, section = resource_helper.getSubSection(ctx,
                                                 root,
                                                 parentTag,
                                                 safe=True)
    if not section:
        return {}
    config = {}
    for xmlCtx, subSection in resource_helper.getIterator(ctx, section):
        item = resource_helper.readItem(xmlCtx, subSection, childTag)
        name = item.name
        if name in config:
            raise resource_helper.ResourceError(
                xmlCtx, 'Item {0} is duplicated.'.format(name))
        config[name] = itemClass(**item.value)

    return config
コード例 #26
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}
コード例 #27
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
コード例 #28
0
ファイル: guisettings.py プロジェクト: webiumsk/WOT-0.9.12
    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)
コード例 #29
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)