Initial set of tools for editing/running projects

This commit is contained in:
2025-01-18 21:25:27 -06:00
commit e239215895
7 changed files with 126 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
build
*.egg-info
__pycache__

13
goat/__init__.py Normal file
View File

@@ -0,0 +1,13 @@
import sys
from . import godot, gzdoom
def main():
project = godot.find_project(".") or gzdoom.find_project(".")
if not project:
raise Exception("could not find valid project")
command = sys.argv[1]
if command == "run":
project.run()
elif command == "edit":
project.edit()

11
goat/__main__.py Normal file
View File

@@ -0,0 +1,11 @@
import sys
import os
if __name__ == "__main__":
try:
from .goat import main
except ImportError:
sys.path.append(os.path.dirname(os.path.dirname(__file__)))
from goat import main
main()

29
goat/godot.py Normal file
View File

@@ -0,0 +1,29 @@
import os
import subprocess
from . import util
GODOT_PATHS = ["C:\Program Files (x86)\Steam\steamapps\common\Godot Engine\godot.windows.opt.tools.64.exe"]
GODOT_PROJECT = "project.godot"
class Project():
def __init__(self, path):
self.path = path
def run(self):
subprocess.run(find_command(), cwd=self.path)
def edit(self):
subprocess.run([find_command(), "--editor"], cwd=self.path)
def find_command():
for exe in GODOT_PATHS:
if os.path.exists(exe):
return exe
return "godot"
def find_project(path):
path = util.find_nearest(path, lambda entry: entry.lower() == GODOT_PROJECT)
if path is not None:
return Project(path)

37
goat/gzdoom.py Normal file
View File

@@ -0,0 +1,37 @@
import os
import subprocess
from . import util
GZDOOM_PATHS = []
SLADE_PATHS = []
GZDOOM_PROJECT = "iwadinfo.txt"
class Project():
def __init__(self, path):
self.path = path
def run(self):
subprocess.run([find_gzdoom_command(), "-iwad", "."], cwd=self.path)
def edit(self):
subprocess.run([find_slade_command(), "."], cwd=self.path)
def find_gzdoom_command():
for exe in GZDOOM_PATHS:
if os.path.exists(exe):
return exe
return "gzdoom"
def find_slade_command():
for exe in SLADE_PATHS:
if os.path.exists(exe):
return exe
return "slade"
def find_project(path):
path = util.find_nearest(path, lambda entry: entry.lower() == GZDOOM_PROJECT)
if path is not None:
return Project(path)

15
goat/util.py Normal file
View File

@@ -0,0 +1,15 @@
import os
def find_nearest(path, test):
path = os.path.abspath(path)
while True:
parent_path = os.path.dirname(path)
for entry in os.listdir(path):
if test(entry):
return path
if parent_path == path:
return None
path = parent_path

18
pyproject.toml Normal file
View File

@@ -0,0 +1,18 @@
[project]
name = "goat-tools"
version = "0.0.1"
dependencies = []
requires-python = ">=3.8"
authors = [
{name = "Gregory Marco", email = "greg@nanoyagi.com"}
]
maintainers = [
{name = "Gregory Marco", email = "greg@nanoyagi.com"}
]
[build-system]
requires = ["setuptools >= 61.0"]
build-backend = "setuptools.build_meta"
[project.scripts]
goat = "goat:main"