From e239215895277e32f1c61b04d28a894b7dd9b47a Mon Sep 17 00:00:00 2001 From: Gregory Marco Date: Sat, 18 Jan 2025 21:25:27 -0600 Subject: [PATCH] Initial set of tools for editing/running projects --- .gitignore | 3 +++ goat/__init__.py | 13 +++++++++++++ goat/__main__.py | 11 +++++++++++ goat/godot.py | 29 +++++++++++++++++++++++++++++ goat/gzdoom.py | 37 +++++++++++++++++++++++++++++++++++++ goat/util.py | 15 +++++++++++++++ pyproject.toml | 18 ++++++++++++++++++ 7 files changed, 126 insertions(+) create mode 100644 .gitignore create mode 100644 goat/__init__.py create mode 100644 goat/__main__.py create mode 100644 goat/godot.py create mode 100644 goat/gzdoom.py create mode 100644 goat/util.py create mode 100644 pyproject.toml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8ed8678 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +build +*.egg-info +__pycache__ diff --git a/goat/__init__.py b/goat/__init__.py new file mode 100644 index 0000000..72cc434 --- /dev/null +++ b/goat/__init__.py @@ -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() diff --git a/goat/__main__.py b/goat/__main__.py new file mode 100644 index 0000000..52e4eed --- /dev/null +++ b/goat/__main__.py @@ -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() diff --git a/goat/godot.py b/goat/godot.py new file mode 100644 index 0000000..c991e7a --- /dev/null +++ b/goat/godot.py @@ -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) diff --git a/goat/gzdoom.py b/goat/gzdoom.py new file mode 100644 index 0000000..92b91b5 --- /dev/null +++ b/goat/gzdoom.py @@ -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) diff --git a/goat/util.py b/goat/util.py new file mode 100644 index 0000000..8d55048 --- /dev/null +++ b/goat/util.py @@ -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 diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..ae58b60 --- /dev/null +++ b/pyproject.toml @@ -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"