add caching
Package Application with PyInstaller / build (push) Successful in 26s

This commit is contained in:
LunaChocken
2025-06-09 17:26:44 +01:00
parent 711579e2b1
commit 153bf640be
3 changed files with 13 additions and 8 deletions
+4 -1
View File
@@ -1,11 +1,14 @@
# -*- mode: python ; coding: utf-8 -*- # -*- mode: python ; coding: utf-8 -*-
from PyInstaller.utils.hooks import collect_data_files
datas = []
datas += collect_data_files('cachier')
a = Analysis( a = Analysis(
['main.py'], ['main.py'],
pathex=[], pathex=[],
binaries=[], binaries=[],
datas=[], datas=datas,
hiddenimports=[], hiddenimports=[],
hookspath=[], hookspath=[],
hooksconfig={}, hooksconfig={},
+4 -3
View File
@@ -4,9 +4,10 @@ import sys
from cachier import cachier from cachier import cachier
import datetime import datetime
cachier = cachier(stale_after=datetime.timedelta(days=1), cache_dir='/tmp/.cache')
@cachier(stale_after=datetime.timedelta(days=1), cache_dir='/tmp/.cache') @cachier
def generate_completer(game_list): def generate_completer(game_list):
g_list = [x['name'] for x in game_list] + [x['appid'] for x in game_list] g_list = [x['name'] for x in game_list] + [x['appid'] for x in game_list]
g_list.append("q") g_list.append("q")
@@ -19,13 +20,13 @@ class PromptHelper:
self.game_list = game_list self.game_list = game_list
self.completer = generate_completer(game_list) self.completer = generate_completer(game_list)
@cachier(stale_after=datetime.timedelta(days=1), cache_dir='/tmp/.cache') @cachier
def find_game_str(self, game_name) -> dict|None: def find_game_str(self, game_name) -> dict|None:
for game in self.game_list: for game in self.game_list:
if game['name'] == game_name: if game['name'] == game_name:
return game return game
@cachier(stale_after=datetime.timedelta(days=1), cache_dir='/tmp/.cache') @cachier
def find_game_num(self, appid: str) -> dict|None: def find_game_num(self, appid: str) -> dict|None:
for game in self.game_list: for game in self.game_list:
if game['appid'] == appid: if game['appid'] == appid:
+5 -4
View File
@@ -2,8 +2,9 @@ import os
import vdf import vdf
from cachier import cachier from cachier import cachier
import datetime import datetime
cachier = cachier(stale_after=datetime.timedelta(days=1), cache_dir='/tmp/.cache')
@cachier(stale_after=datetime.timedelta(days=1)) @cachier
def parse_vdf(steam_vdf_path) -> dict: def parse_vdf(steam_vdf_path) -> dict:
""" """
Reads the Steam vdf file at the given path and returns the corresponding dict. Reads the Steam vdf file at the given path and returns the corresponding dict.
@@ -14,7 +15,7 @@ def parse_vdf(steam_vdf_path) -> dict:
vdf_data = vdf.loads(open(steam_vdf_path, 'r').read()) vdf_data = vdf.loads(open(steam_vdf_path, 'r').read())
return vdf_data return vdf_data
@cachier(stale_after=datetime.timedelta(days=1)) @cachier
def fetch_ids(vdf_json: dict): def fetch_ids(vdf_json: dict):
""" """
Prints all Steam app IDs from the given vdf data. Prints all Steam app IDs from the given vdf data.
@@ -80,13 +81,13 @@ def find_extra_locations(vdf_json):
return steam_library_locations return steam_library_locations
# Reads manifest of individual game vdfs # Reads manifest of individual game vdfs
@cachier(stale_after=datetime.timedelta(days=1), cache_dir='/tmp/.cache') @cachier
def read_game_vdf(gameID: int, steam_vdf_json: dict, path, game) -> dict: def read_game_vdf(gameID: int, steam_vdf_json: dict, path, game) -> dict:
with open(os.path.join(path, game), 'r') as f: with open(os.path.join(path, game), 'r') as f:
game_vdf = vdf.loads(f.read()) game_vdf = vdf.loads(f.read())
return game_vdf['AppState'] return game_vdf['AppState']
@cachier(stale_after=datetime.timedelta(days=1), cache_dir='/tmp/.cache') @cachier
def fetchall_vdfs(steam_vdf_json: dict): def fetchall_vdfs(steam_vdf_json: dict):
""" """
Reads all Steam game manifests in the given Steam VDF data and returns a list of dictionaries containing information about each game. Reads all Steam game manifests in the given Steam VDF data and returns a list of dictionaries containing information about each game.