Ejemplo n.º 1
0
        def rmdir(session, args):
            # validate and build paths
            args = list(map(session.resolve_full_path, args))
            for arg in args:
                if not arg:
                    errors.path_invalid(arg)
                    return

            is_dir = list(map(session.is_dir, args))
            for i, answer in enumerate(is_dir):
                if not answer:
                    errors.wrong_type(args[i], "directory")
                    return

            to_remove = []
            for dir in args:
                children = session.handle_ls(Commands.ls, [dir])

                if len(children) > 2:
                    logger.print_info("Directory {} is not empty. Do you want to remove it with all its contents?\n"
                                      "Print \"yes\" to proceed, or anything else to abort operation.".format(dir))
                    response = input()
                    if response.strip(" ") != "yes":
                        logger.print_info(f"Directory {dir} will not be removed")
                    else:
                        logger.print_info(f"Directory {dir} will be removed")
                        to_remove.append(dir)

                else:
                    to_remove.append(dir)

            CommandConfig.Actions.__n_args_handler(session.send_command, Commands.rmdir, to_remove)
Ejemplo n.º 2
0
        def info(session, args):
            args = list(map(session.resolve_full_path, args))
            for arg in args:
                if not arg:
                    errors.path_invalid(arg)
                    return

            session.handle_info(Commands.info, args)
Ejemplo n.º 3
0
        def print(session, args):
            source = session.resolve_full_path(args[0])
            if not source:
                errors.path_invalid(args[0])
                return

            is_dir = session.is_dir(source)
            if is_dir:
                errors.wrong_type(args[0], "file")
                return
            session.handle_print(Commands.print, source)
Ejemplo n.º 4
0
        def ls(session, args):
            if len(args) == 0:
                args.append(session.get_curr_dir())
            args[0] = session.resolve_full_path(args[0])
            if not args[0]:
                errors.path_invalid(args[0])
                return

            res = session.handle_ls(Commands.ls, args)
            if res is str:
                logger.print_info(res)
            else:
                logger.print_info('\n'.join(res))
Ejemplo n.º 5
0
        def cd(session, args):
            new_path = session.resolve_full_path(args[0])
            if not new_path:
                errors.path_invalid(new_path)
                return

            is_dir = session.is_dir(new_path)
            if not is_dir:
                errors.wrong_type(new_path, "directory")
                logger.handle_error(f"Path {new_path} is not a directory!")
                return

            session.change_curr_dir(new_path)
Ejemplo n.º 6
0
        def rm(session, args):
            args = list(map(session.resolve_full_path, args))
            for arg in args:
                if not arg:
                    errors.path_invalid(arg)
                    return

            is_dir = list(map(session.is_dir, args))
            for i, answer in enumerate(is_dir):
                if answer == 1:
                    errors.wrong_type(args[i], "file")
                    return

            CommandConfig.Actions.__n_args_handler(session.send_command, Commands.rm, args)
Ejemplo n.º 7
0
        def __create_new_path(session, command, args):
            real_paths = list(map(session.resolve_full_path, args))
            for path in real_paths:
                if path:
                    errors.path_already_exists(path)
                    return

            args = list(map(session.resolve_partial_path, args))
            for path in args:
                if not path:
                    errors.path_invalid(path)
                    return

            CommandConfig.Actions.__n_args_handler(session.send_command, command, args)
Ejemplo n.º 8
0
        def __copy_command(session, command, args):
            args[0] = session.resolve_full_path(args[0])
            path_exists = session.resolve_full_path(args[1])

            if path_exists:
                errors.path_already_exists(args[1])
                return

            args[1] = session.resolve_partial_path(args[1])
            for arg in args:
                if not arg:
                    errors.path_invalid(arg)
                    return

            session.send_command(command, *args)
Ejemplo n.º 9
0
        def upload(session, args):
            if len(args) == 1:
                file_name = args[0].split(parameters.sep)[-1]

                args.append(file_name)

            path_exists = session.resolve_full_path(args[1])
            if path_exists:
                errors.path_already_exists(args[1])
                return

            args[1] = session.resolve_partial_path(args[1])

            if not args[1]:
                errors.path_invalid(args[1])
                return

            session.handle_upload(Commands.upload, args)