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 __readTracks(self, ctx, section, offset = 0): result = {} iterator = resource_helper.getIterator(ctx, section) for idx, (subCtx, subSec) in enumerate(iterator): for langCtx, langSec in resource_helper.getIterator(subCtx, subSec): lang = resource_helper.readStringItem(langCtx, langSec).value if len(lang) > 0: result[lang] = idx + offset return result
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 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 __readChapters(ctx, root, filterFunction): ctx, section = resource_helper.getSubSection(ctx, root, 'chapters') chapters = [] index = 0 for chapterCtx, chapterSection in resource_helper.getIterator(ctx, section): filePath = __getCustomSectionValue(chapterCtx, chapterSection, 'file-path') title = __getCustomSectionValue(chapterCtx, chapterSection, 'title') background = __getCustomSectionValue(chapterCtx, chapterSection, 'background') attributes = __getChapterAttributes(filePath, filterFunction) ids = attributes.get('ids', []) if len(ids) != len(set(ids)): _logger.warning('chapter %s has duplicate page ids', title) chapter = {'filePath': filePath, 'pageIDs': ids, 'newPageIDs': attributes.get('newIds', []), 'uiData': {'index': int(index), 'label': translation(title), 'image': background, 'tooltip': makeTooltip(translation(title), '\n'.join(attributes.get('chaptersTitles', [])))}} if any((ids in chapter['pageIDs'] for chapter in chapters)): _logger.warning('chapter %s has duplicate page ids from another chapters', title) _logger.debug('ManualXMLDataReader: Read chapters. Chapter: %s', chapter) chapters.append(chapter) index += 1 return chapters
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 _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
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
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)
def _readConfigItem(key, ctx, section): ctx, sub = resource_helper.getSubSection(ctx, section, key, safe=True) config = {} if sub is not None: for itemCtx, item in resource_helper.getIterator(ctx, sub): source = resource_helper.readDict(itemCtx, item) config[source.name] = source.value return config
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)
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))
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
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
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))
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)
def __readChapter(ctx, root, isBootcampEnabled, bootcampRunCount): pages = [] details = [] index = 0 ctx, section = resource_helper.getSubSection(ctx, root, 'lessons') for lessonCtx, lessonSection in resource_helper.getIterator(ctx, section): template = __getCustomSectionValue(lessonCtx, lessonSection, 'template') title = translation( __getCustomSectionValue(lessonCtx, lessonSection, 'title')) background = __getCustomSectionValue(lessonCtx, lessonSection, 'background') description = __getCustomSectionValue(lessonCtx, lessonSection, 'description', safe=True) if description is None: description = '' else: description = translation(description) contentRendererLinkage = '' if template is _BOOTCAMP_PAGE: if not isBootcampEnabled: continue contentRendererData = __getBootcampRendererData(bootcampRunCount) contentRendererLinkage = _MANUAL_LESSON_TEMPLATES.get(template) else: contentRendererData, hintsCount = __getHintsRendererData( lessonCtx, lessonSection) if hintsCount > 0: contentRendererLinkage = _MANUAL_LESSON_TEMPLATES.get(template) pages.append({ 'buttonsGroup': 'ManualChapterGroup', 'pageIndex': int(index), 'selected': False, 'label': str(int(index) + 1), 'tooltip': { 'tooltip': makeTooltip(title) } }) details.append({ 'title': title, 'description': description, 'background': background, 'contentRendererLinkage': contentRendererLinkage, 'contentRendererData': contentRendererData }) index += 1 chapterData = {'pages': pages, 'details': details} _logger.debug('ManualXMLDataReader: Read chapter: %s', chapterData) return chapterData
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
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
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
def __getChaptersTitlesList(chapterFileName, isBootcampEnabled): chaptersTitles = [] chapterPath = _CHAPTERS_DATA_PATH + chapterFileName with resource_helper.root_generator(chapterPath) as ctx, root: ctx, section = resource_helper.getSubSection(ctx, root, 'lessons') for lessonCtx, lessonSection in resource_helper.getIterator(ctx, section): title = translation(__getCustomSectionValue(lessonCtx, lessonSection, 'title')) template = __getCustomSectionValue(lessonCtx, lessonSection, 'template') if template is _BOOTCAMP_PAGE and not isBootcampEnabled: continue chaptersTitles.append(title) return chaptersTitles
def __getHintsRendererData(lessonCtx, lessonSection): hints = [] contentRendererData = None hintsCtx, hintsSection = resource_helper.getSubSection(lessonCtx, lessonSection, 'hints', safe=True) if hintsSection is not None: for hintCtx, hintSection in resource_helper.getIterator(hintsCtx, hintsSection): hintText = translation(__getCustomSectionValue(hintCtx, hintSection, 'text')) hintIcon = __getCustomSectionValue(hintCtx, hintSection, 'icon') hints.append({'text': hintText, 'icon': hintIcon}) contentRendererData = {'hints': hints} return (contentRendererData, len(hints))
def __readChapter(ctx, root, filterFunction, bootcampRunCount, chapterTitle=''): pages = [] details = [] index = 0 ctx, section = resource_helper.getSubSection(ctx, root, 'lessons') for lessonCtx, lessonSection in resource_helper.getIterator(ctx, section): template = __getCustomSectionValue(lessonCtx, lessonSection, 'template') if not filterFunction(template): continue title = translation(__getCustomSectionValue(lessonCtx, lessonSection, 'title')) background = __getCustomSectionValue(lessonCtx, lessonSection, 'background') description = __getCustomSectionValue(lessonCtx, lessonSection, 'description', safe=True) pageId = __getCustomSectionValue(lessonCtx, lessonSection, 'id') if description is None: description = '' else: description = translation(description) contentRendererLinkage = '' if template == ManualPageTypes.MAPS_TRAINING_PAGE: contentRendererData = {'text': backport.text(R.strings.maps_training.manualPage.button())} contentRendererLinkage = _MANUAL_LESSON_TEMPLATES.get(template) elif template == ManualPageTypes.BOOTCAMP_PAGE: contentRendererData = __getBootcampRendererData(bootcampRunCount) contentRendererLinkage = _MANUAL_LESSON_TEMPLATES.get(template) elif template == ManualPageTypes.VIDEO_PAGE: contentRendererData = __getVideoRendererData(lessonCtx, lessonSection) contentRendererLinkage = _MANUAL_LESSON_TEMPLATES.get(template) else: contentRendererData, hintsCount = __getHintsRendererData(lessonCtx, lessonSection) if hintsCount > 0: contentRendererLinkage = _MANUAL_LESSON_TEMPLATES.get(template) pages.append({'buttonsGroup': 'ManualChapterGroup', 'pageIndex': int(index), 'selected': False, 'hasNewContent': __isNew(lessonCtx, lessonSection), 'label': str(int(index) + 1), 'tooltip': {'tooltip': makeTooltip(title)}}) details.append({'title': title, 'chapterTitle': chapterTitle, 'description': description, 'background': background, 'contentRendererLinkage': contentRendererLinkage, 'contentRendererData': contentRendererData, 'id': pageId, 'pageType': template}) index += 1 chapterData = {'pages': pages, 'details': details} _logger.debug('ManualXMLDataReader: Read chapter: %s', chapterData) return chapterData
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
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
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
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
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
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}
def __readChapters(ctx, root, isBootcampEnabled): ctx, section = resource_helper.getSubSection(ctx, root, 'chapters') chapters = [] index = 0 for chapterCtx, chapterSection in resource_helper.getIterator(ctx, section): filePath = __getCustomSectionValue(chapterCtx, chapterSection, 'file-path') title = __getCustomSectionValue(chapterCtx, chapterSection, 'title') background = __getCustomSectionValue(chapterCtx, chapterSection, 'background') lessonsTitlesList = __getChaptersTitlesList(filePath, isBootcampEnabled) chapter = {'filePath': filePath, 'uiData': {'index': int(index), 'label': translation(title), 'image': background, 'tooltip': makeTooltip(translation(title), '\n'.join(lessonsTitlesList))}} _logger.debug('ManualXMLDataReader: Read chapters. Chapter: %s', chapter) chapters.append(chapter) index += 1 return chapters
def __getChapterAttributes(chapterFileName, filterFunction): chaptersTitles = [] ids = [] newIds = [] chapterPath = _CHAPTERS_DATA_PATH + chapterFileName with resource_helper.root_generator(chapterPath) as ctx, root: ctx, section = resource_helper.getSubSection(ctx, root, 'lessons') for lessonCtx, lessonSection in resource_helper.getIterator(ctx, section): template = __getCustomSectionValue(lessonCtx, lessonSection, 'template') if not filterFunction(template): continue lessonId = int(__getCustomSectionValue(lessonCtx, lessonSection, 'id')) ids.append(lessonId) if __getCustomSectionValue(lessonCtx, lessonSection, 'new', safe=True): newIds.append(lessonId) chaptersTitles.append(translation(__getCustomSectionValue(lessonCtx, lessonSection, 'title'))) return {'ids': ids, 'newIds': newIds, 'chaptersTitles': chaptersTitles}
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
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
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)