added timing
Package Application with PyInstaller / build (push) Successful in 27s

This commit is contained in:
LunaChocken
2025-06-09 18:02:02 +01:00
parent 153bf640be
commit 26840e7a40
4 changed files with 41 additions and 5 deletions
+18 -3
View File
@@ -9,6 +9,11 @@ from src.prompt_helper import PromptHelper
# Commandline options support # Commandline options support
import argparse import argparse
# basic attempt at making program faster
import datetime
from src.timing import timeit
from cachier import cachier
cachier = cachier(stale_after=datetime.timedelta(days=1), cache_dir='/tmp/.cache')
class TableItem: class TableItem:
@@ -90,14 +95,23 @@ class SteamGamePathTool:
else: else:
console.print("No game found") console.print("No game found")
@timeit
@cachier
def prepare_all_games(self):
game_rend = [Panel(self.get_game_content(game), expand=True) for game in self.games]
return game_rend
def print_all_games(self):
game_rend = self.prepare_all_games()
console = Console()
console.print(Columns(game_rend))
def prompt_user(self): def prompt_user(self):
game = self.prompter.prompt_game(text="Input (game name | appid | all | q/quit): ") game = self.prompter.prompt_game(text="Input (game name | appid | all | q/quit): ")
if game is None: if game is None:
return return
elif game == 'fetch_all_games': elif game == 'fetch_all_games':
console = Console() self.print_all_games()
game_rend = [Panel(self.get_game_content(game), expand=True) for game in self.games]
console.print(Columns(game_rend))
else: else:
console = Console() console = Console()
console.print(Panel(self.get_game_content(game), expand=True)) console.print(Panel(self.get_game_content(game), expand=True))
@@ -106,6 +120,7 @@ class SteamGamePathTool:
def sort_games(self, games): def sort_games(self, games):
return sorted(games, key=lambda x: x['name']) return sorted(games, key=lambda x: x['name'])
@cachier
def get_game_content(self, game): def get_game_content(self, game):
""" """
Takes a game dictionary and returns a string that formats game information into a string renderable by the console in the rich library. Takes a game dictionary and returns a string that formats game information into a string renderable by the console in the rich library.
+5 -2
View File
@@ -1,12 +1,13 @@
import prompt_toolkit as pt import prompt_toolkit as pt
from prompt_toolkit.completion import WordCompleter, FuzzyCompleter from prompt_toolkit.completion import WordCompleter, FuzzyCompleter
import sys import sys
from cachier import cachier
import datetime import datetime
from src.timing import timeit
from cachier import cachier
cachier = cachier(stale_after=datetime.timedelta(days=1), cache_dir='/tmp/.cache') cachier = cachier(stale_after=datetime.timedelta(days=1), cache_dir='/tmp/.cache')
@timeit
@cachier @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]
@@ -20,12 +21,14 @@ class PromptHelper:
self.game_list = game_list self.game_list = game_list
self.completer = generate_completer(game_list) self.completer = generate_completer(game_list)
@timeit
@cachier @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
@timeit
@cachier @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:
+16
View File
@@ -0,0 +1,16 @@
from functools import wraps
import time
debug = True
def timeit(func):
@wraps(func)
def timeit_wrapper(*args, **kwargs):
start_time = time.perf_counter()
result = func(*args, **kwargs)
end_time = time.perf_counter()
total_time = end_time - start_time
if debug:
print(f'Function {func.__name__} Took {total_time:.4f} seconds.')
return result
return timeit_wrapper
+2
View File
@@ -2,9 +2,11 @@ import os
import vdf import vdf
from cachier import cachier from cachier import cachier
import datetime import datetime
from src.timing import timeit
cachier = cachier(stale_after=datetime.timedelta(days=1), cache_dir='/tmp/.cache') cachier = cachier(stale_after=datetime.timedelta(days=1), cache_dir='/tmp/.cache')
@cachier @cachier
@timeit
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.