Fixes to enable an import of the watchdog module
This commit is contained in:
parent
750cf953da
commit
ac4b6fc7b5
14 changed files with 111 additions and 46 deletions
|
@ -88,7 +88,7 @@ Event Handler Classes
|
|||
import os.path
|
||||
import logging
|
||||
import re
|
||||
from watchdog.utils.patterns import match_any_paths
|
||||
from .utils.patterns import match_any_paths
|
||||
|
||||
|
||||
EVENT_TYPE_MOVED = 'moved'
|
||||
|
|
|
@ -54,8 +54,8 @@ Class Platforms Note
|
|||
"""
|
||||
|
||||
import warnings
|
||||
from watchdog.utils import platform
|
||||
from watchdog.utils import UnsupportedLibc
|
||||
from ..utils import platform
|
||||
from ..utils import UnsupportedLibc
|
||||
|
||||
if platform.is_linux():
|
||||
try:
|
||||
|
|
|
@ -19,8 +19,8 @@ import queue
|
|||
import threading
|
||||
from pathlib import Path
|
||||
|
||||
from watchdog.utils import BaseThread
|
||||
from watchdog.utils.bricks import SkipRepeatsQueue
|
||||
from ..utils import BaseThread
|
||||
from ..utils.bricks import SkipRepeatsQueue
|
||||
|
||||
DEFAULT_EMITTER_TIMEOUT = 1 # in seconds.
|
||||
DEFAULT_OBSERVER_TIMEOUT = 1 # in seconds.
|
||||
|
|
|
@ -28,7 +28,7 @@ import threading
|
|||
import unicodedata
|
||||
import _watchdog_fsevents as _fsevents
|
||||
|
||||
from watchdog.events import (
|
||||
from ..events import (
|
||||
FileDeletedEvent,
|
||||
FileModifiedEvent,
|
||||
FileCreatedEvent,
|
||||
|
@ -39,7 +39,7 @@ from watchdog.events import (
|
|||
DirMovedEvent
|
||||
)
|
||||
|
||||
from watchdog.observers.api import (
|
||||
from .api import (
|
||||
BaseObserver,
|
||||
EventEmitter,
|
||||
DEFAULT_EMITTER_TIMEOUT,
|
||||
|
|
|
@ -26,7 +26,7 @@ import queue
|
|||
import unicodedata
|
||||
from threading import Thread
|
||||
|
||||
from watchdog.events import (
|
||||
from ..events import (
|
||||
FileDeletedEvent,
|
||||
FileModifiedEvent,
|
||||
FileCreatedEvent,
|
||||
|
@ -36,7 +36,7 @@ from watchdog.events import (
|
|||
DirCreatedEvent,
|
||||
DirMovedEvent
|
||||
)
|
||||
from watchdog.observers.api import (
|
||||
from .api import (
|
||||
BaseObserver,
|
||||
EventEmitter,
|
||||
DEFAULT_EMITTER_TIMEOUT,
|
||||
|
|
|
@ -70,14 +70,14 @@ import os
|
|||
import threading
|
||||
from .inotify_buffer import InotifyBuffer
|
||||
|
||||
from watchdog.observers.api import (
|
||||
from .api import (
|
||||
EventEmitter,
|
||||
BaseObserver,
|
||||
DEFAULT_EMITTER_TIMEOUT,
|
||||
DEFAULT_OBSERVER_TIMEOUT
|
||||
)
|
||||
|
||||
from watchdog.events import (
|
||||
from ..events import (
|
||||
DirDeletedEvent,
|
||||
DirModifiedEvent,
|
||||
DirMovedEvent,
|
||||
|
|
|
@ -15,9 +15,9 @@
|
|||
# limitations under the License.
|
||||
|
||||
import logging
|
||||
from watchdog.utils import BaseThread
|
||||
from watchdog.utils.delayed_queue import DelayedQueue
|
||||
from watchdog.observers.inotify_c import Inotify
|
||||
from ..utils import BaseThread
|
||||
from ..utils.delayed_queue import DelayedQueue
|
||||
from .inotify_c import Inotify
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ import ctypes
|
|||
import ctypes.util
|
||||
from functools import reduce
|
||||
from ctypes import c_int, c_char_p, c_uint32
|
||||
from watchdog.utils import UnsupportedLibc
|
||||
from ..utils import UnsupportedLibc
|
||||
|
||||
|
||||
def _load_libc():
|
||||
|
|
|
@ -67,7 +67,7 @@ Collections and Utility Classes
|
|||
|
||||
"""
|
||||
|
||||
from watchdog.utils import platform
|
||||
from ..utils import platform
|
||||
|
||||
import threading
|
||||
import errno
|
||||
|
@ -78,16 +78,16 @@ import select
|
|||
|
||||
from pathlib import Path
|
||||
|
||||
from watchdog.observers.api import (
|
||||
from .api import (
|
||||
BaseObserver,
|
||||
EventEmitter,
|
||||
DEFAULT_OBSERVER_TIMEOUT,
|
||||
DEFAULT_EMITTER_TIMEOUT
|
||||
)
|
||||
|
||||
from watchdog.utils.dirsnapshot import DirectorySnapshot
|
||||
from ..utils.dirsnapshot import DirectorySnapshot
|
||||
|
||||
from watchdog.events import (
|
||||
from ..events import (
|
||||
DirMovedEvent,
|
||||
DirDeletedEvent,
|
||||
DirCreatedEvent,
|
||||
|
|
|
@ -38,15 +38,15 @@ import os
|
|||
import threading
|
||||
from functools import partial
|
||||
|
||||
from watchdog.utils.dirsnapshot import DirectorySnapshot, DirectorySnapshotDiff
|
||||
from watchdog.observers.api import (
|
||||
from ..utils.dirsnapshot import DirectorySnapshot, DirectorySnapshotDiff
|
||||
from .api import (
|
||||
EventEmitter,
|
||||
BaseObserver,
|
||||
DEFAULT_OBSERVER_TIMEOUT,
|
||||
DEFAULT_EMITTER_TIMEOUT
|
||||
)
|
||||
|
||||
from watchdog.events import (
|
||||
from ..events import (
|
||||
DirMovedEvent,
|
||||
DirDeletedEvent,
|
||||
DirCreatedEvent,
|
||||
|
|
|
@ -20,7 +20,7 @@ import threading
|
|||
import os.path
|
||||
import time
|
||||
|
||||
from watchdog.events import (
|
||||
from ..events import (
|
||||
DirCreatedEvent,
|
||||
DirDeletedEvent,
|
||||
DirMovedEvent,
|
||||
|
@ -33,14 +33,14 @@ from watchdog.events import (
|
|||
generate_sub_created_events,
|
||||
)
|
||||
|
||||
from watchdog.observers.api import (
|
||||
from api import (
|
||||
EventEmitter,
|
||||
BaseObserver,
|
||||
DEFAULT_OBSERVER_TIMEOUT,
|
||||
DEFAULT_EMITTER_TIMEOUT
|
||||
)
|
||||
|
||||
from watchdog.observers.winapi import (
|
||||
from winapi import (
|
||||
read_events,
|
||||
get_directory_handle,
|
||||
close_directory_handle,
|
||||
|
|
|
@ -46,8 +46,8 @@ import signal
|
|||
import subprocess
|
||||
import time
|
||||
|
||||
from watchdog.utils import echo
|
||||
from watchdog.events import PatternMatchingEventHandler
|
||||
from ..utils import echo
|
||||
from ..events import PatternMatchingEventHandler
|
||||
|
||||
|
||||
class Trick(PatternMatchingEventHandler):
|
||||
|
|
|
@ -35,7 +35,6 @@ Classes
|
|||
.. autoclass:: OrderedSet
|
||||
|
||||
"""
|
||||
|
||||
import queue
|
||||
|
||||
|
||||
|
@ -100,3 +99,69 @@ class SkipRepeatsQueue(queue.Queue):
|
|||
if item is self._last_item:
|
||||
self._last_item = None
|
||||
return item
|
||||
|
||||
|
||||
class OrderedSetQueue(queue.Queue):
|
||||
|
||||
"""Thread-safe implementation of an ordered set queue.
|
||||
|
||||
Disallows adding a duplicate item while maintaining the
|
||||
order of items in the queue. The implementation leverages
|
||||
locking already implemented in the base class
|
||||
redefining only the primitives. Since the internal queue
|
||||
is not replaced, the order is maintained. The set is used
|
||||
merely to check for the existence of an item.
|
||||
|
||||
Queued items must be immutable and hashable so that they can be used
|
||||
as dictionary keys. You must implement **only read-only properties** and
|
||||
the :meth:`Item.__hash__()`, :meth:`Item.__eq__()`, and
|
||||
:meth:`Item.__ne__()` methods for items to be hashable.
|
||||
|
||||
An example implementation follows::
|
||||
|
||||
class Item(object):
|
||||
def __init__(self, a, b):
|
||||
self._a = a
|
||||
self._b = b
|
||||
|
||||
@property
|
||||
def a(self):
|
||||
return self._a
|
||||
|
||||
@property
|
||||
def b(self):
|
||||
return self._b
|
||||
|
||||
def _key(self):
|
||||
return (self._a, self._b)
|
||||
|
||||
def __eq__(self, item):
|
||||
return self._key() == item._key()
|
||||
|
||||
def __ne__(self, item):
|
||||
return self._key() != item._key()
|
||||
|
||||
def __hash__(self):
|
||||
return hash(self._key())
|
||||
|
||||
:author: lalinsky@gmail.com (Lukáš Lalinský)
|
||||
:url: http://stackoverflow.com/questions/1581895/how-check-if-a-task-is-already-in-python-queue
|
||||
"""
|
||||
|
||||
def _init(self, maxsize):
|
||||
queue.Queue._init(self, maxsize)
|
||||
self._set_of_items = set()
|
||||
|
||||
def _put(self, item):
|
||||
if item not in self._set_of_items:
|
||||
queue.Queue._put(self, item)
|
||||
self._set_of_items.add(item)
|
||||
else:
|
||||
# `put` increments `unfinished_tasks` even if we did not put
|
||||
# anything into the queue here
|
||||
self.unfinished_tasks -= 1
|
||||
|
||||
def _get(self):
|
||||
item = queue.Queue._get(self)
|
||||
self._set_of_items.remove(item)
|
||||
return item
|
||||
|
|
|
@ -32,8 +32,8 @@ import logging
|
|||
from io import StringIO
|
||||
|
||||
from argh import arg, aliases, ArghParser, expects_obj
|
||||
from watchdog.version import VERSION_STRING
|
||||
from watchdog.utils import WatchdogShutdown, load_class
|
||||
from .version import VERSION_STRING
|
||||
from .utils import WatchdogShutdown, load_class
|
||||
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
@ -162,7 +162,7 @@ def tricks_from(args):
|
|||
:param args:
|
||||
Command line argument options.
|
||||
"""
|
||||
from watchdog.observers import Observer
|
||||
from .observers import Observer
|
||||
|
||||
add_to_sys_path(path_split(args.python_path))
|
||||
observers = []
|
||||
|
@ -312,8 +312,8 @@ def log(args):
|
|||
:param args:
|
||||
Command line argument options.
|
||||
"""
|
||||
from watchdog.utils import echo
|
||||
from watchdog.tricks import LoggerTrick
|
||||
from .utils import echo
|
||||
from .tricks import LoggerTrick
|
||||
|
||||
if args.trace:
|
||||
echo.echo_class(LoggerTrick)
|
||||
|
@ -324,23 +324,23 @@ def log(args):
|
|||
ignore_patterns=ignore_patterns,
|
||||
ignore_directories=args.ignore_directories)
|
||||
if args.debug_force_polling:
|
||||
from watchdog.observers.polling import PollingObserver as Observer
|
||||
from .observers.polling import PollingObserver as Observer
|
||||
elif args.debug_force_kqueue:
|
||||
from watchdog.observers.kqueue import KqueueObserver as Observer
|
||||
from .observers.kqueue import KqueueObserver as Observer
|
||||
elif args.debug_force_winapi_async:
|
||||
from watchdog.observers.read_directory_changes_async import\
|
||||
from .observers.read_directory_changes_async import\
|
||||
WindowsApiAsyncObserver as Observer
|
||||
elif args.debug_force_winapi:
|
||||
from watchdog.observers.read_directory_changes import\
|
||||
from .observers.read_directory_changes import\
|
||||
WindowsApiObserver as Observer
|
||||
elif args.debug_force_inotify:
|
||||
from watchdog.observers.inotify import InotifyObserver as Observer
|
||||
from .observers.inotify import InotifyObserver as Observer
|
||||
elif args.debug_force_fsevents:
|
||||
from watchdog.observers.fsevents import FSEventsObserver as Observer
|
||||
from .observers.fsevents import FSEventsObserver as Observer
|
||||
else:
|
||||
# Automatically picks the most appropriate observer for the platform
|
||||
# on which it is running.
|
||||
from watchdog.observers import Observer
|
||||
from .observers import Observer
|
||||
observer = Observer(timeout=args.timeout)
|
||||
observe_with(observer, handler, args.directories, args.recursive)
|
||||
|
||||
|
@ -420,15 +420,15 @@ def shell_command(args):
|
|||
:param args:
|
||||
Command line argument options.
|
||||
"""
|
||||
from watchdog.tricks import ShellCommandTrick
|
||||
from .tricks import ShellCommandTrick
|
||||
|
||||
if not args.command:
|
||||
args.command = None
|
||||
|
||||
if args.debug_force_polling:
|
||||
from watchdog.observers.polling import PollingObserver as Observer
|
||||
from .observers.polling import PollingObserver as Observer
|
||||
else:
|
||||
from watchdog.observers import Observer
|
||||
from .observers import Observer
|
||||
|
||||
patterns, ignore_patterns = parse_patterns(args.patterns,
|
||||
args.ignore_patterns)
|
||||
|
@ -510,11 +510,11 @@ def auto_restart(args):
|
|||
"""
|
||||
|
||||
if args.debug_force_polling:
|
||||
from watchdog.observers.polling import PollingObserver as Observer
|
||||
from .observers.polling import PollingObserver as Observer
|
||||
else:
|
||||
from watchdog.observers import Observer
|
||||
from .observers import Observer
|
||||
|
||||
from watchdog.tricks import AutoRestartTrick
|
||||
from .tricks import AutoRestartTrick
|
||||
import signal
|
||||
|
||||
if not args.directories:
|
||||
|
|
Loading…
Reference in a new issue