nexusLIMS.utils.files#

File finding and manipulation utilities for NexusLIMS.

Module Contents#

Functions#

find_dirs_by_mtime

Find directories modified between two times.

find_files_by_mtime

Find files motified between two times.

gnu_find_files_by_mtime

Find files modified between two times.

API#

nexusLIMS.utils.files.find_dirs_by_mtime(path: str, dt_from: datetime, dt_to: datetime, *, followlinks: bool = True) List[str][source]#

Find directories modified between two times.

Given two timestamps, find the directories under a path that were last modified between the two.

Deprecated since version 0.0.9: find_dirs_by_mtime is not recommended for use to find files for record inclusion, because subsequent modifications to a directory (e.g. the user wrote a text file or did some analysis afterwards) means no files will be returned from that directory (because it is not searched)

Parameters:
  • path – The root path from which to start the search

  • dt_from – The “starting” point of the search timeframe

  • dt_to – The “ending” point of the search timeframe

  • followlinks – Argument passed on to pyos.walk() to control whether symbolic links are followed

Returns:

dirs – A list of the directories that have modification times within the time range provided

Return type:

list

nexusLIMS.utils.files.find_files_by_mtime(path: Path, dt_from, dt_to) List[Path][source]#

Find files motified between two times.

Given two timestamps, find files under a path that were last modified between the two.

Parameters:
  • path – The root path from which to start the search

  • dt_from (datetime) – The “starting” point of the search timeframe

  • dt_to (datetime) – The “ending” point of the search timeframe

Returns:

files – A list of the files that have modification times within the time range provided (sorted by modification time)

Return type:

list

nexusLIMS.utils.files.gnu_find_files_by_mtime(path: Path, dt_from: datetime, dt_to: datetime, extensions: List[str] | None = None, *, followlinks: bool = True) List[Path][source]#

Find files modified between two times.

Given two timestamps, find files under a path that were last modified between the two. Uses the system-provided GNU find command. In basic testing, this method was found to be approximately 3 times faster than using find_files_by_mtime() (which is implemented in pure Python).

Parameters:
  • path – The root path from which to start the search, relative to the NX_INSTRUMENT_DATA_PATH environment setting.

  • dt_from – The “starting” point of the search timeframe

  • dt_to – The “ending” point of the search timeframe

  • extensions – A list of strings representing the extensions to find. If None, all files between are found between the two times.

  • followlinks – Whether to follow symlinks using the find command via the -H command line flag. This is useful when the NX_INSTRUMENT_DATA_PATH is actually a directory of symlinks. If this is the case and followlinks is False, no files will ever be found because the find command will not “dereference” the symbolic links it finds. See comments in the code for more comments on implementation of this feature.

Returns:

A list of the files that have modification times within the time range provided (sorted by modification time)

Return type:

List[str]

Raises:

RuntimeError – If the find command cannot be found, or running it results in output to stderr