当前位置: 首页>>代码示例>>Python>>正文


Python yamlcache.YamlCache类代码示例

本文整理汇总了Python中horizons.util.yamlcache.YamlCache的典型用法代码示例。如果您正苦于以下问题:Python YamlCache类的具体用法?Python YamlCache怎么用?Python YamlCache使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了YamlCache类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _upgrade_to_rev73

	def _upgrade_to_rev73(self, db):
		# Attempt to fix up corrupt yaml dumped into scenario savegames (#2164)
		key = 'scenario_events'
		try:
			yaml_data = db("SELECT name, value FROM metadata WHERE name = ?", key)[0][1]
		except IndexError:
			# Not a scenario, nothing to repair
			return
		try:
			YamlCache.load_yaml_data(yaml_data)
		except ParserError:
			messed_up = 'events: [ { actions: [ {'
			yaml_data = yaml_data.replace(messed_up, '}, ' + messed_up)
			db("UPDATE metadata SET value = ? WHERE name = ?", yaml_data, key)
开发者ID:pinkfloyda,项目名称:unknown-horizons,代码行数:14,代码来源:savegameupgrader.py

示例2: load

	def load(self):
		"""Load selected scenario and show strings"""
		if self.listbox.selected == -1:
			self._gui.findChild(name="hintlbl").text = u"Select a scenario first."
		else:
			self._gui.findChild(name="hintlbl").text = u""

			# remember current entry
			cur_entry = self.logbook.get_cur_entry()
			cur_entry = cur_entry if cur_entry is not None else 0
			self.logbook.clear()

			# get logbook actions from scenario file and add them to our logbook
			scenario_file_path = self.scenarios[0][self.listbox.selected]
			data = YamlCache.load_yaml_data(open(scenario_file_path, 'r'))
			events = data['events']
			for event in events:
				for action in event['actions']:
					if action['type'] in ('logbook', 'logbook'):
						self.logbook.add_captainslog_entry(action['arguments'], show_logbook=False)

			try:
				self.logbook.set_cur_entry(cur_entry)
			except ValueError:
				pass # no entries
			self.logbook._redraw_captainslog()
			self.logbook.show()
开发者ID:ChrisOelmueller,项目名称:unknown-horizons,代码行数:27,代码来源:stringpreviewwidget.py

示例3: update_infos

	def update_infos(self):
		"""Updates the status label while scrolling the scenario list. No up-
		date to logbook messages. Those are loaded after Load/Reload is clicked.
		"""
		scenario_file_path = self.scenarios[0][self.listbox.selected]
		data = YamlCache.load_yaml_data(open(scenario_file_path, 'r'))
		stats = data.get('translation_status', '') # no stats available => empty label
		self.statslabel.text = unicode(stats)
开发者ID:ChrisOelmueller,项目名称:unknown-horizons,代码行数:8,代码来源:stringpreviewwidget.py

示例4: _find_map_filename

	def _find_map_filename(self, cur_locale, mapfile=None):
		"""Finds the given map's filename with its locale."""
		mapfile = mapfile or self._get_selected_map()
		if mapfile.endswith('.yaml'):
			yamldata = YamlCache.get_file(mapfile, game_data=True)
			split_locale = yamldata['locale']
			mapfile = mapfile.split('_' + split_locale)[0]
		return mapfile + '_' + cur_locale + '.' + SavegameManager.scenario_extension
开发者ID:ChrisOelmueller,项目名称:unknown-horizons,代码行数:8,代码来源:singleplayermenu.py

示例5: _loadBuildings

	def _loadBuildings(self):
		print("loading UH buildings...")
		for root, dirnames, filenames in os.walk(util.getUHPath() + '/content/objects/buildings'):
			for filename in fnmatch.filter(filenames, '*.yaml'):
				# This is needed for dict lookups! Do not convert to os.join!
				full_file = root + "/" + filename
				result = YamlCache.get_file(full_file)
				result['yaml_file'] = full_file
				self._loadBuilding(result)

		print("finished loading UH objects")
开发者ID:volpino,项目名称:unknown-horizons,代码行数:11,代码来源:UHObjectLoader.py

