Refactory of the code (#19)
* Refactory of the code * Autoformatting with black --------- Co-authored-by: Domefemia <domefemia@hotmail.com>
This commit is contained in:
@@ -84,9 +84,7 @@ def bottles_parser(parent_widget, action):
|
||||
_("Set Bottles Location"),
|
||||
).connect("response", response)
|
||||
|
||||
if os.path.isfile(os.path.join(bottles_dir, "library.yml")):
|
||||
pass
|
||||
else:
|
||||
if not os.path.isfile(os.path.join(bottles_dir, "library.yml")):
|
||||
bottles_not_found()
|
||||
return {}
|
||||
|
||||
@@ -137,7 +135,7 @@ def bottles_parser(parent_widget, action):
|
||||
|
||||
bottles_games[values["game_id"]] = values
|
||||
|
||||
if len(bottles_games) == 0:
|
||||
if not bottles_games:
|
||||
create_dialog(
|
||||
parent_widget,
|
||||
_("No Games Found"),
|
||||
|
||||
@@ -202,7 +202,6 @@ def create_details_window(parent_widget, game_id=None):
|
||||
final_executable = executable.get_buffer().get_text()
|
||||
|
||||
if game_id is None:
|
||||
|
||||
if final_name == "":
|
||||
create_dialog(
|
||||
window, _("Couldn't Add Game"), _("Game title cannot be empty.")
|
||||
@@ -223,7 +222,7 @@ def create_details_window(parent_widget, game_id=None):
|
||||
if "imported_" in game:
|
||||
numbers.append(int(game.replace("imported_", "")))
|
||||
|
||||
game_id = "imported_" + str(max(numbers) + 1)
|
||||
game_id = f"imported_{str(max(numbers) + 1)}"
|
||||
|
||||
values["game_id"] = game_id
|
||||
values["hidden"] = False
|
||||
@@ -252,7 +251,7 @@ def create_details_window(parent_widget, game_id=None):
|
||||
save_cover(None, parent_widget, None, pixbuf, game_id)
|
||||
|
||||
values["name"] = final_name
|
||||
values["developer"] = final_developer if final_developer else None
|
||||
values["developer"] = final_developer or None
|
||||
values["executable"] = final_executable
|
||||
|
||||
path = os.path.join(
|
||||
@@ -261,7 +260,7 @@ def create_details_window(parent_widget, game_id=None):
|
||||
or os.path.expanduser(os.path.join("~", ".local", "share")),
|
||||
"cartridges",
|
||||
"games",
|
||||
game_id + ".json",
|
||||
f"{game_id}.json",
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@@ -31,10 +31,9 @@ def get_cover(game_id, parent_widget):
|
||||
or os.path.expanduser(os.path.join("~", ".local", "share")),
|
||||
"cartridges",
|
||||
"covers",
|
||||
game_id + ".tiff",
|
||||
f"{game_id}.tiff",
|
||||
)
|
||||
|
||||
if not os.path.isfile(cover_path):
|
||||
return parent_widget.placeholder_pixbuf
|
||||
|
||||
return GdkPixbuf.Pixbuf.new_from_file(cover_path)
|
||||
if os.path.isfile(cover_path):
|
||||
return GdkPixbuf.Pixbuf.new_from_file(cover_path)
|
||||
return parent_widget.placeholder_pixbuf
|
||||
|
||||
@@ -33,12 +33,10 @@ def get_games(game_ids=None):
|
||||
if not os.path.exists(games_dir):
|
||||
return {}
|
||||
|
||||
if not game_ids:
|
||||
game_files = os.listdir(games_dir)
|
||||
if game_ids:
|
||||
game_files = [f"{game_id}.json" for game_id in game_ids]
|
||||
else:
|
||||
game_files = []
|
||||
for game_id in game_ids:
|
||||
game_files.append(game_id + ".json")
|
||||
game_files = os.listdir(games_dir)
|
||||
|
||||
for game in game_files:
|
||||
with open(os.path.join(games_dir, game), "r") as open_file:
|
||||
|
||||
@@ -90,9 +90,7 @@ def heroic_parser(parent_widget, action):
|
||||
_("Set Heroic Location"),
|
||||
).connect("response", response)
|
||||
|
||||
if os.path.exists(os.path.join(heroic_dir, "config.json")):
|
||||
pass
|
||||
else:
|
||||
if not os.path.exists(os.path.join(heroic_dir, "config.json")):
|
||||
heroic_not_found()
|
||||
return {}
|
||||
|
||||
@@ -120,7 +118,7 @@ def heroic_parser(parent_widget, action):
|
||||
values = {}
|
||||
|
||||
app_name = game["app_name"]
|
||||
values["game_id"] = "heroic_epic_" + app_name
|
||||
values["game_id"] = f"heroic_epic_{app_name}"
|
||||
|
||||
if (
|
||||
values["game_id"] in parent_widget.games
|
||||
@@ -131,9 +129,9 @@ def heroic_parser(parent_widget, action):
|
||||
values["name"] = game["title"]
|
||||
values["developer"] = game["developer"]
|
||||
values["executable"] = (
|
||||
"start heroic://launch/" + app_name
|
||||
f"start heroic://launch/{app_name}"
|
||||
if os.name == "nt"
|
||||
else "xdg-open heroic://launch/" + app_name
|
||||
else f"xdg-open heroic://launch/{app_name}"
|
||||
)
|
||||
values["hidden"] = False
|
||||
values["source"] = "heroic_epic"
|
||||
@@ -168,7 +166,7 @@ def heroic_parser(parent_widget, action):
|
||||
values = {}
|
||||
app_name = item["appName"]
|
||||
|
||||
values["game_id"] = "heroic_gog_" + app_name
|
||||
values["game_id"] = f"heroic_gog_{app_name}"
|
||||
|
||||
if (
|
||||
values["game_id"] in parent_widget.games
|
||||
@@ -197,9 +195,9 @@ def heroic_parser(parent_widget, action):
|
||||
break
|
||||
|
||||
values["executable"] = (
|
||||
"start heroic://launch/" + app_name
|
||||
f"start heroic://launch/{app_name}"
|
||||
if os.name == "nt"
|
||||
else "xdg-open heroic://launch/" + app_name
|
||||
else f"xdg-open heroic://launch/{app_name}"
|
||||
)
|
||||
values["hidden"] = False
|
||||
values["source"] = "heroic_gog"
|
||||
@@ -222,7 +220,7 @@ def heroic_parser(parent_widget, action):
|
||||
values = {}
|
||||
app_name = item["app_name"]
|
||||
|
||||
values["game_id"] = "heroic_sideload_" + app_name
|
||||
values["game_id"] = f"heroic_sideload_{app_name}"
|
||||
|
||||
if (
|
||||
values["game_id"] in parent_widget.games
|
||||
@@ -232,9 +230,9 @@ def heroic_parser(parent_widget, action):
|
||||
|
||||
values["name"] = item["title"]
|
||||
values["executable"] = (
|
||||
"start heroic://launch/" + app_name
|
||||
f"start heroic://launch/{app_name}"
|
||||
if os.name == "nt"
|
||||
else "xdg-open heroic://launch/" + app_name
|
||||
else f"xdg-open heroic://launch/{app_name}"
|
||||
)
|
||||
values["hidden"] = False
|
||||
values["source"] = "heroic_sideload"
|
||||
@@ -250,7 +248,7 @@ def heroic_parser(parent_widget, action):
|
||||
|
||||
heroic_games[values["game_id"]] = values
|
||||
|
||||
if len(heroic_games) == 0:
|
||||
if not heroic_games:
|
||||
create_dialog(
|
||||
parent_widget,
|
||||
_("No Games Found"),
|
||||
|
||||
@@ -26,7 +26,7 @@ from gi.repository import Gio
|
||||
|
||||
def run_command(executable):
|
||||
subprocess.Popen(
|
||||
["flatpak-spawn --host " + executable]
|
||||
[f"flatpak-spawn --host {executable}"]
|
||||
if os.getenv("FLATPAK_ID") == "hu.kramo.Cartridges"
|
||||
else executable.split()
|
||||
if os.name == "nt"
|
||||
|
||||
@@ -42,7 +42,7 @@ def save_cover(game, parent_widget, file_path, pixbuf=None, game_id=None):
|
||||
if not os.path.exists(covers_dir):
|
||||
os.makedirs(covers_dir)
|
||||
|
||||
open_file = Gio.File.new_for_path(os.path.join(covers_dir, game_id + ".tiff"))
|
||||
open_file = Gio.File.new_for_path(os.path.join(covers_dir, f"{game_id}.tiff"))
|
||||
parent_widget.pixbufs[game_id] = pixbuf
|
||||
pixbuf.save_to_streamv_async(
|
||||
open_file.replace(None, False, Gio.FileCreateFlags.NONE),
|
||||
|
||||
@@ -33,6 +33,6 @@ def save_games(games):
|
||||
os.makedirs(games_dir)
|
||||
|
||||
for game in games:
|
||||
with open(os.path.join(games_dir, game + ".json"), "w") as open_file:
|
||||
with open(os.path.join(games_dir, f"{game}.json"), "w") as open_file:
|
||||
open_file.write(json.dumps(games[game], indent=4, sort_keys=True))
|
||||
open_file.close()
|
||||
|
||||
@@ -32,12 +32,12 @@ def toggle_hidden(game):
|
||||
if not os.path.exists(games_dir):
|
||||
return
|
||||
|
||||
with open(os.path.join(games_dir, game + ".json"), "r") as open_file:
|
||||
with open(os.path.join(games_dir, f"{game}.json"), "r") as open_file:
|
||||
data = json.loads(open_file.read())
|
||||
open_file.close()
|
||||
|
||||
data["hidden"] = not data["hidden"]
|
||||
|
||||
with open(os.path.join(games_dir, game + ".json"), "w") as open_file:
|
||||
with open(os.path.join(games_dir, f"{game}.json"), "w") as open_file:
|
||||
open_file.write(json.dumps(data, indent=4))
|
||||
open_file.close()
|
||||
|
||||
Reference in New Issue
Block a user