rattail.filemon.config

File Monitor Configuration

class rattail.filemon.config.LegacyProfile(config, key)[source]

This is a file monitor profile corresponding to the first generation of configuration syntax. E.g. it only supports function-based actions, and does not support keyword arguments.

Note

This profile type will be deprecated at some point in the future. All new code should assume use Profile instead.

class rattail.filemon.config.Profile(config, key)[source]

Simple class to hold configuration for a file monitor “profile”. The profile determines which folders to watch, which actions to take when new files appear, etc. Each instance of this class has the following attributes:

config

Reference to the underlying configuration object from which the profile derives its other attributes.

key

String which differentiates this profile from any others which may exist within the configuration.

dirs

List of directory paths which should be watched by the file monitor on behalf of this profile.

watch_locks

Whether the file monitor should watch for new files, or disappearance of file locks.

If False (the default), the file monitor will not use any special logic and will simply be on the lookout for any new files to appear; when they do, the configured action(s) will be invoked.

If this setting is True, then the simple appearance of a new file will not in itself cause any action(s) being taken. Instead, the file monitor will only watch for the disappearance of file “locks”, i.e. any file or directory whose name ends in ".lock". When the disappearance of such a lock is noticed, the configured action(s) will be invoked.

process_existing

Whether any pre-existing files present in the watched folder(s) should be automatically added to the processing queue.

If this is True (the default), then when the file monitor first starts, it will examine each watched folder to see if it already contains files. If it does, then each file will be added to the processing queue exactly as if the monitor had just noticed the file appear. The files will be added in order of creation timestam, in an effort to be consistent with the real-time behavior.

If this setting is False, any files which happen to exist when the file monitor first starts will be ignored.

stop_on_error

Whether the file monitor should halt processing for all future files, if a single error is encountered.

If this is True, then if a single file action raises an exception, all subsequent files to appear will be effectively ignored. No further actions will be taken for any of them.

If this is False (the default), then a single file error will only cause processing to halt for that particular file. Subsequent files which appear will still be processed as normal.

actions

List of ProfileAction instances representing the actions to be invoked when new files are discovered.

normalize_dirs(dirs)[source]

Normalize a list of directory paths. Converts all to absolute paths, and prunes those which do not exist or do not refer to directories.

class rattail.filemon.config.ProfileAction[source]

Simple class to hold configuration for a particular action defined within a monitor Profile. Each instance has the following attributes:

spec

The original “spec” string used to obtain the action callable.

action

A reference to the action callable.

args

A sequence of positional arguments to be passed to the callable (in addition to the file path) when invoking the action.

kwargs

A dictionary of keyword arguments to be passed to the callable (in addition to the positional arguments) when invoking the action.

retry_attempts

Number of attempts to make when invoking the action. Defaults to 1, meaning the first attempt will be made but no retries will happen.

retry_delay

Number of seconds to pause between retry attempts, if retry_attempts is greater than one. Defaults to 0.

rattail.filemon.config.load_legacy_profiles(config)[source]

Load all active legacy file monitor profiles defined within configuration.

rattail.filemon.config.load_profiles(config)[source]

Load all active file monitor profiles defined within configuration.