Ejemplo n.º 1
0
def find_linux_game_executable(path, make_executable=False):
    """Looks for a binary or shell script that launches the game in a directory"""
    if not MAGIC_AVAILABLE:
        logger.warning("Magic not available. Not finding Linux executables")
        return ""

    for base, _dirs, files in os.walk(path):
        candidates = {}
        for _file in files:
            if is_excluded_elf(_file):
                continue
            abspath = os.path.join(base, _file)
            file_type = magic.from_file(abspath)
            if "ASCII text executable" in file_type:
                candidates["shell"] = abspath
            if "Bourne-Again shell script" in file_type:
                candidates["bash"] = abspath
            if "POSIX shell script executable" in file_type:
                candidates["posix"] = abspath
            if "64-bit LSB executable" in file_type:
                candidates["64bit"] = abspath
            if "32-bit LSB executable" in file_type:
                candidates["32bit"] = abspath
        if candidates:
            if make_executable:
                for candidate in candidates.values():
                    system.make_executable(candidate)
            return (candidates.get("shell") or candidates.get("bash")
                    or candidates.get("posix") or candidates.get("64bit")
                    or candidates.get("32bit"))
    logger.error("Couldn't find a Linux executable in %s", path)
    return ""
Ejemplo n.º 2
0
 def chmodx(self, filename):
     """Make filename executable"""
     filename = self._substitute(filename)
     if not system.path_exists(filename):
         raise ScriptingError(
             "Invalid file '%s'. Can't make it executable" % filename)
     system.make_executable(filename)
Ejemplo n.º 3
0
    def extract(self,
                archive=None,
                dest=None,
                merge_single=None,
                callback=None):
        if not system.path_exists(archive):
            raise RunnerInstallationError(
                "Failed to extract {}".format(archive))
        try:
            extract_archive(archive, dest, merge_single=merge_single)
        except ExtractFailure as ex:
            logger.error(
                "Failed to extract the archive %s file may be corrupt",
                archive)
            raise RunnerInstallationError("Failed to extract {}: {}".format(
                archive, ex)) from ex
        os.remove(archive)

        if self.name == "wine":
            logger.debug("Clearing wine version cache")
            from lutris.util.wine.wine import get_wine_versions
            get_wine_versions.cache_clear()

        if self.runner_executable:
            runner_executable = os.path.join(settings.RUNNER_DIR,
                                             self.runner_executable)
            if os.path.isfile(runner_executable):
                system.make_executable(runner_executable)

        if callback:
            callback()
Ejemplo n.º 4
0
def find_linux_game_executable(path, make_executable=False):
    """Looks for a binary or shell script that launches the game in a directory"""
    for base, _dirs, files in os.walk(path):
        candidates = {}
        for _file in files:
            if "uninstall" in _file.lower():
                continue
            abspath = os.path.join(base, _file)
            file_type = magic.from_file(abspath)
            if "ASCII text executable" in file_type:
                candidates["shell"] = abspath
            if "64-bit LSB executable" in file_type:
                candidates["64bit"] = abspath
            if "32-bit LSB executable" in file_type:
                candidates["32bit"] = abspath
        if candidates:
            if make_executable:
                for file_type in candidates:
                    system.make_executable(candidates[file_type])
            return (
                candidates.get("shell")
                or candidates.get("64bit")
                or candidates.get("32bit")
            )
Ejemplo n.º 5
0
    def execute(self, data):
        """Run an executable file."""
        args = []
        terminal = None
        working_dir = None
        env = {}
        if isinstance(data, dict):
            self._check_required_params([("file", "command")], data, "execute")
            if "command" in data and "file" in data:
                raise ScriptingError(
                    "Parameters file and command can't be used "
                    "at the same time for the execute command",
                    data,
                )
            file_ref = data.get("file", "")
            command = data.get("command", "")
            args_string = data.get("args", "")
            for arg in shlex.split(args_string):
                args.append(self._substitute(arg))
            terminal = data.get("terminal")
            working_dir = data.get("working_dir")
            if not data.get("disable_runtime"):
                # Possibly need to handle prefer_system_libs here
                env.update(runtime.get_env())

            # Loading environment variables set in the script
            env.update(self.script_env)

            # Environment variables can also be passed to the execute command
            local_env = data.get("env") or {}
            env.update({key: self._substitute(value) for key, value in local_env.items()})
            include_processes = shlex.split(data.get("include_processes", ""))
            exclude_processes = shlex.split(data.get("exclude_processes", ""))
        elif isinstance(data, str):
            command = data
            include_processes = []
            exclude_processes = []
        else:
            raise ScriptingError("No parameters supplied to execute command.", data)

        if command:
            file_ref = "bash"
            args = ["-c", self._get_file(command.strip())]
            include_processes.append("bash")
        else:
            # Determine whether 'file' value is a file id or a path
            file_ref = self._get_file(file_ref)
        if system.path_exists(file_ref) and not system.is_executable(file_ref):
            logger.warning("Making %s executable", file_ref)
            system.make_executable(file_ref)
        exec_path = system.find_executable(file_ref)
        if not exec_path:
            raise ScriptingError("Unable to find executable %s" % file_ref)

        if terminal:
            terminal = system.get_default_terminal()

        if not working_dir or not os.path.exists(working_dir):
            working_dir = self.target_path

        command = MonitoredCommand(
            [exec_path] + args,
            env=env,
            term=terminal,
            cwd=working_dir,
            include_processes=include_processes,
            exclude_processes=exclude_processes,
        )
        command.start()
        GLib.idle_add(self.parent.attach_logger, command)
        self.heartbeat = GLib.timeout_add(1000, self._monitor_task, command)
        return "STOP"