From 00ca5e06ba9fc8c2a0833de524141061ceea64e1 Mon Sep 17 00:00:00 2001
From: Gold856 <117957790+Gold856@users.noreply.github.com>
Date: Thu, 1 Jan 2026 19:35:14 -0500
Subject: [PATCH] Remove unused scripting system (#2269)
---
.../networktables/NetworkTablesManager.java | 3 -
.../common/scripting/ScriptConfig.java | 39 -----
.../common/scripting/ScriptEvent.java | 54 -------
.../common/scripting/ScriptEventType.java | 38 -----
.../common/scripting/ScriptManager.java | 140 ------------------
5 files changed, 274 deletions(-)
delete mode 100644 photon-core/src/main/java/org/photonvision/common/scripting/ScriptConfig.java
delete mode 100644 photon-core/src/main/java/org/photonvision/common/scripting/ScriptEvent.java
delete mode 100644 photon-core/src/main/java/org/photonvision/common/scripting/ScriptEventType.java
delete mode 100644 photon-core/src/main/java/org/photonvision/common/scripting/ScriptManager.java
diff --git a/photon-core/src/main/java/org/photonvision/common/dataflow/networktables/NetworkTablesManager.java b/photon-core/src/main/java/org/photonvision/common/dataflow/networktables/NetworkTablesManager.java
index 4c709d17f..6daa04990 100644
--- a/photon-core/src/main/java/org/photonvision/common/dataflow/networktables/NetworkTablesManager.java
+++ b/photon-core/src/main/java/org/photonvision/common/dataflow/networktables/NetworkTablesManager.java
@@ -45,8 +45,6 @@ import org.photonvision.common.logging.LogGroup;
import org.photonvision.common.logging.LogLevel;
import org.photonvision.common.logging.Logger;
import org.photonvision.common.networking.NetworkUtils;
-import org.photonvision.common.scripting.ScriptEventType;
-import org.photonvision.common.scripting.ScriptManager;
import org.photonvision.common.util.TimedTaskManager;
import org.photonvision.common.util.file.JacksonUtils;
@@ -183,7 +181,6 @@ public class NetworkTablesManager {
logger.info(msg);
HardwareManager.getInstance().setNTConnected(true);
- ScriptManager.queueEvent(ScriptEventType.kNTConnected);
getInstance().broadcastVersion();
getInstance().broadcastConnectedStatus();
diff --git a/photon-core/src/main/java/org/photonvision/common/scripting/ScriptConfig.java b/photon-core/src/main/java/org/photonvision/common/scripting/ScriptConfig.java
deleted file mode 100644
index 684a1a882..000000000
--- a/photon-core/src/main/java/org/photonvision/common/scripting/ScriptConfig.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright (C) Photon Vision.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-package org.photonvision.common.scripting;
-
-import com.fasterxml.jackson.annotation.JsonCreator;
-import com.fasterxml.jackson.annotation.JsonProperty;
-
-public class ScriptConfig {
- public final ScriptEventType eventType;
- public final String command;
-
- public ScriptConfig(ScriptEventType eventType) {
- this.eventType = eventType;
- this.command = "";
- }
-
- @JsonCreator
- public ScriptConfig(
- @JsonProperty("eventType") ScriptEventType eventType,
- @JsonProperty("command") String command) {
- this.eventType = eventType;
- this.command = command;
- }
-}
diff --git a/photon-core/src/main/java/org/photonvision/common/scripting/ScriptEvent.java b/photon-core/src/main/java/org/photonvision/common/scripting/ScriptEvent.java
deleted file mode 100644
index a60dd566a..000000000
--- a/photon-core/src/main/java/org/photonvision/common/scripting/ScriptEvent.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (C) Photon Vision.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-package org.photonvision.common.scripting;
-
-import java.io.IOException;
-import org.photonvision.common.logging.LogGroup;
-import org.photonvision.common.logging.Logger;
-import org.photonvision.common.util.ShellExec;
-
-public class ScriptEvent {
- private static final ShellExec executor = new ShellExec(true, true);
-
- public final ScriptConfig config;
- private final Logger logger = new Logger(ScriptEvent.class, LogGroup.General);
-
- public ScriptEvent(ScriptConfig config) {
- this.config = config;
- }
-
- public int run() throws IOException {
- int retVal = executor.executeBashCommand(config.command);
-
- String output = executor.getOutput();
- String error = executor.getError();
-
- if (!error.isEmpty()) {
- logger.error("Error when running \"" + config.eventType.name() + "\" script: " + error);
- } else if (!output.isEmpty()) {
- logger.info(
- String.format("Output from \"%s\" script: %s\n", config.eventType.name(), output));
- }
- logger.info(
- String.format(
- "Script for %s ran with command line: \"%s\", exit code: %d, output: %s, "
- + "error: %s\n",
- config.eventType.name(), config.command, retVal, output, error));
- return retVal;
- }
-}
diff --git a/photon-core/src/main/java/org/photonvision/common/scripting/ScriptEventType.java b/photon-core/src/main/java/org/photonvision/common/scripting/ScriptEventType.java
deleted file mode 100644
index 3fe98bf44..000000000
--- a/photon-core/src/main/java/org/photonvision/common/scripting/ScriptEventType.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (C) Photon Vision.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-package org.photonvision.common.scripting;
-
-public enum ScriptEventType {
- kProgramInit("Program Init"),
- kProgramExit("Program Exit"),
- kNTConnected("NT Connected"),
- kLEDOn("LED On"),
- kLEDOff("LED Off"),
- kEnterDriverMode("Enter Driver Mode"),
- kExitDriverMode("Exit Driver Mode"),
- kFoundTarget("Found Target"),
- kFoundMultipleTarget("Found Multiple Target"),
- kLostTarget("Lost Target"),
- kPipelineLag("Pipeline Lag");
-
- public final String value;
-
- ScriptEventType(String value) {
- this.value = value;
- }
-}
diff --git a/photon-core/src/main/java/org/photonvision/common/scripting/ScriptManager.java b/photon-core/src/main/java/org/photonvision/common/scripting/ScriptManager.java
deleted file mode 100644
index a47684cc5..000000000
--- a/photon-core/src/main/java/org/photonvision/common/scripting/ScriptManager.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * Copyright (C) Photon Vision.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-package org.photonvision.common.scripting;
-
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.LinkedBlockingDeque;
-import org.photonvision.common.hardware.Platform;
-import org.photonvision.common.logging.LogGroup;
-import org.photonvision.common.logging.Logger;
-import org.photonvision.common.util.TimedTaskManager;
-import org.photonvision.common.util.file.JacksonUtils;
-
-public class ScriptManager {
- private static final Logger logger = new Logger(ScriptManager.class, LogGroup.General);
-
- private ScriptManager() {}
-
- private static final List events = new ArrayList<>();
- private static final LinkedBlockingDeque queuedEvents =
- new LinkedBlockingDeque<>(25);
-
- public static void initialize() {
- ScriptConfigManager.initialize();
- if (ScriptConfigManager.fileExists()) {
- for (ScriptConfig scriptConfig : ScriptConfigManager.loadConfig()) {
- ScriptEvent scriptEvent = new ScriptEvent(scriptConfig);
- events.add(scriptEvent);
- }
-
- TimedTaskManager.getInstance().addTask("ScriptRunner", new ScriptRunner(), 10);
-
- } else {
- logger.error("Something went wrong initializing scripts! Events will not run.");
- }
- }
-
- private static class ScriptRunner implements Runnable {
- @Override
- public void run() {
- try {
- handleEvent(queuedEvents.takeFirst());
- } catch (InterruptedException e) {
- logger.error("ScriptRunner queue interrupted!", e);
- }
- }
-
- private void handleEvent(ScriptEventType eventType) {
- var toRun =
- events.parallelStream()
- .filter(e -> e.config.eventType == eventType)
- .findFirst()
- .orElse(null);
- if (toRun != null) {
- try {
- toRun.run();
- } catch (IOException e) {
- logger.error("Failed to run script for event \"" + eventType.name() + "\"", e);
- }
- }
- }
- }
-
- protected static class ScriptConfigManager {
- // protected static final Path scriptConfigPath =
- // Paths.get(ConfigManager.SettingsPath.toString(), "scripts.json");
- static final Path scriptConfigPath = Paths.get(""); // TODO: Waiting on config
-
- private ScriptConfigManager() {}
-
- static boolean fileExists() {
- return Files.exists(scriptConfigPath);
- }
-
- public static void initialize() {
- if (!fileExists()) {
- List eventsConfig = new ArrayList<>();
- for (var eventType : ScriptEventType.values()) {
- eventsConfig.add(new ScriptConfig(eventType));
- }
-
- try {
- JacksonUtils.serialize(scriptConfigPath, eventsConfig.toArray(new ScriptConfig[0]), true);
- } catch (IOException e) {
- logger.error("Failed to initialize!", e);
- }
- }
- }
-
- static List loadConfig() {
- try {
- var raw = JacksonUtils.deserialize(scriptConfigPath, ScriptConfig[].class);
- if (raw != null) {
- return List.of(raw);
- }
- } catch (IOException e) {
- logger.error("Failed to load scripting config!", e);
- }
- return new ArrayList<>();
- }
-
- protected static void deleteConfig() {
- try {
- Files.delete(scriptConfigPath);
- } catch (IOException e) {
- //
- }
- }
- }
-
- public static void queueEvent(ScriptEventType eventType) {
- if (Platform.isLinux()) {
- try {
- queuedEvents.putLast(eventType);
- logger.info("Queued event: " + eventType.name());
- } catch (InterruptedException e) {
- logger.error("Failed to add event to queue: " + eventType.name(), e);
- }
- }
- }
-}