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


Python DbReader.execute_script方法代码示例

本文整理汇总了Python中horizons.util.dbreader.DbReader.execute_script方法的典型用法代码示例。如果您正苦于以下问题:Python DbReader.execute_script方法的具体用法?Python DbReader.execute_script怎么用?Python DbReader.execute_script使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在horizons.util.dbreader.DbReader的用法示例。


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

示例1: save_map

# 需要导入模块: from horizons.util.dbreader import DbReader [as 别名]
# 或者: from horizons.util.dbreader.DbReader import execute_script [as 别名]
	def save_map(self, path, prefix):
		map_file = os.path.join(path, prefix + '.sqlite')
		if os.path.exists(map_file):
			os.unlink(map_file) # the process relies on having an empty file

		db = DbReader(map_file)
		with open('content/map-template.sql') as map_template:
			db.execute_script(map_template.read())

		db('BEGIN')
		for island_id, coords_list in self._iter_islands():
			for x, y in coords_list:
				tile = self.world.full_map[(x, y)]
				db('INSERT INTO ground VALUES(?, ?, ?, ?, ?, ?)', island_id, x, y, tile.id, tile.shape, tile.rotation + 45)
		db('COMMIT')
		db.close()
开发者ID:flaviusanton,项目名称:unknown-horizons,代码行数:18,代码来源:worldeditor.py

示例2: check_files

# 需要导入模块: from horizons.util.dbreader import DbReader [as 别名]
# 或者: from horizons.util.dbreader.DbReader import execute_script [as 别名]
    def check_files(cls):
        """Check that the required atlas files exist."""
        paths = [
            "content" + os.sep + "actionsets.json",
            "content" + os.sep + "atlas.sql",
            "content" + os.sep + "tilesets.json",
        ]
        for path in paths:
            if not os.path.exists(path):
                return False

                # verify that the combined images exist
        db = DbReader(":memory:")
        db.execute_script(open("content" + os.sep + "atlas.sql").read())
        for db_row in db("SELECT atlas_path FROM atlas"):
            if not os.path.exists(db_row[0]):
                return False
        return True
开发者ID:korchynskyi,项目名称:unknown-horizons,代码行数:20,代码来源:generate_atlases.py

示例3: check_files

# 需要导入模块: from horizons.util.dbreader import DbReader [as 别名]
# 或者: from horizons.util.dbreader.DbReader import execute_script [as 别名]
	def check_files(cls):
		"""Check that the required atlas files exist."""
		paths = [
			PATHS.ACTION_SETS_JSON_FILE,
			PATHS.ATLAS_DB_PATH,
			PATHS.TILE_SETS_JSON_FILE,
		]
		for path in paths:
			if not os.path.exists(path):
				return False

		# verify that the combined images exist
		db = DbReader(':memory:')
		with open(PATHS.ATLAS_DB_PATH) as f:
			db.execute_script(f.read())
		for db_row in db("SELECT atlas_path FROM atlas"):
			if not os.path.exists(db_row[0]):
				return False
		return True
开发者ID:MarkusHackspacher,项目名称:unknown-horizons,代码行数:21,代码来源:generate_atlases.py

示例4: save_map

# 需要导入模块: from horizons.util.dbreader import DbReader [as 别名]
# 或者: from horizons.util.dbreader.DbReader import execute_script [as 别名]
	def save_map(self, path, prefix):
		map_file = os.path.join(path, prefix + '.sqlite')
		if os.path.exists(map_file):
			os.unlink(map_file) # the process relies on having an empty file

		db = DbReader(map_file)
		with open('content/map-template.sql') as map_template:
			db.execute_script(map_template.read())

		save_successful = True
		try:
			db('BEGIN')
			for island_id, coords_list in self._iter_islands():
				for x, y in coords_list:
					tile = self.world.full_map[(x, y)]
					db('INSERT INTO ground VALUES(?, ?, ?, ?, ?, ?)', island_id, x, y, tile.id, tile.shape, tile.rotation + 45)
			db('COMMIT')
		except sqlite3.Error as e:
			self.log.debug('Error: {error}'.format(error=e.args[0]))
			save_successful = False
		finally:
			db.close()

		return save_successful
开发者ID:KITSJonathanDixon,项目名称:unknown-horizons,代码行数:26,代码来源:worldeditor.py

示例5: __init__

