Skip to content

MaxFilesCount

Bases: BaseFileLimit, FrozenModel

Limits the total number of files handled by File Downloader or File Mover.

All files until specified limit (including) will be downloaded/moved, but limit+1 will not.

This doesn't apply to directories.

Added in 0.8.0

Replaces deprecated onetl.core.FileLimit

Parameters:

  • limit (int) –

    Maximum number of files to handle.

Examples:

Create filter which allows to download/move up to 100 files, but stops on 101:

from onetl.file.limit import MaxFilesCount

limit = MaxFilesCount(100)

is_reached property

Check if limit is reached.

Added in 0.8.0

Returns:

  • bool

    True if limit is reached, False otherwise.

Examples:

>>> from onetl.impl import LocalPath
>>> limit.is_reached
False
>>> limit.stops_at(LocalPath("/path/to/file.csv"))
False
>>> limit.is_reached
False
>>> # after limit is reached
>>> limit.stops_at(LocalPath("/path/to/file.csv"))
True
>>> limit.is_reached
True

reset()

Resets the internal limit state.

Added in 0.8.0

Returns:

  • Self

    Returns a filter of the same type, but with non-reached state.

    It could be the same filter or a new one, this is an implementation detail.

Examples:

>>> limit.is_reached
True
>>> new_limit = limit.reset()
>>> new_limit.is_reached
False

stops_at(path)

Update internal state and return current state.

Added in 0.8.0

Parameters:

  • path (PathProtocol) –

    Path to check

Returns:

  • bool

    True if limit is reached, False otherwise.

Examples:

>>> from onetl.impl import LocalPath
>>> # limit is not reached yet
>>> limit.stops_at(LocalPath("/path/to/file.csv"))
False
>>> # after limit is reached
>>> limit.stops_at(LocalPath("/path/to/another.csv"))
True
>>> # at this point, .stops_at() and .is_reached will always return True,
>>> # even on inputs that returned False before.
>>> # it will be in the same state until .reset() is called
>>> limit.stops_at(LocalPath("/path/to/file.csv"))
True