java.lang.Object
com.inductiveautomation.ignition.common.script.builtin.SystemUtilities
Direct Known Subclasses:
DesignerSystemUtilities

public abstract class SystemUtilities extends Object
Provides core system functions exposed as system.util.* in scripting.

These functions are available across all Ignition scopes, although some implementations may vary depending on whether they are running in a Gateway, Client, or Designer context.

  • Field Details

    • DEFAULT_REQUEST_TIMEOUT

      protected static final int DEFAULT_REQUEST_TIMEOUT
    • LOG

      protected static final LoggerEx LOG
    • MSGLOG

      protected static final LoggerEx MSGLOG
  • Constructor Details

    • SystemUtilities

      public SystemUtilities()
  • Method Details

    • execute

      public static void execute(String[] commands) throws IOException
      Executes a shell command on the host operating system.
      Parameters:
      commands - An array of strings representing the command and its arguments.
      Throws:
      IOException - If an I/O error occurs during command execution.
    • getProperty

      public static String getProperty(String name)
      Returns the string value of the system property with the specified name.
      Parameters:
      name - The name of the system property.
      Returns:
      The string value of the system property, or null if it doesn't exist.
    • beep

      public static void beep()
    • playSoundClip

      public static void playSoundClip(String wavFile) throws IOException
      Throws:
      IOException
    • threadDump

      public String threadDump() throws IOException
      Gets a thread dump from the JVM and returns as a string.
      Throws:
      IOException
    • _getCpuUsageString

      protected Double _getCpuUsageString(ThreadInfo threadInfo)
    • setLoggingLevel

      public static void setLoggingLevel(String loggerName, String loggerLevel)
      Sets the logging level for the named logger.
    • playSoundClip

      public static void playSoundClip(String wavFile, double volume, boolean wait) throws IOException
      Throws:
      IOException
    • playSoundClip

      public static void playSoundClip(byte[] soundData) throws IOException
      Throws:
      IOException
    • playSoundClip

      public static void playSoundClip(byte[] soundData, double volume, boolean wait) throws IOException
      Throws:
      IOException
    • invokeAsynchronous

      public final Thread invokeAsynchronous(org.python.core.PyObject[] args, String[] keywords)
      Invokes the provided Python function in a background thread.

      This is useful for long-running operations that would otherwise block the main thread (e.g., the UI thread in a Client or Designer). Note that any operations that modify the UI from the background thread must be wrapped in system.util.invokeLater.

      Parameters:
      args - The arguments to the function, including 'function', 'args', 'kwargs', and 'description'.
      Returns:
      The Thread that was created to run the function.
    • _invokeAsyncImpl

      protected abstract Thread _invokeAsyncImpl(org.python.core.PyObject fun, org.python.core.PyObject[] args, String[] kwargs, @Nullable String description)
    • logger

      public static org.slf4j.Logger logger(String loggerName)
    • getLogger

      public static LoggerEx getLogger(String name)
    • jsonEncode

      public static String jsonEncode(org.python.core.PyObject pyObj) throws JSONException
      Encodes a PyObject into a JSON string.

      The conversion rules are as follows:

      • None into null
      • True/False into true/false
      • Python numbers (int, long, float) into JSON numbers
      • Dictionaries into JSON objects
      • Sequences (list, tuple) into JSON arrays
      • Dataset objects are converted into a JSON object with 'columns' and 'rows'
      Parameters:
      pyObj - The Python object to encode.
      Returns:
      A JSON string representation of the object.
      Throws:
      JSONException - If an error occurs during encoding.
    • jsonEncode

      public static String jsonEncode(DatasetUtilities.PyDataSet dataSet) throws JSONException
      Throws:
      JSONException
    • jsonEncode

      public static String jsonEncode(org.python.core.PyObject pyObj, int indentFactor) throws JSONException
      Encodes a PyObject into a JSON string with optional pretty-printing.
      Parameters:
      pyObj - The Python object to encode.
      indentFactor - The number of spaces to use for indentation in pretty-printing.
      Returns:
      A JSON string representation of the object.
      Throws:
      JSONException - If an error occurs during encoding.
    • jsonEncode

      public static String jsonEncode(DatasetUtilities.PyDataSet dataSet, int indentFactor) throws JSONException
      Throws:
      JSONException
    • jsonDecode

      public static org.python.core.PyObject jsonDecode(String jsonString) throws JSONException
      Decodes a JSON string into a PyObject.

      The mapping is the inverse of jsonEncode(PyObject), with the caveat that JSON arrays are always decoded as PyLists.

      Parameters:
      jsonString - The JSON string to decode.
      Returns:
      A PyObject representing the decoded JSON data.
      Throws:
      JSONException - If the provided string is not valid JSON.
    • translate

      public String translate(org.python.core.PyObject[] args, String[] kwargs)
    • translateImpl

      protected abstract @Nullable String translateImpl(@NonNull String term, @Nullable String locale, boolean strict) throws Exception
      Throws:
      Exception
    • parseTranslateArguments

      public static org.apache.commons.lang3.tuple.Triple<String,String,Boolean> parseTranslateArguments(org.python.core.PyObject[] args, String[] kwargs)
      Parse keyword arguments to the translate function. Broken into a unique function to avoid duplication in other, more specific contexts.
      Returns:
      A Triple containing the term, locale, and whether the 'strict' flag was passed.
      Throws:
      org.python.core.PyException - if there was an error parsing the arguments. Should be thrown directly.
    • modifyTranslation

      public void modifyTranslation(String term, String translation, String locale)
    • modifyTranslationImpl

      protected abstract void modifyTranslationImpl(@NonNull String term, @NonNull String translation, @Nullable String locale)
    • getSessionInfo

      public Dataset getSessionInfo()
    • getSessionInfo

      public Dataset getSessionInfo(String unameFilter)
    • getSessionInfo

      public Dataset getSessionInfo(String unameFilter, String projectFilter)
    • getSessionInfo

      public Dataset getSessionInfo(org.python.core.PyObject[] values, String[] keywords)
    • _getSessionInfo

      public abstract Dataset _getSessionInfo(String unameFilter, String projectFilter)
    • sendMessage

      public List<String> sendMessage(org.python.core.PyObject[] values, String[] keywords) throws Exception
      Throws:
      Exception
    • sendMessageInternal

      public abstract List<String> sendMessageInternal(String project, String messageHandler, org.python.core.PyDictionary payload, Properties filterParams) throws Exception
      Throws:
      Exception
    • sendRequest

      public Object sendRequest(org.python.core.PyObject[] values, String[] keywords) throws Exception
      Throws:
      Exception
    • sendRequestAsync

      public Request sendRequestAsync(org.python.core.PyObject[] values, String[] keywords)
    • sendRequestInternal

      protected final CompletableFuture<Object> sendRequestInternal(PyArgumentMap args, boolean async)
    • sendRequestInternal

      protected abstract CompletableFuture<Object> sendRequestInternal(String project, String messageHandler, @Nullable org.python.core.PyDictionary payload, Properties params)
    • getGatewayStatus

      public String getGatewayStatus(org.python.core.PyObject[] values, String[] keywords)
    • getVersion

      public Version getVersion() throws Exception
      Throws:
      Exception
    • getVersionInternal

      protected abstract Version getVersionInternal() throws Exception
      Throws:
      Exception
    • audit

      public abstract void audit(org.python.core.PyObject[] args, String[] keywords)