Exemplo n.º 1
0
    def main(self, ns: Namespace, term: Terminal) -> None:
        try:
            if self.path.is_file():
                return self.path.read_text('utf-8')
            raise OSException('error: not a file')

        except OSError:
            raise OSException('error: no such file') from None
Exemplo n.º 2
0
    def main(self, ns: Namespace, term: Terminal) -> None:
        try:
            if self.path.is_file():
                return ('Sorry, we did not manage in time :(')

            raise OSException('error: not a file')

        except OSError:
            raise OSException('error: no such file') from None
Exemplo n.º 3
0
    def main(self, ns: Namespace, term: Terminal) -> None:
        if not self.dest.is_dir():
            raise OSException('error: destination is not a directory')

        for src in self.srcs:
            try:
                src.copy(self.dest)
            except OSError:
                raise OSException('error: failed to copy path') from None
Exemplo n.º 4
0
    def main(self, ns: Namespace, term: Terminal) -> None:
        try:
            if self.dest.is_dir():
                for src in self.srcs:
                    src.rename(self.dest / src.name)
            else:
                # rename attempt
                src = self.srcs.pop()
                if self.srcs:
                    raise OSException('error: cannot rename several files')

                src.rename(self.dest)
        except OSError:
            raise OSException('error: failed to move/rename paths')
Exemplo n.º 5
0
    def main(self, ns: Namespace, term: Terminal) -> None:
        is_dir = self.path.is_dir()

        try:
            if self.recursive:
                delete_recursive(self.path)
            elif is_dir:
                if self.dir:
                    self.path.rmdir()
                else:
                    raise OSException('error: is a directory')
            else:
                if self.dir:
                    raise OSException('error: not a directory')
                else:
                    self.path.unlink()

        except OSError:
            raise OSException('error: failed to remove given path') from None
Exemplo n.º 6
0
    def handle_paths(self, ns: Namespace, term: Terminal) -> None:
        paths = ns.paths.copy()

        if len(paths) < 2:
            raise OSException('error: not enough paths given')

        *self.srcs, self.dest = (term.fs.get_path(term.path,
                                                  path,
                                                  check_dir=False)
                                 for path in paths)
Exemplo n.º 7
0
    def main(self, ns: Namespace, term: Terminal) -> None:
        if self.dir.exists():
            raise OSException('error: path already exists')
        try:
            if self.resolve:
                path, parts = self.dir.clone(), list()

                while not path.exists():
                    parts.append(path.name)
                    path = path.parent

                for part in reversed(parts):
                    path /= part
                    path.mkdir()

            else:
                self.dir.mkdir()

        except OSError:
            raise OSException('error: can not find path') from None
Exemplo n.º 8
0
    def execute(self, string: str, term: Terminal) -> None:
        args: List[str] = string.split()

        if not args:
            return

        commands = self._commands
        command_name = args.pop(0)
        if command_name in commands:
            return commands.get(command_name).execute(term=term, args=args)

        raise OSException(f'error: could not execute string: {string!r}')
Exemplo n.º 9
0
 def main(self, ns: Namespace, term: Terminal) -> None:
     try:
         self.path.touch()
     except OSError:
         raise OSException('error: no such file or directory') from None
Exemplo n.º 10
0
    def handle_path(self, ns: Namespace, term: Terminal) -> None:
        if ns.path is None:
            raise OSException('error: path not specified')

        self.path = term.fs.get_path(term.path, ns.path, check_existing=False)
Exemplo n.º 11
0
 def exit(self, status: int = 0, message: str = '') -> None:
     raise OSException(message.strip('\n'))
Exemplo n.º 12
0
 def main(self, ns: Namespace, term: Terminal) -> None:
     try:
         self.dir.rmdir()
     except OSError:
         raise OSException('error: directory not empty') from None
Exemplo n.º 13
0
    def handle_dir(self, ns: Namespace, term: Terminal) -> None:
        if ns.dir is None:
            raise OSException('error: dir not specified')

        self.dir = term.fs.get_path(term.path, ns.dir)