Exemplo n.º 1
0
def check_arg_input(parser, args):
    if not args.input:
        parser.error("-i, --input INPUT is required.")

    loader = Loader.get_loader(args.input)
    if loader == FSLoader:
        if os.path.isfile(
                args.input) and not is_a_supported_image_file_extension(
                    args.input):
            parser.error("Input {} file not supported format.".format(
                args.input))
        if os.path.isfile(args.input):
            check_image_file_validity(args.input)
    elif loader == HTTPLoader:
        if not check_url(args.input):
            parser.error(
                "Url {} of the http ressource doesn't exist or is not accesible."
                .format(args.input))
        if not is_a_supported_image_file_extension(args.input):
            parser.error(
                "Url {} is not file with a supported extension format.".format(
                    args.input))
    else:
        parser.error(
            "Input {} is not a valid file or directory or url.".format(
                args.input))
    return args.input
Exemplo n.º 2
0
    def _setup(self, *args):
        self._input_folder_path = self._args['input']
        self._output_folder_path = self._args['output']
        self._multiprocessing = Conf.multiprocessing()
        self._process_list = []
        Conf.log.debug([(r, d, f) for r, d, f in os.walk(self._input_folder_path)])

        for r, _, _ in os.walk(self._input_folder_path):
            args = copy.deepcopy(self._args)
            args['input'] = [
                x.path for x in os.scandir(r) if x.is_file() and is_a_supported_image_file_extension(x.path)
            ]
            args['phases'] = select_phases(self._args)
            args['output'] = [
                "{}{}{}".format(
                    os.path.splitext(x)[0],
                    '_out',
                    os.path.splitext(x)[1]
                )
                if not Conf.args['output'] else
                os.path.join(
                    Conf.args['output'],
                    pathlib.Path(*pathlib.Path(r).parts[1:]),
                    os.path.basename(x)
                )
                for x in args['input']
            ]

            self._process_list.append(
                (MultipleImageProcessing(), self.__get_folder_args(args, r))
            )
Exemplo n.º 3
0
def check_arg_output(parser, args):
    if os.path.isfile(args.input) and not args.output:
        _, extension = os.path.splitext(args.input)
        args.output = "output{}".format(extension)
    elif args.output and os.path.isfile(
            args.input) and not is_a_supported_image_file_extension(
                args.output):
        parser.error("Output {} file not a supported format.".format(
            args.output))