* build the python scripts achievements_gen.py and parse_controller_vdf.py into binary form using pyinstaller

* change the scripts `achievements_gen.py` and `parse_controller_vdf.py` to accept multiple files
This commit is contained in:
otavepto 2024-02-24 14:58:58 +02:00 committed by otavepto
parent f5d0b06ab4
commit 883dfac04f
8 changed files with 124 additions and 47 deletions

2
.gitignore vendored
View File

@ -17,7 +17,7 @@ tools/generate_emu_config/bin/
tools/generate_emu_config/login_temp/
tools/generate_emu_config/output/
tools/generate_emu_config/**/__pycache__/
tools/generate_emu_config/generate_emu_config*.spec
tools/generate_emu_config/**/*.spec
tools/generate_emu_config/**/my_login.txt
tools/generate_emu_config/top_owners_ids.txt

View File

@ -1,3 +1,8 @@
# 2024/2/24
* build the python scripts `achievements_gen.py` and `parse_controller_vdf.py` into binary form using `pyinstaller` for a more user friendly usage, suggested by **[DogancanYr]**
* change the scripts `achievements_gen.py` and `parse_controller_vdf.py` to accept multiple files
# 2024/2/23
* more accurately handle and download steamhttp requests in multi-threaded manner:

View File

@ -3,6 +3,7 @@
import vdf
import sys
import os
import traceback
keymap_digital = {
"button_a": "A",
@ -180,17 +181,44 @@ def generate_controller_config(controller_vdf, config_dir):
os.makedirs(config_dir)
for k in all_bindings:
with open(os.path.join(config_dir, k + '.txt'), 'w') as f:
with open(os.path.join(config_dir, f'{k}.txt'), 'w', encoding='utf-8') as f:
for b in all_bindings[k]:
f.write(b + "=" + ','.join(all_bindings[k][b]) + "\n")
f.write(f"{b}=" + ','.join(all_bindings[k][b]) + "\n")
def help():
exe_name = os.path.basename(sys.argv[0])
print(f"\nUsage: {exe_name} xbox_controller_config.vdf [xbox360_controller_config.vdf] ... ")
print(f" Example: {exe_name} xbox_controller_config.vdf")
print(f" Example: {exe_name} xboxone_controller.vdf xbox360_controller.vdf")
print("\nAt least 1 .vdf file must be provided\n")
if __name__ == '__main__':
if len(sys.argv) < 2:
print("format: {} xbox_controller_config.vdf".format(sys.argv[0]))
exit(0)
help()
sys.exit(1)
with open(sys.argv[1], 'rb') as f:
for vdf_file in sys.argv[1:]:
try:
print(f"parsing controller file '{vdf_file}'")
t = ''
with open(vdf_file, 'rb') as f:
t = f.read().decode('utf-8')
if t:
filename = os.path.basename(vdf_file)
outdir = os.path.join(f"{filename}_config", "steam_settings", "controller")
print(f"output dir: '{outdir}'")
generate_controller_config(t, outdir)
else:
print("[X] couldn't load file", file=sys.stderr)
generate_controller_config(t, os.path.join(sys.argv[1] + "_config/steam_settings", "controller"))
print('**********************************\n')
except Exception as e:
print("Unexpected error:")
print(e)
print("-----------------------")
for line in traceback.format_exception(e):
print(line)
print('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n')
sys.exit(0)

View File

@ -7,7 +7,6 @@ if [ "$(id -u)" -ne 0 ]; then
fi
build_dir="bin/linux"
tool_name="generate_emu_config"
out_dir="bin/package/linux"
script_dir=$( cd -- "$( dirname -- "${0}" )" &> /dev/null && pwd )
@ -21,6 +20,9 @@ apt install tar -y || exit 1
mkdir -p "$script_dir/$out_dir"
archive_file="$script_dir/$out_dir/$tool_name-linux.tar.gz"
archive_file="$script_dir/$out_dir/generate_emu_config-linux.tar.gz"
[[ -f "$archive_file" ]] && rm -f "$archive_file"
tar -C "$script_dir/$build_dir" -c -j -vf "$archive_file" "$tool_name"
pushd "$script_dir/$build_dir"
tar -c -j -vf "$archive_file" $(ls -d */)
popd

View File

@ -6,7 +6,6 @@ pushd "%~dp0"
set /a last_code=0
set "build_dir=bin\win"
set "tool_name=generate_emu_config"
set "out_dir=bin\package\win"
set /a MEM_PERCENT=90
@ -34,12 +33,12 @@ if not exist "%build_dir%" (
mkdir "%out_dir%"
set "archive_file=%out_dir%\%tool_name%-win.7z"
set "archive_file=%out_dir%\generate_emu_config-win.7z"
if exist "%archive_file%" (
del /f /q "%archive_file%"
)
"%packager%" a "%archive_file%" ".\%build_dir%\%tool_name%" -t7z -slp -ssw -mx -myx -mmemuse=p%MEM_PERCENT% -ms=on -mqs=off -mf=on -mhc+ -mhe- -m0=LZMA2:d=%DICT_SIZE_MB%m -mmt=%THREAD_COUNT% -mmtf+ -mtm- -mtc- -mta- -mtr+
"%packager%" a "%archive_file%" ".\%build_dir%\*" -t7z -slp -ssw -mx -myx -mmemuse=p%MEM_PERCENT% -ms=on -mqs=off -mf=on -mhc+ -mhe- -m0=LZMA2:d=%DICT_SIZE_MB%m -mmt=%THREAD_COUNT% -mmtf+ -mtm- -mtc- -mta- -mtr+
:script_end

View File

@ -4,8 +4,6 @@
venv=".env-linux"
out_dir="bin/linux"
build_temp_dir="bin/tmp/linux"
tool_name="generate_emu_config"
main_file="generate_emu_config.py"
[[ -d "$out_dir" ]] && rm -r -f "$out_dir"
mkdir -p "$out_dir"
@ -17,14 +15,21 @@ rm -f *.spec
chmod 777 "./$venv/bin/activate"
source "./$venv/bin/activate"
pyinstaller "$main_file" --distpath "$out_dir" -y --clean --onedir --name "$tool_name" --noupx --console -i "NONE" --workpath "$build_temp_dir" --collect-submodules "steam" || exit 1
echo building generate_emu_config...
pyinstaller "generate_emu_config.py" --distpath "$out_dir" -y --clean --onedir --name "generate_emu_config" --noupx --console -i "NONE" --workpath "$build_temp_dir" --collect-submodules "steam" || exit 1
cp -f "steam_default_icon_locked.jpg" "$out_dir/$tool_name"
cp -f "steam_default_icon_unlocked.jpg" "$out_dir/$tool_name"
cp -f "README.md" "$out_dir/$tool_name"
echo "Check the README" > "$out_dir/$tool_name/my_login.EXAMPLE.txt"
echo "Check the README" > "$out_dir/$tool_name/top_owners_ids.EXAMPLE.txt"
echo "You can use a website like: https://steamladder.com/ladder/games/" >> "$out_dir/$tool_name/top_owners_ids.EXAMPLE.txt"
echo building parse_controller_vdf...
pyinstaller "controller_config_generator/parse_controller_vdf.py" --distpath "$out_dir" -y --clean --onedir --name "parse_controller_vdf" --noupx --console -i "NONE" --workpath "$build_temp_dir" || exit 1
echo building parse_achievements_schema...
pyinstaller "stats_schema_achievement_gen/achievements_gen.py" --distpath "$out_dir" -y --clean --onedir --name "parse_achievements_schema" --noupx --console -i "NONE" --workpath "$build_temp_dir" || exit 1
cp -f "steam_default_icon_locked.jpg" "$out_dir/generate_emu_config"
cp -f "steam_default_icon_unlocked.jpg" "$out_dir/generate_emu_config"
cp -f "README.md" "$out_dir/generate_emu_config"
echo "Check the README" > "$out_dir/generate_emu_config/my_login.EXAMPLE.txt"
echo "Check the README" > "$out_dir/generate_emu_config/top_owners_ids.EXAMPLE.txt"
echo "You can use a website like: https://steamladder.com/games/" >> "$out_dir/generate_emu_config/top_owners_ids.EXAMPLE.txt"
echo;
echo =============

View File

@ -6,9 +6,7 @@ pushd "%~dp0"
set "venv=.env-win"
set "out_dir=bin\win"
set "build_temp_dir=bin\tmp\win"
set "tool_name=generate_emu_config"
set "icon_file=icon\Froyoshark-Enkel-Steam.ico"
set "main_file=generate_emu_config.py"
set "signer_tool=..\..\third-party\build\win\cert\sign_helper.bat"
set /a last_code=0
@ -32,30 +30,43 @@ del /f /q "*.spec"
call "%venv%\Scripts\activate.bat"
pyinstaller "%main_file%" --distpath "%out_dir%" -y --clean --onedir --name "%tool_name%" --noupx --console -i "%icon_file%" --workpath "%build_temp_dir%" --collect-submodules "steam" || (
echo building generate_emu_config...
pyinstaller "generate_emu_config.py" --distpath "%out_dir%" -y --clean --onedir --name "generate_emu_config" --noupx --console -i "%icon_file%" --workpath "%build_temp_dir%" --collect-submodules "steam" || (
set /a last_code=1
goto :script_end
)
for /f "usebackq tokens=* delims=" %%A in ('"%main_file%"') do (
call "%signer_tool%" "%out_dir%\%tool_name%\%%~nA.exe"
)
call "%signer_tool%" "%out_dir%\generate_emu_config\generate_emu_config.exe"
copy /y "steam_default_icon_locked.jpg" "%out_dir%\%tool_name%\"
copy /y "steam_default_icon_unlocked.jpg" "%out_dir%\%tool_name%\"
copy /y "README.md" "%out_dir%\%tool_name%\"
1>"%out_dir%\%tool_name%\my_login.EXAMPLE.txt" echo Check the README
1>"%out_dir%\%tool_name%\top_owners_ids.EXAMPLE.txt" echo Check the README
1>>"%out_dir%\%tool_name%\top_owners_ids.EXAMPLE.txt" echo You can use a website like: https://steamladder.com/ladder/games/
echo building parse_controller_vdf...
pyinstaller "controller_config_generator\parse_controller_vdf.py" --distpath "%out_dir%" -y --clean --onedir --name "parse_controller_vdf" --noupx --console -i "NONE" --workpath "%build_temp_dir%" || (
set /a last_code=1
goto :script_end
)
call "%signer_tool%" "%out_dir%\parse_controller_vdf\parse_controller_vdf.exe"
echo building parse_achievements_schema...
pyinstaller "stats_schema_achievement_gen\achievements_gen.py" --distpath "%out_dir%" -y --clean --onedir --name "parse_achievements_schema" --noupx --console -i "NONE" --workpath "%build_temp_dir%" || (
set /a last_code=1
goto :script_end
)
call "%signer_tool%" "%out_dir%\parse_achievements_schema\parse_achievements_schema.exe"
copy /y "steam_default_icon_locked.jpg" "%out_dir%\generate_emu_config\"
copy /y "steam_default_icon_unlocked.jpg" "%out_dir%\generate_emu_config\"
copy /y "README.md" "%out_dir%\generate_emu_config\"
1>"%out_dir%\generate_emu_config\my_login.EXAMPLE.txt" echo Check the README
1>"%out_dir%\generate_emu_config\top_owners_ids.EXAMPLE.txt" echo Check the README
1>>"%out_dir%\generate_emu_config\top_owners_ids.EXAMPLE.txt" echo You can use a website like: https://steamladder.com/games/
echo:
echo =============
echo Built inside: "%out_dir%\"
:script_end
if exist "%build_temp_dir%" (
rmdir /s /q "%build_temp_dir%"
)
:script_end
popd
endlocal & (
exit /b %last_code%

View File

@ -3,6 +3,7 @@ import sys
import os
import json
import copy
import traceback
STAT_TYPE_INT = '1'
@ -115,13 +116,39 @@ def generate_stats_achievements(
return (achievements_out, stats_out,
copy_default_unlocked_img, copy_default_locked_img)
def help():
exe_name = os.path.basename(sys.argv[0])
print(f"\nUsage: {exe_name} UserGameStatsSchema_480.bin [UserGameStatsSchema_2370.bin] ... ")
print(f" Example: {exe_name} UserGameStatsSchema_480.bin")
print(f" Example: {exe_name} UserGameStatsSchema_480.bin UserGameStatsSchema_2370.bin")
print("\nAt least 1 .bin file must be provided\n")
if __name__ == '__main__':
if len(sys.argv) < 2:
print("format: {} UserGameStatsSchema_480.bin".format(sys.argv[0]))
exit(0)
help()
sys.exit(1)
with open(sys.argv[1], 'rb') as f:
for bin_file in sys.argv[1:]:
try:
print(f"parsing schema file '{bin_file}'")
schema: bytes = b''
with open(bin_file, 'rb') as f:
schema = f.read()
if schema:
filename = os.path.basename(bin_file)
outdir = os.path.join(f"{filename}_output", "steam_settings")
print(f"output dir: '{outdir}'")
generate_stats_achievements(schema, outdir)
else:
print("[X] couldn't load file", file=sys.stderr)
generate_stats_achievements(schema, os.path.join("{}".format( "{}_output".format(sys.argv[1])), "steam_settings"))
print('**********************************\n')
except Exception as e:
print("Unexpected error:")
print(e)
print("-----------------------")
for line in traceback.format_exception(e):
print(line)
print('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n')
sys.exit(0)