Use simpler syntax for I/O operations

This commit is contained in:
kramo
2023-04-01 16:14:19 +02:00
parent 3bcbf8457c
commit 6899246d01
7 changed files with 12 additions and 20 deletions

View File

@@ -110,8 +110,7 @@ class game(Gtk.Box): # pylint: disable=invalid-name
if not games_dir.exists():
return
with open((games_dir / f"{self.game_id}.json") / "r") as open_file:
data = json.loads(open_file.read())
data = json.loads((games_dir / f"{self.game_id}.json").read_text())
data["hidden"] = not data["hidden"]

View File

@@ -46,8 +46,7 @@ def bottles_parser(parent_widget):
bottles_dir = Path(schema.get_string("bottles-location")).expanduser()
current_time = int(time())
with open((bottles_dir / "library.yml"), "r") as open_file:
data = open_file.read()
data = (bottles_dir / "library.yml").read_text()
library = yaml.load(data, Loader=yaml.Loader)

View File

@@ -277,8 +277,7 @@ def create_details_window(parent_widget, game_id=None):
path = parent_widget.data_dir / "cartridges" / "games" / f"{game_id}.json"
if path.exists():
with open(path, "r") as open_file:
data = json.loads(open_file.read())
data = json.loads(path.read_text())
data.update(values)
save_game(parent_widget, data)
else:

View File

@@ -33,8 +33,7 @@ def get_games(parent_widget, game_ids=None):
game_files = games_dir.iterdir()
for game in game_files:
with open((games_dir / game), "r") as open_file:
data = json.loads(open_file.read())
data = json.loads((games_dir / game).read_text())
games[data["game_id"]] = data
return games

View File

@@ -58,8 +58,7 @@ def heroic_parser(parent_widget):
if not schema.get_boolean("heroic-import-epic"):
pass
elif (heroic_dir / "lib-cache" / "library.json").exists():
with open((heroic_dir / "lib-cache" / "library.json"), "r") as open_file:
data = open_file.read()
data = (heroic_dir / "lib-cache" / "library.json").read_text()
library = json.loads(data)
try:
@@ -112,8 +111,7 @@ def heroic_parser(parent_widget):
if not schema.get_boolean("heroic-import-gog"):
pass
elif (heroic_dir / "gog_store" / "installed.json").exists():
with open((heroic_dir / "gog_store" / "installed.json"), "r") as open_file:
data = open_file.read()
data = (heroic_dir / "gog_store" / "installed.json").read_text()
installed = json.loads(data)
importer.total_queue += len(installed["installed"])
@@ -133,8 +131,7 @@ def heroic_parser(parent_widget):
continue
# Get game title and developer from library.json as they are not present in installed.json
with open((heroic_dir / "gog_store" / "library.json"), "r") as open_file:
data = open_file.read()
data = (heroic_dir / "gog_store" / "library.json").read_text()
library = json.loads(data)
for game in library["games"]:
if game["app_name"] == app_name:
@@ -165,8 +162,7 @@ def heroic_parser(parent_widget):
if not schema.get_boolean("heroic-import-sideload"):
pass
elif (heroic_dir / "sideload_apps" / "library.json").exists():
with open((heroic_dir / "sideload_apps" / "library.json"), "r") as open_file:
data = open_file.read()
data = (heroic_dir / "sideload_apps" / "library.json").read_text()
library = json.loads(data)
importer.total_queue += len(library["games"])

View File

@@ -25,5 +25,6 @@ def save_game(parent_widget, game):
games_dir.mkdir(parents=True, exist_ok=True)
with open((games_dir / f'{game["game_id"]}.json'), "w") as open_file:
open_file.write(json.dumps(game, indent=4, sort_keys=True))
(games_dir / f'{game["game_id"]}.json').write_text(
json.dumps(game, indent=4, sort_keys=True)
)

View File

@@ -46,8 +46,7 @@ def get_game(
):
values = {}
with open(appmanifest, "r") as open_file:
data = open_file.read()
data = appmanifest.read_text()
for datatype in datatypes:
value = re.findall(f'"{datatype}"\t\t"(.*)"\n', data)
values[datatype] = value[0]