Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added event_time attr to the FileSystemEvent for more accurate timing… #748

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/watchdog/events.py
Expand Up @@ -94,6 +94,9 @@
import re
from watchdog.utils.patterns import match_any_paths

from datetime import datetime
# System time as in iso format.
iso_time = lambda: datetime.isoformat(datetime.now())

EVENT_TYPE_MOVED = 'moved'
EVENT_TYPE_DELETED = 'deleted'
Expand Down Expand Up @@ -127,6 +130,14 @@ class FileSystemEvent:

def __init__(self, src_path):
self._src_path = src_path
self._event_time = iso_time() # Time when the object was created

@property
def event_time(self):
""" The time FileSystemEvent object was created, rather than
the time FileSystemEventHandler is run. Which is always
different due to blocking."""
return self._event_time #> ie 2021-01-19T12:34:44.772505

@property
def src_path(self):
Expand All @@ -139,17 +150,19 @@ def __str__(self):
def __repr__(self):
return ("<%(class_name)s: event_type=%(event_type)s, "
"src_path=%(src_path)r, "
"is_directory=%(is_directory)s>"
"is_directory=%(is_directory)s, "
"event_time=%(event_time)s> "
) % (dict(
class_name=self.__class__.__name__,
event_type=self.event_type,
src_path=self.src_path,
is_directory=self.is_directory))
is_directory=self.is_directory,
event_time=self.event_time))

# Used for comparison of events.
@property
def key(self):
return (self.event_type, self.src_path, self.is_directory)
return (self.event_type, self.src_path, self.is_directory, self.event_time)

def __eq__(self, event):
return self.key == event.key
Expand Down