def files_in_to_out(self, in_path, out_path=None):
        """Write in files to out, calling the line_handler on each line.

        Calls file_in_to_out under the hood to format the in_path payload. The
        formatting processing is done by the self.formatter instance.

        Args:
            in_path: str, path-like, or an iterable (list/tuple) of
                     strings/paths. Each str/path can be a glob, relative or
                     absolute path.
            out_path: str or path-like. Can refer to a file or a directory.
                      will create directory structure if it doesn't exist. If
                      in-path refers to >1 file (e.g it's a glob or list), out
                      path can only be a directory - it doesn't make sense to
                      write >1 file to the same single file (this is no an
                      appender.) To ensure out_path is read as a directory and
                      not a file, be sure to have the path separator (/) at the
                      end.
                      Top tip: Path-like objects strip the trailing slash. If
                      you want to pass in a dir that does not exist yet as
                      out-path with a trailing /, you should be passing it as a
                      str to preserve the /.
                      If out_path is not specified or None, will in-place edit
                      and overwrite the in-files.

        Returns:
            None.

        """
        in_paths = get_glob(in_path)

        in_count = len(in_paths)
        if in_count == 0:
            logger.debug(f'in path found {in_count} paths.')
        else:
            logger.debug(f'in path found {in_count} paths:')
            for path in in_paths:
                logger.debug(f'{path}')
            logger.debug(
                'herewith ends the paths. will now process each file.')

        if in_paths:
            # derive the destination directory, ensure it's ready for writing
            basedir_out = None
            is_outfile_name_known = False
            if out_path:
                # outpath could be a file, or a dir
                pathlib_out = Path(out_path)
                # yep, Path() strips trailing /, hence check original string
                if isinstance(out_path, str) and out_path.endswith(os.sep):
                    # ensure dir - mimic posix mkdir -p
                    pathlib_out.mkdir(parents=True, exist_ok=True)
                    basedir_out = pathlib_out
                elif pathlib_out.is_dir():
                    basedir_out = pathlib_out
                else:
                    if len(in_paths) > 1:
                        raise Error(
                            f'{in_path} resolves to {len(in_paths)} files, '
                            'but you specified only a single file as out '
                            f'{out_path}. If the outpath is meant to be a '
                            'directory, put a / at the end.')

                    # at this point it must be a file (not dir) path
                    # make sure that the parent dir exists
                    basedir_out = pathlib_out.parent
                    basedir_out.parent.mkdir(parents=True, exist_ok=True)
                    is_outfile_name_known = True

            # loop through all the in files and write them to the out dir
            file_counter = 0
            is_edit = False
            for path in in_paths:
                actual_in = Path(path)
                # recursive glob returns dirs too, only interested in files
                if actual_in.is_file():
                    if basedir_out:
                        if is_outfile_name_known:
                            actual_out = pathlib_out
                        else:
                            # default to original src file name if only out dir
                            # specified without an out file name
                            actual_out = basedir_out.joinpath(actual_in.name)

                        logger.debug(f"writing {path} to {actual_out}")
                        self.in_to_out(in_path=actual_in, out_path=actual_out)
                    else:
                        logger.debug(f"editing {path}")
                        self.in_to_out(in_path=actual_in)
                        is_edit = True
                    file_counter += 1

            if is_edit:
                logger.info(
                    f"edited & wrote {file_counter} file(s) at {in_path}")
            else:
                logger.info(
                    f"read {in_path}, formatted and wrote {file_counter} "
                    f"file(s) to {out_path}")
        else:
            logger.info(f"{in_path} found no files")
def files_in_to_out ( self , in_path , out_path = None ) : in_paths = get_glob ( in_path ) in_count = len ( in_paths ) if in_count == 0 : logger . debug ( f'in path found {in_count} paths.' ) else : logger . debug ( f'in path found {in_count} paths:' ) for path in in_paths : logger . debug ( f'{path}' ) logger . debug ( 'herewith ends the paths. will now process each file.' ) if in_paths : basedir_out = None is_outfile_name_known = False if out_path : pathlib_out = Path ( out_path ) if isinstance ( out_path , str ) and out_path . endswith ( os . sep ) : pathlib_out . mkdir ( parents = True , exist_ok = True ) basedir_out = pathlib_out elif pathlib_out . is_dir ( ) : basedir_out = pathlib_out else : if len ( in_paths ) > 1 : raise Error ( f'{in_path} resolves to {len(in_paths)} files, ' 'but you specified only a single file as out ' f'{out_path}. If the outpath is meant to be a ' 'directory, put a / at the end.' ) basedir_out = pathlib_out . parent basedir_out . parent . mkdir ( parents = True , exist_ok = True ) is_outfile_name_known = True file_counter = 0 is_edit = False for path in in_paths : actual_in = Path ( path ) if actual_in . is_file ( ) : if basedir_out : if is_outfile_name_known : actual_out = pathlib_out else : actual_out = basedir_out . joinpath ( actual_in . name ) logger . debug ( f"writing {path} to {actual_out}" ) self . in_to_out ( in_path = actual_in , out_path = actual_out ) else : logger . debug ( f"editing {path}" ) self . in_to_out ( in_path = actual_in ) is_edit = True file_counter += 1 if is_edit : logger . info ( f"edited & wrote {file_counter} file(s) at {in_path}" ) else : logger . info ( f"read {in_path}, formatted and wrote {file_counter} " f"file(s) to {out_path}" ) else : logger . info ( f"{in_path} found no files" )
Write in files to out, calling the line_handler on each line.

        Calls file_in_to_out under the hood to format the in_path payload. The
        formatting processing is done by the self.formatter instance.

        Args:
            in_path: str, path-like, or an iterable (list/tuple) of
                     strings/paths. Each str/path can be a glob, relative or
                     absolute path.
            out_path: str or path-like. Can refer to a file or a directory.
                      will create directory structure if it doesn't exist. If
                      in-path refers to >1 file (e.g it's a glob or list), out
                      path can only be a directory - it doesn't make sense to
                      write >1 file to the same single file (this is no an
                      appender.) To ensure out_path is read as a directory and
                      not a file, be sure to have the path separator (/) at the
                      end.
                      Top tip: Path-like objects strip the trailing slash. If
                      you want to pass in a dir that does not exist yet as
                      out-path with a trailing /, you should be passing it as a
                      str to preserve the /.
                      If out_path is not specified or None, will in-place edit
                      and overwrite the in-files.

        Returns:
            None.