Skip to content

Instantly share code, notes, and snippets.

@nothke
Created August 1, 2023 17:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nothke/1813917fbb38a9977723f2e2c8812891 to your computer and use it in GitHub Desktop.
Save nothke/1813917fbb38a9977723f2e2c8812891 to your computer and use it in GitHub Desktop.
Shakedown Rally itch uploader example
# A script for single [double] click uploading to itch using butler
# by Nothke
#
# Requirements:
# - Installed butler: https://itch.io/docs/butler/
# - butler added to PATH
#
# How to use:
# 1. Put this script in your project folder,
# 2. Edit the script by adding project names and ignores below
# 3. Run the script!
import os
import subprocess
import shutil
from shutil import ignore_patterns
import configparser
# --------------------------------------------
# ---- Add your project's specifics here! ----
# --------------------------------------------
source = "Release" # folder relative to script
target = "nothke/shakedown" # target itch project user/game
channel = "windows" # win|windows/linux/mac|osx/android [-stable, -beta]
# Add subfolders or patterns here to ignore
ignores = [
"log.txt",
"imgui.ini",
"NEngine-drive.pdb",
"with_shared_res.bat",
"guana.ini",
"kyzo.ini",
"sweden.ini",
"sweden.bat",
"NEngine-drive.exp",
"NEngine-drive.lib",
]
res_ignores = [
"mosk",
"rent",
"sweden.glb",
"testfield.glb",
"track_template.glb",
"guana.glb",
"testchk.gltf",
"b_3.4_track_test.glb"
]
expectedConfigValues = [
("screen", "fullscreen", 1),
("screen", "maximized", 0),
("screen", "width", 1600),
("screen", "height", 900),
("screen", "vsync", 1),
("audio", "masterVolume", 1),
("scene", "track", "/models/monty.glb"),
]
# Add external folders or files here to include TODO
# includes = []
# XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
# XXXXXX Code, don't touch this: XXXXXXX
script_path = os.path.dirname(os.path.realpath(__file__))
source_path = script_path + "\\" + source
temp_path = script_path + "\\butler_script_temp"
def remove_temp_folder():
if os.path.isdir(temp_path):
shutil.rmtree(temp_path)
def wait_quit():
input("Press Enter to close and cleanup..")
remove_temp_folder()
os._exit(1)
# Check if temp path already exists
if os.path.isdir(temp_path):
input("Temp folder already exists. Press Enter to remove it and proceed")
remove_temp_folder()
# Check if source folder exists
if not os.path.isdir(source_path):
print("Source folder " + source_path + " doesn't exist or is not a folder")
wait_quit()
# Copy to temporary folder to ignore certain files
shutil.copytree(source_path, temp_path,
ignore = ignore_patterns(*ignores))
# Validate config
config = configparser.ConfigParser()
configName = "config.ini"
configPath = temp_path + "\\" + configName
config.read(configPath)
badConfig = False
for val in expectedConfigValues:
if not config.has_option(val[0], val[1]):
print(configName + ": [" + val[0] + "][" + val[1] + "] entry doesn't exist")
badConfig = True
else:
v = config[val[0]][val[1]]
if v != str(val[2]):
print(configName + ": should be [" + val[0] + "] " + val[1] + " = "
+ str(val[2]) + " but is " + str(v))
badConfig = True
if badConfig:
wait_quit()
# Shakedown resource folder
shutil.copytree("..\\res", temp_path + "\\res",
ignore = ignore_patterns(*res_ignores))
#print("calling: butler push " + source_path + " " + target + ":" + channel)
# UPLOAD TO ITCH!
if input("Prepared folder for upload. Upload? (y/n)") == "y":
subprocess.call(['butler', 'push', temp_path, target + ":" + channel])
#remove the temporary folder
if input("Remove upload folder? (y/n)") == "y":
remove_temp_folder()
input("Press Enter to close..")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment