Exemple #1
0
    def runScript(self, script_path: pathlib.Path) -> None:
        """Runs the script at the given path and saves it's output.

        Args:
            script_path (pathlib.Path): The path to the script to run.
        """
        if script_path.is_file():
            self._logger.warning(
                'Calling build tool config script "{path}"'.format(path=script_path)
            )
            try:
                script_out = runCommand(
                    exe_args=ExeArgs(script_path.__str__(), [self.arch])
                )
                build_tool_cfg = json.loads(
                    script_out.std_out,
                    object_hook=lambda dict: SimpleNamespace(**dict),
                )
            except Exception as excp:
                self._logger.error(
                    'error "{error}" running build tool script "{path}"'.format(
                        error=excp, path=script_path
                    )
                )
            for item in build_tool_cfg.build_tools:
                if self.isBuildToolCfgOK(item):
                    self.build_tool_cfgs.append(item)
                else:
                    self._logger.error(
                        'build tool config "{cfg}" doesn\'t have all needed attributes!'.format(
                            cfg=script_path
                        )
                    )
    def install(self, dep: object) -> None:
        """Install the dependency.

        Args:
            dep (object): The dependency object to install.
        """
        try:
            self._logger.info(
                'trying to install "{name}" using command "{cmd}" with args "{args}"'.format(
                    name=dep.name, cmd=dep.install_cmd, args=dep.install_arguments
                )
            )
            output = runCommand(
                exe_args=ExeArgs(dep.install_cmd, dep.install_arguments)
            )
            self._logger.debug(output.std_out)
            self._logger.debug(output.err_out)
        except Exception as excp:
            self._logger.error(
                'error "{error}" trying to install "{name}" using command "{cmd}" with args "{args}"'.format(
                    error=excp,
                    name=dep.name,
                    cmd=dep.install_cmd,
                    args=dep.install_arguments,
                )
            )
Exemple #3
0
def getNumCoresOSX() -> CmdOutput:
    """Returns the number of physical cores.

    Returns:
        CmdOutput: The output of the command, as a `CmdOutput` instance containing
                    `stdout` and `stderr` as attributes.
    """
    return runCommand(exe_args=ExeArgs("sysctl", ["-n", "hw.physicalcpu"]))
Exemple #4
0
def getRAMSizeOSX() -> CmdOutput:
    """Returns the RAM size in bytes.

    Returns:
        CmdOutput: The output of the command, as a `CmdOutput` instance containing
                    `stdout` and `stderr` as attributes.
    """
    return runCommand(exe_args=ExeArgs("sysctl", ["-n", "hw.memsize"]))
Exemple #5
0
def getCPUNameOSX() -> CmdOutput:
    """Returns the CPU name.

    Returns:
        CmdOutput: The output of the command, as a `CmdOutput` instance containing
                    `stdout` and `stderr` as attributes.
    """
    return runCommand(exe_args=ExeArgs("sysctl", ["-n", "machdep.cpu.brand_string"]))
Exemple #6
0
def getCPUName() -> CmdOutput:
    """Gets the CPU name using `wmic`

    Returns:
        CmdOutput: The output of the command, as a `CmdOutput` instance containing
                    `stdout` and `stderr` as attributes.
    """
    return runCommand(exe_args=ExeArgs("wmic", ["cpu", "get", "Name"]))
Exemple #7
0
def getOSName() -> CmdOutput:
    """Returns the OS version of OS X.

    Returns:
        CmdOutput: The output of the command, as a `CmdOutput` instance containing
                    `stdout` and `stderr` as attributes.
    """
    return runCommand(exe_args=ExeArgs("sw_vers", ["-productVersion"]))
Exemple #8
0
def getNumLogCoresOSX() -> CmdOutput:
    """Returns the number of logical cores, including hyperthreading.

    Returns:
        CmdOutput: The output of the command, as a `CmdOutput` instance containing
                    `stdout` and `stderr` as attributes.
    """
    return runCommand(exe_args=ExeArgs("sysctl", ["-n", "hw.logicalcpu"]))
Exemple #9
0
def getGPUOSX() -> CmdOutput:
    """Return the GPU names.

    Returns:
         CmdOutput: The output of the command, as a `CmdOutput` instance containing
                    `stdout` and `stderr` as attributes.
    """
    return runCommand(exe_args=ExeArgs("system_profiler", ["SPDisplaysDataType"]))
Exemple #10
0
def getL3CacheOSX() -> CmdOutput:
    """Returns the size of the CPU's level 3 cache.

    Returns:
        CmdOutput: The output of the command, as a `CmdOutput` instance containing
                    `stdout` and `stderr` as attributes.
    """
    return runCommand(exe_args=ExeArgs("sysctl", ["-n", "hw.l3cachesize"]))
Exemple #11
0
def getGPUInfo() -> CmdOutput:
    """Returns the GPU names.

    Returns:
        CmdOutput: The output of the command, as a `CmdOutput` instance containing
                    `stdout` and `stderr` as attributes.
    """
    return runCommand(exe_args=ExeArgs(
        "wmic", ["path", "win32_VideoController", "get", "name"]))
Exemple #12
0
def getMemInfo() -> CmdOutput:
    """Returns the RAM size in bytes.

    Returns:
        CmdOutput: The output of the command, as a `CmdOutput` instance containing
                    `stdout` and `stderr` as attributes.
    """
    return runCommand(
        exe_args=ExeArgs("wmic", ["memorychip", "get", "capacity"]))
Exemple #13
0
def getGPUNamesLinux() -> CmdOutput:
    """Returns the names of the GPUs.

    Returns:
        CmdOutput: The output of the command, as a `CmdOutput` instance containing
                    `stdout` and `stderr` as attributes.
    """
    return runCommand(
        exe_args=ExeArgs("bash", ["-c", "lspci|grep VGA|cut -f3 -d':'"]))
Exemple #14
0
def getRAMSizeLinux() -> CmdOutput:
    """Returns the RAM size in bytes.

    Returns:
        CmdOutput: The output of the command, as a `CmdOutput` instance containing
                    `stdout` and `stderr` as attributes.
    """
    return runCommand(exe_args=ExeArgs(
        "bash", ["-c", "free -b|grep 'Mem:'|awk '{print $2}'"]))
Exemple #15
0
def getGPUNamesSbinLinux() -> CmdOutput:
    """Returns the names of the GPUs, using `/sbin/lspci` because some distributions
    don't have `lspci` in `/usr/bin`

    Returns:
        CmdOutput: The output of the command, as a `CmdOutput` instance containing
                    `stdout` and `stderr` as attributes.
    """
    return runCommand(
        exe_args=ExeArgs("bash", ["-c", "/sbin/lspci|grep VGA|cut -f3 -d':'"]))
Exemple #16
0
def getCPUNameLinux() -> CmdOutput:
    """Returns the CPU's name.

    Returns:
        CmdOutput: The output of the command, as a `CmdOutput` instance containing
                    `stdout` and `stderr` as attributes.
    """
    return runCommand(exe_args=ExeArgs(
        "bash",
        ["-c", "grep 'model name' /proc/cpuinfo |head -1|cut -d':' -f2-"],
    ))
Exemple #17
0
def getNumCoresLinux() -> CmdOutput:
    """Returns the number of physical cores.

    Returns:
        CmdOutput: The output of the command, as a `CmdOutput` instance containing
                    `stdout` and `stderr` as attributes.
    """
    return runCommand(exe_args=ExeArgs(
        "bash",
        ["-c", "grep 'cpu cores' /proc/cpuinfo |uniq|cut -d':' -f2"],
    ))
Exemple #18
0
def getNumLogCoresLinux() -> CmdOutput:
    """Returns the number of logical cores, including the hyperthreading.

    Returns:
        CmdOutput: The output of the command, as a `CmdOutput` instance containing
                    `stdout` and `stderr` as attributes.
    """
    return runCommand(exe_args=ExeArgs(
        "bash",
        ["-c", "grep siblings /proc/cpuinfo |uniq |cut -d':' -f2"],
    ))
Exemple #19
0
def getL2CacheLinux() -> CmdOutput:
    """Returns the size of the CPU's level 2 cache.

    Returns:
        CmdOutput: The output of the command, as a `CmdOutput` instance containing
                    `stdout` and `stderr` as attributes.
    """
    return runCommand(exe_args=ExeArgs(
        "bash",
        ["-c", "getconf -a|grep LEVEL2_CACHE_SIZE|awk '{print $2}'"],
    ))
