src/pds_doi_service/core/input/input_util.py
def _read_from_path(self, path):
        """
        Parses DOI's from the file or files referenced by the provided path.
        If the path points to a single file, only that file is parsed. Otherwise,
        directories are walked for any files contained within. Any files with
        unsupported extensions are ignored.

        Parameters
        ----------
        path : str
            Path to the location to read. May be a single file or directory.

        Returns
        -------
        dois : list[doi]
            The list of Doi objects parsed from the provided path.

        Raises
        -------
        InputFormatException
            If an error is encountered while reading a local file.

        """
        dois = []

        if os.path.isfile(path):
            logger.info("Reading local file path %s", path)

            extension = os.path.splitext(path)[-1]

            if extension in self._valid_extensions:
                # Select the appropriate read function based on the extension
                read_function = self._parser_map[extension]

                try:
                    dois = read_function(path)
                except OSError as err:
                    msg = f"Error reading file {path}, reason: {str(err)}"

                    logger.error(msg)
                    raise InputFormatException(msg)

                # Make a note of where we can find the original input file that
                # resulted in these DOI's so we can save it to the transaction
                # history later on
                for doi in dois:
                    doi.input_source = path
            else:
                logger.info("File %s has unsupported extension, ignoring", path)
        else:
            logger.info("Reading files within directory %s", path)

            for sub_path in os.listdir(path):
                dois.extend(self._read_from_path(os.path.join(path, sub_path)))

        return dois

        Parses DOI's from the file or files referenced by the provided path.
        If the path points to a single file, only that file is parsed. Otherwise,
        directories are walked for any files contained within. Any files with
        unsupported extensions are ignored.

        Parameters
        ----------
        path : str
            Path to the location to read. May be a single file or directory.

        Returns
        -------
        dois : list[doi]
            The list of Doi objects parsed from the provided path.

        Raises
        -------
        InputFormatException
            If an error is encountered while reading a local file.

        
Parses DOI's from the file or files referenced by the provided path.
If the path points to a single file, only that file is parsed. Otherwise,
directories are walked for any files contained within. Any files with
unsupported extensions are ignored.

Parameters

path : str
Path to the location to read. May be a single file or directory.

Returns

dois : list[doi]
The list of Doi objects parsed from the provided path.

Raises

InputFormatException
If an error is encountered while reading a local file.
Parses DOI ' s from the file or files referenced by the provided path . If the path points to a single file only that file is parsed . Otherwise directories are walked for any files contained within . Any files with unsupported extensions are ignored . Parameters path : str Path to the location to read . May be a single file or directory . Returns dois : list [ doi ] The list of Doi objects parsed from the provided path . Raises InputFormatException If an error is encountered while reading a local file .
def _read_from_path(self, path):
        dois = []
        if os.path.isfile(path):
            logger.info("Reading local file path %s", path)
            extension = os.path.splitext(path)[-1]
            if extension in self._valid_extensions:
                read_function = self._parser_map[extension]
                try:
                    dois = read_function(path)
                except OSError as err:
                    msg = f"Error reading file {path}, reason: {str(err)}"
                    logger.error(msg)
                    raise InputFormatException(msg)
                for doi in dois:
                    doi.input_source = path
            else:
                logger.info("File %s has unsupported extension, ignoring", path)
        else:
            logger.info("Reading files within directory %s", path)
            for sub_path in os.listdir(path):
                dois.extend(self._read_from_path(os.path.join(path, sub_path)))
        return dois
def _read_from_path ( self , path ) : dois = [ ] if os . path . isfile ( path ) : logger . info ( "Reading local file path %s" , path ) extension = os . path . splitext ( path ) [ - 1 ] if extension in self . _valid_extensions : read_function = self . _parser_map [ extension ] try : dois = read_function ( path ) except OSError as err : msg = f"Error reading file {path}, reason: {str(err)}" logger . error ( msg ) raise InputFormatException ( msg ) for doi in dois : doi . input_source = path else : logger . info ( "File %s has unsupported extension, ignoring" , path ) else : logger . info ( "Reading files within directory %s" , path ) for sub_path in os . listdir ( path ) : dois . extend ( self . _read_from_path ( os . path . join ( path , sub_path ) ) ) return dois
Parses DOI's from the file or files referenced by the provided path.
Parses DOI ' s from the file or files referenced by the provided path .
"""
        Parses DOI's from the file or files referenced by the provided path.
        If the path points to a single file, only that file is parsed. Otherwise,
        directories are walked for any files contained within. Any files with
        unsupported extensions are ignored.

        Parameters
        ----------
        path : str
            Path to the location to read. May be a single file or directory.

        Returns
        -------
        dois : list[doi]
            The list of Doi objects parsed from the provided path.

        Raises
        -------
        InputFormatException
            If an error is encountered while reading a local file.

        """ # Select the appropriate read function based on the extension # Make a note of where we can find the original input file that # resulted in these DOI's so we can save it to the transaction # history later on
self
path