示例6: _update_scenario_translation_infos

	def _update_scenario_translation_infos(self, new_map_name):
		"""Fill in translation infos of selected scenario to translation label.
		This function also sets scenario map name using locale.
		(e.g. tutorial -> tutorial_en.yaml)"""
		translation_status_label = self.current.findChild(name="translation_status")
		yamldata = YamlCache.get_file(new_map_name, game_data=True)
		translation_status = yamldata.get('translation_status')
		if translation_status:
			translation_status_label.text = translation_status
			translation_status_label.show()
		else:
			translation_status_label.hide()
		self.current.files[ self.active_right_side.collectData('maplist') ] = new_map_name
开发者ID:Antagonym,项目名称:unknown-horizons,代码行数:13,代码来源:singleplayermenu.py

示例7: test_build_menu_consistency

def test_build_menu_consistency():
	"""
	Check that the same buildings are referenced in both configurations of the build menu.
	"""
	assert len(BuildTab.build_menus) == 2, 'Expected 2 build menu configs'

	buildings = []
	for filename in BuildTab.build_menus:
		with open(os.path.join(ROOT_DIR, filename)) as f:
			data = YamlCache.load_yaml_data(f)
			buildings.append(sorted(list(_get_referenced_buildings(data))))

	assert buildings[0] == buildings[1]
开发者ID:MarkusHackspacher,项目名称:unknown-horizons,代码行数:13,代码来源:test_build_menu_consistency.py

示例8: update_infos

	def update_infos(self):
		"""Updates the status label while scrolling the scenario list. No up-
		date to logbook messages. Those are loaded after Load/Reload is clicked.
		"""
		scenario_file_path = self.scenarios[0][self.listbox.selected]
		data = YamlCache.load_yaml_data(open(scenario_file_path, 'r'))

		if 'metadata' in data:
			# no stats available => empty label
			stats = data['metadata'].get('translation_status', '')
		else:
			# Old scenario syntax version without metadata
			stats = data.get('translation_status', '')
		self.statslabel.text = str(stats)
开发者ID:MarkusHackspacher,项目名称:unknown-horizons,代码行数:14,代码来源:stringpreviewwidget.py

示例9: get_scenario_info

	def get_scenario_info(cls, name="", filename=""):
		"""Return this scenario data"""
		sfiles, snames = cls.get_scenarios(include_displaynames = True)
		if name:
			if not name in snames:
				print "Error: Cannot find scenario '{name}'.".format(name=name)
				return {}
			index = snames.index(name)
		elif filename:
			if not filename in sfiles:
				print "Error: Cannot find scenario '{name}'.".format(name=filename)
				return {}
			index = sfiles.index(filename)
		data = YamlCache.get_file(sfiles[index], game_data=True)
		return data
开发者ID:Hadescho,项目名称:unknown-horizons,代码行数:15,代码来源:savegamemanager.py

示例10: load_units

	def load_units(cls, load_now=False):
		cls.log.debug("Entities: loading units")
		if hasattr(cls, 'units'):
			cls.log.debug("Entities: units already loaded")
			return
		cls.units = _EntitiesLazyDict()

		from horizons.world.units import UnitClass
		for root, dirnames, filenames in os.walk('content/objects/units'):
			for filename in fnmatch.filter(filenames, '*.yaml'):
				full_file = os.path.join(root, filename)
				result = YamlCache.get_file(full_file, game_data=True)
				unit_id = int(result['id'])
				cls.units.create_on_access(unit_id, Callback(UnitClass, id=unit_id, yaml_data=result))
				if load_now:
					cls.units[unit_id]
开发者ID:STEVEOO6,项目名称:unknown-horizons,代码行数:16,代码来源:entities.py

示例11: get_scenario_metadata

	def get_scenario_metadata(cls, scenario="", filename=""):
		"""Return the `metadata` dict for a scenario.

		Pass either the scenario name (*scenario*) or a .yaml *filename*.
		"""
		sfiles, snames = cls.get_scenarios(include_displaynames=True)
		if scenario:
			if scenario not in snames:
				cls.log.error("Error: Cannot find scenario '{name}'.".format(name=scenario))
				return {}
			index = snames.index(scenario)
		elif filename:
			if filename not in sfiles:
				cls.log.error("Error: Cannot find scenario '{name}'.".format(name=filename))
				return {}
			index = sfiles.index(filename)
		data = YamlCache.get_file(sfiles[index], game_data=True)
		return data.get('metadata', {})
开发者ID:JamesOravec,项目名称:unknown-horizons,代码行数:18,代码来源:savegamemanager.py

