本文整理汇总了Python中fsgs.Database.Database.instance方法的典型用法代码示例。如果您正苦于以下问题:Python Database.instance方法的具体用法?Python Database.instance怎么用?Python Database.instance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fsgs.Database.Database
的用法示例。
在下文中一共展示了Database.instance方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_game_variant
# 需要导入模块: from fsgs.Database import Database [as 别名]
# 或者: from fsgs.Database.Database import instance [as 别名]
def load_game_variant(self, variant_uuid):
# game_database = fsgs.get_game_database()
# values = game_database.get_game_values_for_uuid(variant_uuid)
from .Database import Database
database = Database.instance()
try:
database_name = database.find_game_database_for_game_variant(
variant_uuid)
except LookupError:
return False
values = self.game.set_from_variant_uuid(database_name, variant_uuid)
if not values:
return False
# print("")
# for key in sorted(values.keys()):
# print(" * {0} = {1}".format(key, values[key]))
# print("")
from fsgs.platform import PlatformHandler
platform_handler = PlatformHandler.create(self.game.platform.id)
loader = platform_handler.get_loader(self)
self.config.load(loader.load_values(values))
return True
示例2: main
# 需要导入模块: from fsgs.Database import Database [as 别名]
# 或者: from fsgs.Database.Database import instance [as 别名]
def main():
Application("fs-uae-game-system")
if "--unsupported" in sys.argv:
if "--http-server" in sys.argv:
from fsgs.http.server import http_server_main
return http_server_main()
if len(sys.argv) < 3:
print("")
print("usage: fsgs run <game>")
print("")
print("game:")
print(" - search term(s) identifying a single game")
print(" - path to a .fsgs file")
print(" - path to a recognized cartridge ROM or disk file format")
print("")
sys.exit(1)
assert sys.argv[1] == "run"
game_arg = " ".join(sys.argv[2:])
print(game_arg)
if os.path.exists(game_arg):
load_file(game_arg)
else:
search = game_arg.lower()
database = Database.instance()
# cursor.execute("SELECT id FROM game WHERE name like")
terms = GameNameUtil.extract_search_terms(search)
found_games = database.find_games_new(" ".join(terms))
games = []
for game in found_games:
print(list(game))
if game[0]:
# only process entries with a game uuid
games.append(game)
game_uuid = None
if len(games) == 0:
print("no games found")
sys.exit(2)
if len(games) > 1:
matches = 0
for row in games:
if row[1].lower() == search:
if game_uuid is None:
game_uuid = row[0]
matches += 1
if matches != 1:
print("")
print("More than one game matches:")
print("")
for row in games:
print(" {0} ({1})".format(row[1], row[2]))
print(" {0}".format(row[0]))
print("")
sys.exit(3)
game_uuid = games[0][0]
assert game_uuid
variant_uuid = find_preferred_variant(game_uuid)
load_game_variant(variant_uuid)
fsgs.run_game()
示例3: find_preferred_game_variant
# 需要导入模块: from fsgs.Database import Database [as 别名]
# 或者: from fsgs.Database.Database import instance [as 别名]
def find_preferred_game_variant(self, game_uuid):
print("find_preferred_game_variant game_uuid =", game_uuid)
from .Database import Database
database = Database.instance()
variants = database.find_game_variants_new(game_uuid=game_uuid)
print(variants)
ordered_list = []
for variant in variants:
variant["like_rating"], variant["work_rating"] = \
database.get_ratings_for_game(variant["uuid"])
variant["personal_rating"], ignored = \
database.get_ratings_for_game(variant["uuid"])
variant_uuid = variant["uuid"]
variant_name = variant["name"]
variant_name = variant_name.replace("\n", " (")
variant_name = variant_name.replace(" \u00b7 ", ", ")
variant_name += ")"
ordered_list.append(
((1 - bool(variant["have"]),
1000 - variant["personal_rating"],
1000 - variant["like_rating"]),
(variant_uuid, variant_name)))
ordered_list.sort()
print("ordered variant list:")
for variant in ordered_list:
print("-", variant[1][1])
# item.configurations = [x[1] for x in ordered_list]
return ordered_list[0][1][0]
示例4: get_ordered_game_variants
# 需要导入模块: from fsgs.Database import Database [as 别名]
# 或者: from fsgs.Database.Database import instance [as 别名]
def get_ordered_game_variants(self, game_uuid):
print("get_ordered_game_variants game_uuid =", game_uuid)
from .Database import Database
database = Database.instance()
variants = database.find_game_variants_new(game_uuid=game_uuid)
print(variants)
# ordered_list = []
# FIXME: Merge code with VariantsBrowser.py
sortable_items = []
for i, variant in enumerate(variants):
game_database = self.game_database(variant["database"])
variant["like_rating"], variant["work_rating"] = \
game_database.get_ratings_for_game(variant["uuid"])
variant["personal_rating"], ignored = \
database.get_ratings_for_game(variant["uuid"])
# variant_uuid = variant["uuid"]
name = variant["name"]
name = name.replace("\n", " (")
name = name.replace(" \u00b7 ", ", ")
name += ")"
# ordered_list.append(
# ((1 - bool(variant["have"]),
# 1000 - variant["personal_rating"],
# 1000 - variant["like_rating"]),
# (variant_uuid, variant_name)))
sort_key = (0, 1000000 - variant["like_rating"],
1000000 - variant["work_rating"], name)
sortable_items.append(
(sort_key, i, variant))
ordered_list = [x[2] for x in sorted(sortable_items)]
print("ordered variant list:")
for variant in ordered_list:
print("-", variant["name"])
# item.configurations = [x[1] for x in ordered_list]
select_index = None
if select_index is None:
# default index selection
for i, variant in enumerate(ordered_list):
if variant["personal_rating"] == 5:
select_index = i
break
else:
for i, variant in enumerate(ordered_list):
if variant["have"] >= 3:
select_index = i
break
else:
for i, variant in enumerate(ordered_list):
if variant["have"] >= 1:
select_index = i
break
else:
if len(ordered_list) > 0:
select_index = 0
# return ordered_list[select_index]["uuid"]
if select_index and select_index > 0:
ordered_list.insert(0, ordered_list.pop(select_index))
return ordered_list
示例5: set_rating_for_variant
# 需要导入模块: from fsgs.Database import Database [as 别名]
# 或者: from fsgs.Database.Database import instance [as 别名]
def set_rating_for_variant(variant_uuid, rating):
# FIXME: Do asynchronously, add to queue
client = OGDClient()
result = client.rate_variant(variant_uuid, like=rating)
like_rating = result.get("like", 0)
work_rating = result.get("work", 0)
database = Database.instance()
cursor = database.cursor()
cursor.execute(
"DELETE FROM rating WHERE game_uuid = ?", (variant_uuid,))
cursor.execute(
"INSERT INTO rating (game_uuid, work_rating, like_rating) "
"VALUES (?, ?, ?)", (variant_uuid, work_rating, like_rating))
database.commit()
LauncherConfig.set("variant_rating", str(like_rating))
示例6: create_game_items
# 需要导入模块: from fsgs.Database import Database [as 别名]
# 或者: from fsgs.Database.Database import instance [as 别名]
def create_game_items(cls, words, args=None, filters=None, list_uuid=None):
if filters is None:
filters = []
search = " ".join(words)
item_list = []
local_game_database = Database.instance()
for game in local_game_database.find_games_new(
search=search, database_only=True, list_uuid=list_uuid
):
item = GameItem(game)
for filter in filters:
pass
# if not filter(game):
# break
else:
item_list.append(item)
return item_list
示例7: activate
# 需要导入模块: from fsgs.Database import Database [as 别名]
# 或者: from fsgs.Database.Database import instance [as 别名]
def activate(self, menu):
print("PlatformMenuItem.activate")
new_menu = create_item_menu(gettext("Select Platform"))
menu_path = self.create_menu_path(menu)
new_menu.update_path(menu_path)
with Database.instance() as database:
cursor = database.cursor()
cursor.execute(
"SELECT DISTINCT platform FROM game WHERE have >= 3 "
"ORDER BY platform")
items = []
for row in cursor:
if not row[0]:
continue
item = PlatformItem(row[0])
items.append((item.sort_title, item))
for sort_title, item in sorted(items):
new_menu.append(item)
return new_menu
示例8: create_game_items
# 需要导入模块: from fsgs.Database import Database [as 别名]
# 或者: from fsgs.Database.Database import instance [as 别名]
def create_game_items(cls, words, args=None, filters=None):
if filters is None:
filters = []
search = " ".join(words)
# query = "SELECT id, name, config, platform, " \
# "imageratio, screenratio, year, publisher, developer,
# subtitle " \
# "FROM Game WHERE 1 = 1 {0} ORDER BY sort_key".format(clause)
# print(query, args)
# Database.cursor.execute(query, args)
# item_list = []
# last_item = None
# for row in Database.cursor:
# if last_item:
# if last_item.name == row[1] and last_item.platform == row[3]:
# last_item.configurations.append(row[2])
# continue
# for filter in filters:
# if not filter(row):
# break
# else:
# item = GameItem(id=row[0], name=row[1], configurations=[
# row[2]],
# platform=row[3], ratio=row[4], screenratio=row[5],
# year=row[6], publisher=row[7], developer=row[8],
# subtitlepos=row[9])
# item_list.append(item)
# last_item = item
# return item_list
item_list = []
local_game_database = Database.instance()
for game in local_game_database.find_games_new(
search=search, database_only=True):
item = GameItem(game)
item_list.append(item)
return item_list
示例9: database
# 需要导入模块: from fsgs.Database import Database [as 别名]
# 或者: from fsgs.Database.Database import instance [as 别名]
def database(self):
return Database.instance()
示例10: get_game_lists
# 需要导入模块: from fsgs.Database import Database [as 别名]
# 或者: from fsgs.Database.Database import instance [as 别名]
def get_game_lists(cls):
result = []
local_game_database = Database.instance()
for list_uuid, list_name in local_game_database.get_game_lists():
result.append((list_name, list_uuid))
return result