Beispiel #1
0
    def locate_file(self):
        if System.is_windows():
            command = f'explorer /select,"{self.__path}"'
        elif System.is_mac():
            # TODO not tested
            command = ["open", "-R", self.__path]
        elif System.is_linux():
            # TODO not tested
            command = ["nautilus", self.__path]
        else:
            raise core_exceptions.UnsupportedSystemError(System.platform())
        process = subprocess.Popen(command,
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE)
        stdout, stderr = process.communicate()
        if stdout or stderr:
            return OSError(f"""Unable to locate file: {self.__path}
STDOUT: {stdout.strip()}
STDERR: {stderr.strip()}""")
        return self.get_directory()
Beispiel #2
0
    def open(self):
        """Open path with default OS program."""
        if System.is_linux():
            subprocess.run(["xdg-open", self.__path])
        elif System.is_mac():
            subprocess.run(["open", self.__path])
        elif System.is_windows():
            if self.__path.startswith(WINDOWS_PATH_PREFIX):
                from pysaurus.core.native.windows import get_short_path_name

                path = get_short_path_name(self.standard_path)
                print("AbsolutePath: opening Windows short path",
                      path,
                      file=sys.stderr)
            else:
                path = self.__path
            FileSystem.startfile(path)
        else:
            raise core_exceptions.UnsupportedSystemError(System.platform())
        return self