Exemple #20
0
def getOSVer() -> CmdOutput:
    """Returns the minor OS version.

    Returns:
        CmdOutput: The output of the command, as a `CmdOutput` instance containing
                    `stdout` and `stderr` as attributes.
    """
    return runCommand(exe_args=ExeArgs(
        "bash",
        [
            "-c",
            "grep VERSION /etc/os-release |head -1|cut -d'=' -f2|tr -d '\"'",
        ],
    ))
Exemple #21
0
def getCPUInfo() -> CmdOutput:
    """Gets CPU info using `wmic`.

    Returns:
        CmdOutput: The output of the command, as a `CmdOutput` instance containing
                    `stdout` and `stderr` as attributes.
    """
    ret_val = runCommand(exe_args=ExeArgs(
        "wmic",
        [
            "cpu",
            "get",
            "L2CacheSize,L3CacheSize,NumberOfLogicalProcessors,NumberOfCores",
        ],
    ), )

    return ret_val
    def isExecuteableDep(self, dep: object) -> bool:
        """Execute the dependency, if that works, returns `True`.

        Args:
            dep (object): the dependency to run

        Returns:
            bool: `True` if the executable has been running OK and returns the
                         configured string.
                  `False` else
        """
        self._logger.info(
            'Checking dependency "{name}", try to run executable "{exe}" with argument "{arg}" against regex "{regex}"'.format(
                name=dep.name,
                exe=dep.ok_if_executable,
                arg=dep.executable_argument,
                regex=dep.executable_check_regex,
            )
        )

        try:
            matched_string = doesExecutableWork(
                exe_args=ExeArgs(dep.ok_if_executable, [dep.executable_argument]),
                check_regex=RunRegex(dep.executable_check_regex, 0),
            )

            if matched_string != "":
                return True

        except Exception as excp:
            self._logger.error(
                'error "{error}" dependency "{name}", trying to run executable "{exe}" with argument "{arg}" against regex "{regex}"'.format(
                    error=excp,
                    name=dep.name,
                    exe=dep.ok_if_executable,
                    arg=dep.executable_argument,
                    regex=dep.executable_check_regex,
                )
            )

        return False
Exemple #23
0
    def checkVersions(self) -> None:
        """Runs all configured build tools with the 'show version' argument.

        To check, if the configured build tools exist and are working, try to
        execute each with the argument to get the version string of the build
        tool.
        """
        for tool in self.build_tool_cfgs:
            if tool.build_tool_exe == "":
                self._logger.error(
                    'build tool "{name}" has no executable configured!'.format(
                        name=tool.name
                    )
                )
                continue

            exe_path = tool.build_tool_exe

            # has environment script to call
            if tool.env_script != "":
                self._logger.info(
                    '"{name}": calling environment script "{script}".'.format(
                        name=tool.name, script=tool.env_script
                    )
                )

            # has full path (so maybe not in PATH)
            elif tool.install_path != "":
                exe_path = os.path.normpath(
                    "/".join([tool.install_path, tool.build_tool_exe])
                )
                self._logger.info(
                    '"{name}": using path "{path}".'.format(
                        name=tool.name, path=exe_path
                    )
                )

            # no full path given, so it hopefully is in PATH
            else:
                self._logger.info(
                    '"{name}": checking if executable "{exe}" is in PATH.'.format(
                        name=tool.name, exe=tool.build_tool_exe
                    )
                )

            try:

                source_env_script = self.os in (LINUX_OS_STRING, OSX_OS_STRING)

                tool.version = doesExecutableWork(
                    exe_args=ExeArgs(exe_path, [tool.version_arg]),
                    env_args=EnvArgs(
                        tool.env_script,
                        [tool.env_script_arg],
                        source_env_script,
                    ),
                    check_regex=RunRegex(tool.version_regex, 1),
                )
                if tool.version != "":
                    tool.is_checked = True

            except Exception as excp:
                self._logger.error(
                    'error "{error}" parsing version of "{exe} {opt}" using version regex "{regex}"'.format(
                        error=excp,
                        exe=exe_path,
                        opt=tool.version_arg,
                        regex=tool.version_regex,
                    )
                )