-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Revert "Initial MacOS Support""
This reverts commit 65d77d3.
- Loading branch information
Showing
12 changed files
with
256 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
__version__ = '0.0.4' | ||
|
||
import platform | ||
|
||
if platform.system() == 'Windows': | ||
from .windows import WatchableFolder, FolderSpy | ||
elif platform.system() == 'Linux': | ||
from .linux import WatchableFolder, FolderSpy | ||
elif platform.system() == 'Darwin': | ||
from .mac import WatchableFolder, FolderSpy | ||
else: | ||
raise Exception('{0} is not a supported.'.format(platform.system())) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = '0.0.3' | ||
__version__ = '0.0.4' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from .folder import WatchableFolder | ||
from .spy import FolderSpy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import os.path | ||
|
||
from fsevents import Stream | ||
from fsevents import IN_MODIFY, IN_ATTRIB, IN_CREATE, IN_DELETE, IN_MOVED_FROM, IN_MOVED_TO | ||
|
||
|
||
class FileEvent(object): | ||
|
||
def __init__(self, full_path, maskname): | ||
self.name = os.path.basename(full_path) | ||
self.pathname = full_path | ||
self.maskname = maskname | ||
|
||
|
||
class WatchableFolder(object): | ||
|
||
MASK_NAMES = { | ||
IN_MODIFY: 'IN_MODIFY', | ||
IN_ATTRIB: 'IN_ATTRIB', | ||
IN_CREATE: 'IN_CREATE', | ||
IN_DELETE: 'IN_DELETE', | ||
IN_MOVED_FROM: 'IN_MOVED_FROM', | ||
IN_MOVED_TO: 'IN_MOVED_TO' | ||
} | ||
|
||
def __init__(self, path='', recursive=False, listen_to=None): | ||
self.path = path | ||
self.recursive = recursive | ||
self.listen_to = listen_to | ||
self.stream = Stream(self._on_event, self.path, file_events=True) | ||
|
||
def _on_event(self, event): | ||
"""Called when any event is triggered.""" | ||
|
||
mask_name = self.MASK_NAMES[event.mask] | ||
|
||
getattr(self, 'process_{0}'.format(mask_name))( | ||
FileEvent(event.name, mask_name) | ||
) | ||
|
||
def process_IN_ATTRIB(self, event): | ||
"""Metadata changed for a file.""" | ||
|
||
def process_IN_CREATE(self, event): | ||
"""A file/directory was created in watched directory.""" | ||
|
||
def process_IN_DELETE(self, event): | ||
"""A file/directory was deleted in watched directory.""" | ||
|
||
def process_IN_MODIFY(self, event): | ||
"""A file was modified.""" | ||
|
||
def process_IN_MOVED_FROM(self, event): | ||
"""A file/directory was moved away from the current watched directory.""" | ||
|
||
def process_IN_MOVED_TO(self, event): | ||
"""A file/directory was moved into the current watched directory.""" |
Oops, something went wrong.