All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.python.modules.posix.OS Maven / Gradle / Ivy

Go to download

Jython is an implementation of the high-level, dynamic, object-oriented language Python written in 100% Pure Java, and seamlessly integrated with the Java platform. It thus allows you to run Python on any Java platform.

There is a newer version: 2.7.4
Show newest version
/* Copyright (c) Jython Developers */
package org.python.modules.posix;

import java.util.Locale;
import org.python.core.PySystemState;
import org.python.core.RegistryKey;

/**
 * A Marker tagging what OS we're running on, with some accompanying information about
 * that platform.
 */
enum OS {
    NT("Windows", new String[] {"cmd.exe", "/c"}, new String[] {"command.com", "/c"}),
    // http://bugs.jython.org/issue1842
    IBMi("OS/400", new String[] {"/QOpenSys/usr/bin/sh", "-c"}),
    POSIX(new String[] {"/bin/sh", "-c"});

    /** An array of potential shell commands this platform may use. */
    private final String[][] shellCommands;

    /**
     * Name to match against os.name System property for identification
     * (os.name.startswith(pattern)). Defaults to name().
     */
    private final String pattern;

    OS(String pattern, String[]... shellCommands) {
        this.shellCommands = shellCommands;
        this.pattern = pattern != null ? pattern : name();
    }

    OS(String[]... shellCommands) {
        this(null, shellCommands);
    }

    String getModuleName() {
        return name().toLowerCase(Locale.ROOT);
    }

    String[][] getShellCommands() {
        return shellCommands;
    }

    /**
     * Return the OS we're running on.
     */
    static OS getOS() {
        String osName = PySystemState.registry.getProperty(
                                                RegistryKey.PYTHON_OS);
        if (osName == null) {
            osName = System.getProperty("os.name");
        }

        for (OS os : OS.values()) {
            if (osName.startsWith(os.pattern)) {
                return os;
            }
        }
        return OS.POSIX;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy