本文整理汇总了Python中fsgs.Database.Database类的典型用法代码示例。如果您正苦于以下问题:Python Database类的具体用法?Python Database怎么用?Python Database使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Database类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_search
def update_search(self):
search = LauncherSettings.get("config_search").strip().lower()
print("search for", search)
words = []
special = []
for word in search.split(" "):
word = word.strip()
if not word:
continue
if ":" in word[1:-1]:
special.append(word)
else:
words.append(word)
terms = GameNameUtil.extract_search_terms(" ".join(words))
terms.update(special)
database = Database.get_instance()
try:
have = int(LauncherSettings.get("database_show_games"))
except ValueError:
# default is show all downloadable and locally available games
have = 1
items = database.find_games_new(
" ".join(terms), have=have,
list_uuid=LauncherSettings.get("game_list_uuid"))
self.set_items(items)
示例2: main
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
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: load_game_variant
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
示例5: run
def run(self):
self.defragment(FileDatabase.get_instance(), "Files.sqlite")
self.stop_check()
self.defragment(LockerDatabase.instance(), "Locker.sqlite")
self.stop_check()
self.defragment(fsgs.get_game_database(), "Amiga.sqlite")
self.stop_check()
self.defragment(Database.get_instance(), "Database.sqlite")
示例6: get_ordered_game_variants
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
示例7: load_configuration
def load_configuration(self, item):
if item[str("uuid")]:
LauncherSettings.set("parent_uuid", item[str("uuid")])
else:
config_path = Database.get_instance().decode_path(
item[str("path")])
print("load config from", config_path)
LauncherConfig.load_file(config_path)
LauncherSettings.set("parent_uuid", "")
示例8: set_rating_for_variant
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))
示例9: create_game_items
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
示例10: activate
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
示例11: create_game_items
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
示例12: temp_fix_configs
def temp_fix_configs(self, item):
from fsgs.Database import Database
local_game_database = Database.get_instance()
game_database = fsgs.get_game_database()
variants = local_game_database.find_game_variants_new(
game_uuid=item.uuid)
print(variants)
ordered_list = []
for variant in variants:
variant["like_rating"], variant["work_rating"] = \
game_database.get_ratings_for_game(variant["uuid"])
variant["personal_rating"], ignored = \
local_game_database.get_ratings_for_game(variant["uuid"])
# user_rating = variant[5] or 0
# global_rating = variant[3] or 0
# user_rating = 0
# global_rating = 0
variant_uuid = variant["uuid"] # variant[2]
variant_name = variant["name"] # variant[1]
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, variant["database"])))
ordered_list.sort()
print("ordered variant list:")
for variant in ordered_list:
print("-", variant[1][1])
item.configurations = [co[1] for co in ordered_list]
示例13: database
def database(self):
return Database.instance()
示例14: get_game_lists
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
示例15: update_list
def update_list(self, game_uuid):
print("VariantsBrowser.update_list, game_uuid=", game_uuid)
database = Database.get_instance()
items = database.find_game_variants_new(game_uuid, have=0)
# items = database.search_configurations(self.search)
sortable_items = []
for i, item in enumerate(items):
name = item["name"]
name = name.replace("\nAmiga \u00b7 ", "\n")
# print(name, item[3])
# name = name.replace("\nCD32 \u00b7 ", "\n")
# name = item[1].replace("\n", " \u00b7 ")
# only show variant name (without game name)
name = name.split("\n", 1)[-1]
game_database = fsgs.game_database(item["database"])
item["like_rating"], item["work_rating"] = game_database\
.get_ratings_for_game(item["uuid"])
item["personal_rating"], ignored = database.get_ratings_for_game(
item["uuid"])
sort_key = (0, 1000000 - item["like_rating"],
1000000 - item["work_rating"], name)
sortable_items.append(
(sort_key, i, item))
# print(sortable_items)
self.items = [x[2] for x in sorted(sortable_items)]
self.update()
# self.set_items(self.items)
# self.set_item_count(len(self.items))
self.select_item(None, signal=False)
select_index = None
list_uuid = LauncherSettings.get("game_list_uuid")
if list_uuid:
list_variant_uuid = database.get_variant_for_list_and_game(
list_uuid, game_uuid)
print("game list", list_uuid, "override variant",
list_variant_uuid)
else:
list_variant_uuid = None
if list_variant_uuid:
# override variant selection from list if possible
for i, item in enumerate(self.items):
print(item["uuid"], item["name"], list_variant_uuid)
if item["uuid"] == list_variant_uuid:
select_index = i
print("override select index", select_index)
break
if select_index is None:
# default index selection
for i, item in enumerate(self.items):
if item["personal_rating"] == 5:
select_index = i
break
else:
for i, item in enumerate(self.items):
if item["have"] >= 3:
select_index = i
break
else:
for i, item in enumerate(self.items):
if item["have"] >= 1:
select_index = i
break
else:
if len(self.items) > 0:
select_index = 0
# self.clear()
# for i, item in enumerate(self.items):
# self.add_item(item["name"], icon=self.get_item_icon(i))
self.enable(len(self.items) > 0)
if select_index is not None:
print("selecting variant index", select_index)
self.select_item(select_index)
else:
ConfigGroup.new_config()