示例12: get_building_tiers

	def get_building_tiers(cls):
		"""Returns a dictionary mapping building type ids to their tiers
		@return cached dictionary (don't modifiy)"""
		building_tiers = {}
		data = YamlCache.get_file( cls.build_menu_config_per_tier, game_data=True )
		tier = -1
		for tab, tabdata in sorted(data.iteritems()):
			if tab == "meta":
				continue # not a tab

			tier += 1

			for row in tabdata:
				if isinstance(row, list): # actual content
					for entry in row:
						if isinstance(entry, int): # actual building button
							building_tiers[entry] = tier
		return building_tiers
开发者ID:BenjaminHarper,项目名称:unknown-horizons,代码行数:18,代码来源:buildtabs.py

示例13: create_tabs

    def create_tabs(cls, session, build_callback):
        """Create according to current build menu config
		@param build_callback: function to call to enable build mode, has to take building type parameter
		"""
        source = cls.cur_build_menu_config

        # parse
        data = YamlCache.get_file(source, game_data=True)
        if "meta" not in data:
            raise InvalidBuildMenuFileFormat('File does not contain "meta" section')
        metadata = data["meta"]
        if "unlocking_strategy" not in metadata:
            raise InvalidBuildMenuFileFormat('"meta" section does not contain "unlocking_strategy"')
        try:
            unlocking_strategy = cls.unlocking_strategies.get_item_for_string(metadata["unlocking_strategy"])
        except KeyError:
            raise InvalidBuildMenuFileFormat('Invalid entry for "unlocking_strategy"')

            # create tab instances
        tabs = []
        for tab, tabdata in sorted(data.iteritems()):
            if tab == "meta":
                continue  # not a tab

            if (
                unlocking_strategy == cls.unlocking_strategies.tab_per_tier
                and len(tabs) > session.world.player.settler_level
            ):
                break

            try:
                tab = BuildTab(session, len(tabs), tabdata, build_callback, unlocking_strategy, source)
                tabs.append(tab)
            except Exception as e:
                to_add = "\nThis error happened in %s of %s ." % (tab, source)
                e.args = (e.args[0] + to_add,) + e.args[1:]
                e.message = e.message + to_add
                raise

        return tabs
开发者ID:hansjoachim,项目名称:unknown-horizons,代码行数:40,代码来源:buildtabs.py

示例14: get_campaigns

	def get_campaigns(cls, include_displaynames=True, include_scenario_list=False, campaign_data=False):
		"""Returns all campaigns
		@param include_displaynames: should we return the name of the campaign
		@param include_scenario_list: should we return the list of scenarios in the campaign
		@param campaign_data: should we return the full campaign data
		@return: (campaign_files, campaign_names, campaign_scenarios, campaign_data) (depending of the parameters)
		"""
		cls.log.debug("Savegamemanager: campaigns from: %s", cls.campaigns_dir)
		files, names = cls.__get_saves_from_dirs([cls.campaigns_dir], include_displaynames, cls.campaign_extension, False)
		if not include_displaynames:
			return (files,)
		if not include_scenario_list:
			return (files, names)
		scenarios_lists = []
		campaign_datas = []
		for i, f in enumerate(files):
			campaign = YamlCache.get_file(f)
			campaign_datas.append(campaign)
			scenarios_lists.append([sc.get('level') for sc in campaign.get('scenarios',[])])
		if not campaign_data:
			return (files, names, scenarios_lists)
		return (files, names, scenarios_lists, campaign_datas)
开发者ID:acieroid,项目名称:unknown-horizons,代码行数:22,代码来源:savegamemanager.py

示例15: load

    def load(self):
        """Load selected scenario and show strings"""
        # remember current entry
        cur_entry = self.logbook.get_cur_entry()
        cur_entry = cur_entry if cur_entry is not None else 0
        self.logbook.clear()

        # get logbook actions from scenario file and add them to our logbook
        scenario_file_path = self.scenarios[0][self.listbox.selected]
        data = YamlCache.load_yaml_data(open(scenario_file_path, "r"))
        events = data["events"]
        for event in events:
            for action in event["actions"]:
                if action["type"] in ("logbook", "logbook"):
                    self.logbook.add_captainslog_entry(action["arguments"], show_logbook=False)

        try:
            self.logbook.set_cur_entry(cur_entry)
        except ValueError:
            pass  # no entries
        self.logbook._redraw_captainslog()
        self.logbook.show()
开发者ID:ThePawnBreak,项目名称:unknown-horizons,代码行数:22,代码来源:stringpreviewwidget.py


注:本文中的horizons.util.yamlcache.YamlCache类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。