Code style
This commit is contained in:
0
src/utils/__init__.py
Normal file
0
src/utils/__init__.py
Normal file
@@ -48,7 +48,7 @@ def bottles_parser(parent_widget, action):
|
||||
else:
|
||||
filechooser = Gtk.FileDialog.new()
|
||||
|
||||
def set_bottles_dir(source, result, _):
|
||||
def set_bottles_dir(_source, result, _unused):
|
||||
try:
|
||||
schema.set_string(
|
||||
"bottles-location",
|
||||
@@ -58,7 +58,7 @@ def bottles_parser(parent_widget, action):
|
||||
except GLib.GError:
|
||||
return
|
||||
|
||||
def choose_folder(widget):
|
||||
def choose_folder(_widget):
|
||||
filechooser.select_folder(parent_widget, None, set_bottles_dir, None)
|
||||
|
||||
def response(widget, response):
|
||||
@@ -84,9 +84,9 @@ def bottles_parser(parent_widget, action):
|
||||
bottles_games = {}
|
||||
current_time = int(time.time())
|
||||
|
||||
open_file = open(os.path.join(bottles_dir, "library.yml"), "r")
|
||||
data = open_file.read()
|
||||
open_file.close()
|
||||
with open(os.path.join(bottles_dir, "library.yml"), "r") as open_file:
|
||||
data = open_file.read()
|
||||
open_file.close()
|
||||
|
||||
library = yaml.load(data, Loader=yaml.Loader)
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ def create_details_window(parent_widget, game_id=None):
|
||||
games = parent_widget.games
|
||||
pixbuf = None
|
||||
|
||||
if game_id == None:
|
||||
if game_id is None:
|
||||
window.set_title(_("Add New Game"))
|
||||
cover = Gtk.Picture.new_for_pixbuf(parent_widget.placeholder_pixbuf)
|
||||
name = Gtk.Entry()
|
||||
@@ -119,10 +119,10 @@ def create_details_window(parent_widget, game_id=None):
|
||||
main_box.append(general_page)
|
||||
window.set_content(main_box)
|
||||
|
||||
def choose_cover(widget):
|
||||
def choose_cover(_widget):
|
||||
filechooser.open(window, None, set_cover, None)
|
||||
|
||||
def set_cover(source, result, _):
|
||||
def set_cover(_source, result, _unused):
|
||||
nonlocal pixbuf
|
||||
try:
|
||||
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(
|
||||
@@ -132,10 +132,10 @@ def create_details_window(parent_widget, game_id=None):
|
||||
except GLib.GError:
|
||||
return
|
||||
|
||||
def close_window(widget, callback=None):
|
||||
def close_window(_widget, _callback=None):
|
||||
window.close()
|
||||
|
||||
def apply_preferences(widget, callback=None):
|
||||
def apply_preferences(_widget, _callback=None):
|
||||
nonlocal pixbuf
|
||||
nonlocal game_id
|
||||
|
||||
@@ -144,7 +144,7 @@ def create_details_window(parent_widget, game_id=None):
|
||||
final_name = name.get_buffer().get_text()
|
||||
final_executable = executable.get_buffer().get_text()
|
||||
|
||||
if game_id == None:
|
||||
if game_id is None:
|
||||
|
||||
if final_name == "":
|
||||
create_dialog(
|
||||
@@ -191,7 +191,7 @@ def create_details_window(parent_widget, game_id=None):
|
||||
)
|
||||
return
|
||||
|
||||
if pixbuf != None:
|
||||
if pixbuf is not None:
|
||||
save_cover(None, parent_widget, None, pixbuf, game_id)
|
||||
|
||||
values["name"] = final_name
|
||||
@@ -207,9 +207,9 @@ def create_details_window(parent_widget, game_id=None):
|
||||
)
|
||||
|
||||
if os.path.exists(path):
|
||||
open_file = open(path, "r")
|
||||
data = json.loads(open_file.read())
|
||||
open_file.close()
|
||||
with open(path, "r") as open_file:
|
||||
data = json.loads(open_file.read())
|
||||
open_file.close()
|
||||
data.update(values)
|
||||
save_games({game_id: data})
|
||||
else:
|
||||
@@ -221,7 +221,7 @@ def create_details_window(parent_widget, game_id=None):
|
||||
window.close()
|
||||
parent_widget.show_overview(None, game_id)
|
||||
|
||||
def focus_executable(widget):
|
||||
def focus_executable(_widget):
|
||||
window.set_focus(executable)
|
||||
|
||||
cover_button.connect("clicked", choose_cover)
|
||||
|
||||
@@ -25,7 +25,7 @@ def get_games(game_ids=None):
|
||||
games_dir = os.path.join(os.environ.get("XDG_DATA_HOME"), "cartridges", "games")
|
||||
games = {}
|
||||
|
||||
if os.path.exists(games_dir) == False:
|
||||
if not os.path.exists(games_dir):
|
||||
return {}
|
||||
|
||||
if not game_ids:
|
||||
@@ -36,8 +36,8 @@ def get_games(game_ids=None):
|
||||
game_files.append(game_id + ".json")
|
||||
|
||||
for game in game_files:
|
||||
open_file = open(os.path.join(games_dir, game), "r")
|
||||
data = json.loads(open_file.read())
|
||||
open_file.close()
|
||||
with open(os.path.join(games_dir, game), "r") as open_file:
|
||||
data = json.loads(open_file.read())
|
||||
open_file.close()
|
||||
games[data["game_id"]] = data
|
||||
return games
|
||||
|
||||
@@ -50,7 +50,7 @@ def heroic_parser(parent_widget, action):
|
||||
else:
|
||||
filechooser = Gtk.FileDialog.new()
|
||||
|
||||
def set_heroic_dir(source, result, _):
|
||||
def set_heroic_dir(_source, result, _unused):
|
||||
try:
|
||||
schema.set_string(
|
||||
"heroic-location",
|
||||
@@ -60,7 +60,7 @@ def heroic_parser(parent_widget, action):
|
||||
except GLib.GError:
|
||||
return
|
||||
|
||||
def choose_folder(widget):
|
||||
def choose_folder(_widget):
|
||||
filechooser.select_folder(parent_widget, None, set_heroic_dir, None)
|
||||
|
||||
def response(widget, response):
|
||||
@@ -90,13 +90,15 @@ def heroic_parser(parent_widget, action):
|
||||
if not schema.get_boolean("heroic-import-epic"):
|
||||
pass
|
||||
elif os.path.exists(os.path.join(heroic_dir, "lib-cache", "library.json")):
|
||||
open_file = open(os.path.join(heroic_dir, "lib-cache", "library.json"), "r")
|
||||
data = open_file.read()
|
||||
with open(
|
||||
os.path.join(heroic_dir, "lib-cache", "library.json"), "r"
|
||||
) as open_file:
|
||||
data = open_file.read()
|
||||
open_file.close()
|
||||
library = json.loads(data)
|
||||
open_file.close()
|
||||
|
||||
for game in library["library"]:
|
||||
if game["is_installed"] == False:
|
||||
if not game["is_installed"]:
|
||||
continue
|
||||
|
||||
values = {}
|
||||
@@ -133,9 +135,11 @@ def heroic_parser(parent_widget, action):
|
||||
if not schema.get_boolean("heroic-import-gog"):
|
||||
pass
|
||||
elif os.path.exists(os.path.join(heroic_dir, "gog_store", "installed.json")):
|
||||
open_file = open(os.path.join(heroic_dir, "gog_store", "installed.json"), "r")
|
||||
data = open_file.read()
|
||||
open_file.close()
|
||||
with open(
|
||||
os.path.join(heroic_dir, "gog_store", "installed.json"), "r"
|
||||
) as open_file:
|
||||
data = open_file.read()
|
||||
open_file.close()
|
||||
installed = json.loads(data)
|
||||
for item in installed["installed"]:
|
||||
values = {}
|
||||
@@ -150,9 +154,11 @@ def heroic_parser(parent_widget, action):
|
||||
continue
|
||||
|
||||
# Get game title from library.json as it's not present in installed.json
|
||||
open_file = open(os.path.join(heroic_dir, "gog_store", "library.json"), "r")
|
||||
data = open_file.read()
|
||||
open_file.close()
|
||||
with open(
|
||||
os.path.join(heroic_dir, "gog_store", "library.json"), "r"
|
||||
) as open_file:
|
||||
data = open_file.read()
|
||||
open_file.close()
|
||||
library = json.loads(data)
|
||||
for game in library["games"]:
|
||||
if game["app_name"] == app_name:
|
||||
@@ -178,9 +184,11 @@ def heroic_parser(parent_widget, action):
|
||||
if not schema.get_boolean("heroic-import-sideload"):
|
||||
pass
|
||||
elif os.path.exists(os.path.join(heroic_dir, "sideload_apps", "library.json")):
|
||||
open_file = open(os.path.join(heroic_dir, "sideload_apps", "library.json"), "r")
|
||||
data = open_file.read()
|
||||
open_file.close()
|
||||
with open(
|
||||
os.path.join(heroic_dir, "sideload_apps", "library.json"), "r"
|
||||
) as open_file:
|
||||
data = open_file.read()
|
||||
open_file.close()
|
||||
library = json.loads(data)
|
||||
for item in library["games"]:
|
||||
values = {}
|
||||
|
||||
@@ -23,7 +23,7 @@ import sys
|
||||
from gi.repository import Gio
|
||||
|
||||
|
||||
def run_command(parent_widget, executable):
|
||||
def run_command(executable):
|
||||
subprocess.Popen(
|
||||
["flatpak-spawn --host " + executable], shell=True, start_new_session=True
|
||||
)
|
||||
|
||||
@@ -24,22 +24,22 @@ from gi.repository import GdkPixbuf, Gio
|
||||
|
||||
def save_cover(game, parent_widget, file_path, pixbuf=None, game_id=None):
|
||||
covers_dir = os.path.join(os.environ.get("XDG_DATA_HOME"), "cartridges", "covers")
|
||||
if os.path.exists(covers_dir) == False:
|
||||
if not os.path.exists(covers_dir):
|
||||
os.makedirs(covers_dir)
|
||||
|
||||
if game_id == None:
|
||||
if game_id is None:
|
||||
game_id = game["game_id"]
|
||||
|
||||
if pixbuf == None:
|
||||
if pixbuf is None:
|
||||
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(file_path, 600, 900, False)
|
||||
|
||||
def cover_callback(*args):
|
||||
def cover_callback(*_unused):
|
||||
pass
|
||||
|
||||
file = Gio.File.new_for_path(os.path.join(covers_dir, game_id + ".jpg"))
|
||||
open_file = Gio.File.new_for_path(os.path.join(covers_dir, game_id + ".jpg"))
|
||||
parent_widget.pixbufs[game_id] = pixbuf
|
||||
pixbuf.save_to_streamv_async(
|
||||
file.replace(None, False, Gio.FileCreateFlags.NONE),
|
||||
open_file.replace(None, False, Gio.FileCreateFlags.NONE),
|
||||
"jpeg",
|
||||
callback=cover_callback,
|
||||
)
|
||||
|
||||
@@ -24,10 +24,10 @@ import os
|
||||
def save_games(games):
|
||||
games_dir = os.path.join(os.environ.get("XDG_DATA_HOME"), "cartridges", "games")
|
||||
|
||||
if os.path.exists(games_dir) == False:
|
||||
if not os.path.exists(games_dir):
|
||||
os.makedirs(games_dir)
|
||||
|
||||
for game in games:
|
||||
open_file = open(os.path.join(games_dir, game + ".json"), "w")
|
||||
open_file.write(json.dumps(games[game], indent=4, sort_keys=True))
|
||||
open_file.close()
|
||||
with open(os.path.join(games_dir, game + ".json"), "w") as open_file:
|
||||
open_file.write(json.dumps(games[game], indent=4, sort_keys=True))
|
||||
open_file.close()
|
||||
|
||||
@@ -45,7 +45,7 @@ def steam_parser(parent_widget, action):
|
||||
else:
|
||||
filechooser = Gtk.FileDialog.new()
|
||||
|
||||
def set_steam_dir(source, result, _):
|
||||
def set_steam_dir(_source, result, _unused):
|
||||
try:
|
||||
schema.set_string(
|
||||
"steam-location",
|
||||
@@ -55,7 +55,7 @@ def steam_parser(parent_widget, action):
|
||||
except GLib.GError:
|
||||
return
|
||||
|
||||
def choose_folder(widget):
|
||||
def choose_folder(_widget):
|
||||
filechooser.select_folder(parent_widget, None, set_steam_dir, None)
|
||||
|
||||
def response(widget, response):
|
||||
@@ -94,9 +94,9 @@ def steam_parser(parent_widget, action):
|
||||
|
||||
for appmanifest in appmanifests:
|
||||
values = {}
|
||||
open_file = open(appmanifest, "r")
|
||||
data = open_file.read()
|
||||
open_file.close()
|
||||
with open(appmanifest, "r") as open_file:
|
||||
data = open_file.read()
|
||||
open_file.close()
|
||||
for datatype in datatypes:
|
||||
value = re.findall('"' + datatype + '"\t\t"(.*)"\n', data)
|
||||
values[datatype] = value[0]
|
||||
|
||||
@@ -27,10 +27,10 @@ def toggle_hidden(game):
|
||||
if not os.path.exists(games_dir):
|
||||
return
|
||||
|
||||
file = open(os.path.join(games_dir, game + ".json"), "r")
|
||||
data = json.loads(file.read())
|
||||
file.close()
|
||||
file = open(os.path.join(games_dir, game + ".json"), "w")
|
||||
data["hidden"] = not data["hidden"]
|
||||
file.write(json.dumps(data, indent=4))
|
||||
file.close()
|
||||
with open(os.path.join(games_dir, game + ".json"), "r") as open_file:
|
||||
data = json.loads(open_file.read())
|
||||
open_file.close()
|
||||
with open(os.path.join(games_dir, game + ".json"), "w") as open_file:
|
||||
data["hidden"] = not data["hidden"]
|
||||
open_file.write(json.dumps(data, indent=4))
|
||||
open_file.close()
|
||||
|
||||
Reference in New Issue
Block a user