Welcome to Grigori’s documentation!

Quickstart

Requirements

This module has no requirements. The requirements.dev.txt is for development to the module only and contains packages like Sphinx and setuptools.

Installation

Install the package using the following command.

pip install grigori

Example

The simple example below watches the current directory for any changes, and notifies us of the file and type of the change.

For more detailed usage please see the Usage

from grigori import Watcher

directory = './'

w = Watcher(directory)

for changes in w.watch():
    for change in changes:
        print("file '%s' has been changed in the following way: '%s'" % (change["file"], change["type"]))

Usage

More usage

grigori

grigori package

Submodules

grigori.watcher module

class grigori.watcher.Change[source]

Bases: enum.IntEnum

Simple Enum representing the different types of changes to a file.

ADDED = 1
DELETED = 3
MODIFIED = 2
class grigori.watcher.Watcher(directory: str, recursive: bool = False, polling_interval: int = 1000, file_pattern: str = '.+', directory_pattern: str = '.+', cache: bool = False)[source]

Bases: object

Class that starts watching your files.

on(change_type: grigori.watcher.Change, callback: function) → None[source]

Register a callback function for a type of change.

Parameters:
  • change_type – The type of the change.
  • callback – A function to call when a change of the given type occurs.
wait() → None[source]

Hacky method to use the ‘watch’ method without a ‘for loop’.

watch() → generator[source]

Keep polling for file changes and yield them.

Returns:A generator that yields a list of changes.

Module contents

Basic watcher module.

The grigori module contains two classes:

  • grigori.Change
  • grigori.Watcher

You can use the grigori.Watcher class to create a watcher instance. Then you have the choice if you want to use callbacks or a for loop. To use callbacks, use the grigori.Watcher.wait() method. To use the for loop, use the grigori.Watcher.watch() method.