Explicit is better than implicit 🐍🤓
This commit is contained in:
@@ -172,7 +172,9 @@ class CartridgesApplication(Adw.Application):
|
|||||||
try:
|
try:
|
||||||
game_id = args[index + 1]
|
game_id = args[index + 1]
|
||||||
data = json.load(
|
data = json.load(
|
||||||
(path := shared.games_dir / (game_id + ".json")).open("r")
|
(path := shared.games_dir / (game_id + ".json")).open(
|
||||||
|
"r", encoding="utf-8"
|
||||||
|
)
|
||||||
)
|
)
|
||||||
executable = (
|
executable = (
|
||||||
shlex.join(data["executable"])
|
shlex.join(data["executable"])
|
||||||
@@ -184,7 +186,7 @@ class CartridgesApplication(Adw.Application):
|
|||||||
run_executable(executable)
|
run_executable(executable)
|
||||||
|
|
||||||
data["last_played"] = int(time())
|
data["last_played"] = int(time())
|
||||||
json.dump(data, path.open("w"))
|
json.dump(data, path.open("w", encoding="utf-8"))
|
||||||
|
|
||||||
except (IndexError, KeyError, OSError, json.decoder.JSONDecodeError):
|
except (IndexError, KeyError, OSError, json.decoder.JSONDecodeError):
|
||||||
return 1
|
return 1
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ class FileManager(AsyncManager):
|
|||||||
|
|
||||||
json.dump(
|
json.dump(
|
||||||
{attr: getattr(game, attr) for attr in attrs if attr},
|
{attr: getattr(game, attr) for attr in attrs if attr},
|
||||||
(shared.games_dir / f"{game.game_id}.json").open("w"),
|
(shared.games_dir / f"{game.game_id}.json").open("w", encoding="utf-8"),
|
||||||
indent=4,
|
indent=4,
|
||||||
sort_keys=True,
|
sort_keys=True,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ def migrate_files_v1_to_v2() -> None:
|
|||||||
imported_execs = set()
|
imported_execs = set()
|
||||||
for game_path in shared.games_dir.glob("imported_*.json"):
|
for game_path in shared.games_dir.glob("imported_*.json"):
|
||||||
try:
|
try:
|
||||||
game_data = json.load(game_path.open("r"))
|
game_data = json.load(game_path.open("r", encoding="utf-8"))
|
||||||
except (OSError, json.JSONDecodeError):
|
except (OSError, json.JSONDecodeError):
|
||||||
continue
|
continue
|
||||||
number = int(game_data["game_id"].replace("imported_", ""))
|
number = int(game_data["game_id"].replace("imported_", ""))
|
||||||
@@ -86,7 +86,7 @@ def migrate_files_v1_to_v2() -> None:
|
|||||||
# Migrate imported game files
|
# Migrate imported game files
|
||||||
for game_path in old_imported_game_paths:
|
for game_path in old_imported_game_paths:
|
||||||
try:
|
try:
|
||||||
game_data = json.load(game_path.open("r"))
|
game_data = json.load(game_path.open("r", encoding="utf-8"))
|
||||||
except (OSError, json.JSONDecodeError):
|
except (OSError, json.JSONDecodeError):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@@ -104,7 +104,7 @@ def migrate_files_v1_to_v2() -> None:
|
|||||||
)
|
)
|
||||||
json.dump(
|
json.dump(
|
||||||
game_data,
|
game_data,
|
||||||
destination_game_path.open("w"),
|
destination_game_path.open("w", encoding="utf-8"),
|
||||||
indent=4,
|
indent=4,
|
||||||
sort_keys=True,
|
sort_keys=True,
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user