# 需要导入模块: from horizons.util.dbreader import DbReader [as 别名]
# 或者: from horizons.util.dbreader.DbReader import execute_script [as 别名]
	def __init__(self, game_identifier, is_map, options=None):
		is_random_map = False
		if is_map:
			self.upgrader = None
			handle, self._temp_path = tempfile.mkstemp()
			os.close(handle)
			super(SavegameAccessor, self).__init__(dbfile=self._temp_path)
			with open('content/savegame_template.sql') as savegame_template:
				self.execute_script(savegame_template.read())

			if isinstance(game_identifier, list):
				is_random_map = True
				random_island_sequence = game_identifier
			else:
				self._map_path = game_identifier
		else:
			self.upgrader = SavegameUpgrader(game_identifier)
			self._temp_path = None
			game_identifier = self.upgrader.get_path()
			super(SavegameAccessor, self).__init__(dbfile=game_identifier)

			map_name_data = self('SELECT value FROM metadata WHERE name = ?', 'map_name')
			if not map_name_data:
				is_random_map = True
				random_island_sequence = self('SELECT value FROM metadata WHERE name = ?', 'random_island_sequence')[0][0].split(' ')
			else:
				map_name = map_name_data[0][0]
				if map_name.startswith('USER_MAPS_DIR:'):
					self._map_path = PATHS.USER_MAPS_DIR + map_name[len('USER_MAPS_DIR:'):]
				elif os.path.isabs(map_name):
					self._map_path = map_name
				else:
					self._map_path = SavegameManager.get_filename_from_map_name(map_name)

		if is_random_map:
			handle, self._temp_path2 = tempfile.mkstemp()
			os.close(handle)
			random_map_db = DbReader(self._temp_path2)
			with open('content/map-template.sql') as map_template:
				random_map_db.execute_script(map_template.read())
			for island_id, island_string in enumerate(random_island_sequence):
				create_random_island(random_map_db, island_id, island_string)
			random_map_db.close()
			self._map_path = self._temp_path2

			self('INSERT INTO metadata VALUES(?, ?)', 'random_island_sequence',
				' '.join(random_island_sequence))

		if options is not None:
			if options.map_padding is not None:
				self("INSERT INTO map_properties VALUES(?, ?)", 'padding', options.map_padding)

		self('ATTACH ? AS map_file', self._map_path)
		if is_random_map:
			self.map_name = random_island_sequence
		elif os.path.isabs(self._map_path):
			self.map_name = self._map_path
		else:
			self.map_name = SavegameManager.get_savegamename_from_filename(self._map_path)

		map_padding = self("SELECT value FROM map_properties WHERE name = 'padding'")
		self.map_padding = int(map_padding[0][0]) if map_padding else MAP.PADDING

		self._load_building()
		self._load_settlement()
		self._load_concrete_object()
		self._load_production()
		self._load_storage()
		self._load_wildanimal()
		self._load_unit()
		self._load_building_collector()
		self._load_production_line()
		self._load_unit_path()
		self._load_storage_global_limit()
		self._load_health()
		self._load_fish_data()
		self._hash = None
开发者ID:STEVEOO6,项目名称:unknown-horizons,代码行数:79,代码来源:savegameaccessor.py

示例6: __init__

# 需要导入模块: from horizons.util.dbreader import DbReader [as 别名]
# 或者: from horizons.util.dbreader.DbReader import execute_script [as 别名]
    def __init__(self, game_identifier, is_map):
        is_random_map = False
        if is_map:
            self.upgrader = None
            handle, self._temp_path = tempfile.mkstemp()
            os.close(handle)
            super(SavegameAccessor, self).__init__(dbfile=self._temp_path)
            with open("content/savegame_template.sql") as savegame_template:
                self.execute_script(savegame_template.read())

            if isinstance(game_identifier, list):
                is_random_map = True
                random_island_sequence = game_identifier
            else:
                self._map_path = game_identifier
        else:
            self.upgrader = SavegameUpgrader(game_identifier)
            self._temp_path = None
            game_identifier = self.upgrader.get_path()
            super(SavegameAccessor, self).__init__(dbfile=game_identifier)

            map_name_data = self("SELECT value FROM metadata WHERE name = ?", "map_name")
            if not map_name_data:
                is_random_map = True
                random_island_sequence = self("SELECT value FROM metadata WHERE name = ?", "random_island_sequence")[0][
                    0
                ].split(" ")
            else:
                map_name = map_name_data[0][0]
                if os.path.isabs(map_name):
                    self._map_path = map_name
                else:
                    self._map_path = SavegameManager.get_filename_from_map_name(map_name)

        if is_random_map:
            handle, self._temp_path2 = tempfile.mkstemp()
            os.close(handle)
            random_map_db = DbReader(self._temp_path2)
            with open("content/map-template.sql") as map_template:
                random_map_db.execute_script(map_template.read())
            for island_id, island_string in enumerate(random_island_sequence):
                create_random_island(random_map_db, island_id, island_string)
            random_map_db.close()
            self._map_path = self._temp_path2

            self("INSERT INTO metadata VALUES(?, ?)", "random_island_sequence", " ".join(random_island_sequence))

        self("ATTACH ? AS map_file", self._map_path)
        if is_random_map:
            self.map_name = random_island_sequence
        elif os.path.isabs(self._map_path):
            self.map_name = self._map_path
        else:
            self.map_name = SavegameManager.get_savegamename_from_filename(self._map_path)

        self._load_building()
        self._load_settlement()
        self._load_concrete_object()
        self._load_production()
        self._load_storage()
        self._load_wildanimal()
        self._load_unit()
        self._load_building_collector()
        self._load_production_line()
        self._load_unit_path()
        self._load_storage_global_limit()
        self._load_health()
        self._load_fish_data()
        self._hash = None
开发者ID:kendhia,项目名称:unknown-horizons,代码行数:71,代码来源:savegameaccessor.py


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