labscript_utils.filewatcher.FileWatcher

class labscript_utils.filewatcher.FileWatcher(callback, files=None, folders=None, clean_modified_info=None, hashable_types=None, interval=1, **kwargs)[source]

Bases: object

__init__(callback, files=None, folders=None, clean_modified_info=None, hashable_types=None, interval=1, **kwargs)[source]

Detect modification, deletion, creation, or restoration of specific files (and all files in specific folders).

Parameters
  • callback (function) – elicited whenever file events are detected, requires at least (name, info) arguments. Event specific callback requires (name, info, event) arguments, where event is on of: ‘modified’, ‘deleted’ (or None), ‘created’, ‘restored’, ‘original’ The ‘original’ event corresponds to a state change that results in the original file info at instantiation.

  • files (list, optional) – List of specific files to watch. A single file can be specified as a string (default None).

  • folders (list, optional) – List of specific folders to watch. A single folder can be specified as a string (default None). If a file is created/deleted in/from any watched folder, it is added/ removed to/from the FileWatcher.files attribute.

  • clean_modified_info (dict, optional) – File info to detect modification/restoration with respect to. If None (default), or for files not present in clean_modified_info, the initial modified info will be based on the first polling of files.

  • hashable_types (iterable, optional) – File extensions for which MD5 checksum will be used to detect modification/restoration with (default None). Files of any other type will be watched using their modified time. Restoration cannot be detected for types not in hashable_types.

  • interval (float, optional) – Polling interval in seconds (default 1).

Methods

__init__(callback[, files, folders, …])

Detect modification, deletion, creation, or restoration of specific files (and all files in specific folders).

add_file(path)

add_files(files[, clean_modified_info])

add_folder(folder)

add_folders(folders[, clean_modified_info])

check([trigger_callback])

get_clean_modified_info()

get_modified_info()

get_modified_times()

mainloop()

stop()

update_files([folders, trigger_callback, …])

Refresh the watchlist of files (FileWatcher.files) by checking the folders kwarg or Filewatcher.folders if this is not specified.

add_file(path)[source]
add_files(files, clean_modified_info=None)[source]
add_folder(folder)[source]
add_folders(folders, clean_modified_info=None)[source]
check(trigger_callback=True)[source]
get_clean_modified_info()[source]
get_modified_info()[source]
get_modified_times()[source]
mainloop()[source]
stop()[source]
update_files(folders=None, trigger_callback=True, recursive=True)[source]

Refresh the watchlist of files (FileWatcher.files) by checking the folders kwarg or Filewatcher.folders if this is not specified.