__init__.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # Copyright 2011 Yesudeep Mangalapilly <yesudeep@gmail.com>
  5. # Copyright 2012 Google, Inc.
  6. #
  7. # Licensed under the Apache License, Version 2.0 (the "License");
  8. # you may not use this file except in compliance with the License.
  9. # You may obtain a copy of the License at
  10. #
  11. # http://www.apache.org/licenses/LICENSE-2.0
  12. #
  13. # Unless required by applicable law or agreed to in writing, software
  14. # distributed under the License is distributed on an "AS IS" BASIS,
  15. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. # See the License for the specific language governing permissions and
  17. # limitations under the License.
  18. """
  19. :module: watchdog.observers
  20. :synopsis: Observer that picks a native implementation if available.
  21. :author: yesudeep@google.com (Yesudeep Mangalapilly)
  22. Classes
  23. =======
  24. .. autoclass:: Observer
  25. :members:
  26. :show-inheritance:
  27. :inherited-members:
  28. Observer thread that schedules watching directories and dispatches
  29. calls to event handlers.
  30. You can also import platform specific classes directly and use it instead
  31. of :class:`Observer`. Here is a list of implemented observer classes.:
  32. ============== ================================ ==============================
  33. Class Platforms Note
  34. ============== ================================ ==============================
  35. |Inotify| Linux 2.6.13+ ``inotify(7)`` based observer
  36. |FSEvents| Mac OS X FSEvents based observer
  37. |Kqueue| Mac OS X and BSD with kqueue(2) ``kqueue(2)`` based observer
  38. |WinApi| MS Windows Windows API-based observer
  39. |Polling| Any fallback implementation
  40. ============== ================================ ==============================
  41. .. |Inotify| replace:: :class:`.inotify.InotifyObserver`
  42. .. |FSEvents| replace:: :class:`.fsevents.FSEventsObserver`
  43. .. |Kqueue| replace:: :class:`.kqueue.KqueueObserver`
  44. .. |WinApi| replace:: :class:`.read_directory_changes.WindowsApiObserver`
  45. .. |WinApiAsync| replace:: :class:`.read_directory_changes_async.WindowsApiAsyncObserver`
  46. .. |Polling| replace:: :class:`.polling.PollingObserver`
  47. """
  48. import warnings
  49. from watchdog.utils import platform
  50. from watchdog.utils import UnsupportedLibc
  51. if platform.is_linux():
  52. try:
  53. from .inotify import InotifyObserver as Observer
  54. except UnsupportedLibc:
  55. from .polling import PollingObserver as Observer
  56. elif platform.is_darwin():
  57. try:
  58. from .fsevents import FSEventsObserver as Observer
  59. except Exception:
  60. try:
  61. from .kqueue import KqueueObserver as Observer
  62. warnings.warn("Failed to import fsevents. Fall back to kqueue")
  63. except Exception:
  64. from .polling import PollingObserver as Observer
  65. warnings.warn("Failed to import fsevents and kqueue. Fall back to polling.")
  66. elif platform.is_bsd():
  67. from .kqueue import KqueueObserver as Observer
  68. elif platform.is_windows():
  69. # TODO: find a reliable way of checking Windows version and import
  70. # polling explicitly for Windows XP
  71. try:
  72. from .read_directory_changes import WindowsApiObserver as Observer
  73. except Exception:
  74. from .polling import PollingObserver as Observer
  75. warnings.warn("Failed to import read_directory_changes. Fall back to polling.")
  76. else:
  77. from .polling import PollingObserver as Observer
  78. __all__ = ["Observer"]