本文整理匯總了Python中watchdog.events.FileSystemEventHandler方法的典型用法代碼示例。如果您正苦於以下問題:Python events.FileSystemEventHandler方法的具體用法?Python events.FileSystemEventHandler怎麽用?Python events.FileSystemEventHandler使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類watchdog.events
的用法示例。
在下文中一共展示了events.FileSystemEventHandler方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from watchdog import events [as 別名]
# 或者: from watchdog.events import FileSystemEventHandler [as 別名]
def __init__(self, *args, **kwargs):
ReloaderLoop.__init__(self, *args, **kwargs)
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
self.observable_paths = set()
def _check_modification(filename):
if filename in self.extra_files:
self.trigger_reload(filename)
dirname = os.path.dirname(filename)
if dirname.startswith(tuple(self.observable_paths)):
if filename.endswith((".pyc", ".pyo", ".py")):
self.trigger_reload(filename)
class _CustomHandler(FileSystemEventHandler):
def on_created(self, event):
_check_modification(event.src_path)
def on_modified(self, event):
_check_modification(event.src_path)
def on_moved(self, event):
_check_modification(event.src_path)
_check_modification(event.dest_path)
def on_deleted(self, event):
_check_modification(event.src_path)
reloader_name = Observer.__name__.lower()
if reloader_name.endswith("observer"):
reloader_name = reloader_name[:-8]
reloader_name += " reloader"
self.name = reloader_name
self.observer_class = Observer
self.event_handler = _CustomHandler()
self.should_reload = False
示例2: _watch
# 需要導入模塊: from watchdog import events [as 別名]
# 或者: from watchdog.events import FileSystemEventHandler [as 別名]
def _watch(root='.', dest='_site', pattern='**/*.html', exclude='_*/**'):
try:
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
except ImportError:
msg = "The build --watch feature requires watchdog. \n"\
+ "Please install it with 'easy_install watchdog'."
print(msg)
return None
class handler(FileSystemEventHandler):
def on_any_event(self, event):
exclude_path = os.path.join(os.getcwd(), exclude)
if not utils.matches_pattern(exclude_path, event.src_path):
build_files(root=root,
dest=dest,
pattern=pattern,
exclude=exclude)
observer = Observer()
observer.schedule(handler(), root, recursive=True)
observer.start()
print("Watching '{0}' ...".format(root))
return observer
示例3: __init__
# 需要導入模塊: from watchdog import events [as 別名]
# 或者: from watchdog.events import FileSystemEventHandler [as 別名]
def __init__(self, overlay_folder, mount_dir, max_filesize, use_revisions):
super(FileSystemEventHandler, self).__init__()
self.overlay_folder = overlay_folder
self.mount_dir = mount_dir
self.max_filesize = max_filesize
self.use_revisions = use_revisions
示例4: __init__
# 需要導入模塊: from watchdog import events [as 別名]
# 或者: from watchdog.events import FileSystemEventHandler [as 別名]
def __init__(self, *args, **kwargs):
ReloaderLoop.__init__(self, *args, **kwargs)
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
self.observable_paths = set()
def _check_modification(filename):
if filename in self.extra_files:
self.trigger_reload(filename)
dirname = os.path.dirname(filename)
if dirname.startswith(tuple(self.observable_paths)):
if filename.endswith(('.pyc', '.pyo')):
self.trigger_reload(filename[:-1])
elif filename.endswith('.py'):
self.trigger_reload(filename)
class _CustomHandler(FileSystemEventHandler):
def on_created(self, event):
_check_modification(event.src_path)
def on_modified(self, event):
_check_modification(event.src_path)
def on_moved(self, event):
_check_modification(event.src_path)
_check_modification(event.dest_path)
def on_deleted(self, event):
_check_modification(event.src_path)
reloader_name = Observer.__name__.lower()
if reloader_name.endswith('observer'):
reloader_name = reloader_name[:-8]
reloader_name += ' reloader'
self.name = reloader_name
self.observer_class = Observer
self.event_handler = _CustomHandler()
self.should_reload = False
示例5: __init__
# 需要導入模塊: from watchdog import events [as 別名]
# 或者: from watchdog.events import FileSystemEventHandler [as 別名]
def __init__(self, *args, **kwargs):
ReloaderLoop.__init__(self, *args, **kwargs)
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
self.observable_paths = set()
def _check_modification(filename):
if filename in self.extra_files:
self.trigger_reload(filename)
dirname = os.path.dirname(filename)
if dirname.startswith(tuple(self.observable_paths)):
if filename.endswith(('.pyc', '.pyo', '.py')):
self.trigger_reload(filename)
class _CustomHandler(FileSystemEventHandler):
def on_created(self, event):
_check_modification(event.src_path)
def on_modified(self, event):
_check_modification(event.src_path)
def on_moved(self, event):
_check_modification(event.src_path)
_check_modification(event.dest_path)
def on_deleted(self, event):
_check_modification(event.src_path)
reloader_name = Observer.__name__.lower()
if reloader_name.endswith('observer'):
reloader_name = reloader_name[:-8]
reloader_name += ' reloader'
self.name = reloader_name
self.observer_class = Observer
self.event_handler = _CustomHandler()
self.should_reload = False
示例6: __init__
# 需要導入模塊: from watchdog import events [as 別名]
# 或者: from watchdog.events import FileSystemEventHandler [as 別名]
def __init__(self, *args, **kwargs):
ReloaderLoop.__init__(self, *args, **kwargs)
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
self.observable_paths = set()
def _check_modification(filename):
if filename in self.extra_files:
self.trigger_reload(filename)
dirname = os.path.dirname(filename)
if dirname.startswith(tuple(self.observable_paths)):
if filename.endswith(('.pyc', '.pyo')):
self.trigger_reload(filename[:-1])
elif filename.endswith('.py'):
self.trigger_reload(filename)
class _CustomHandler(FileSystemEventHandler):
def on_created(self, event):
_check_modification(event.src_path)
def on_modified(self, event):
_check_modification(event.src_path)
reloader_name = Observer.__name__.lower()
if reloader_name.endswith('observer'):
reloader_name = reloader_name[:-8]
reloader_name += ' reloader'
self.name = reloader_name
self.observer_class = Observer
self.event_handler = _CustomHandler()
self.should_reload = False
示例7: start_daemon
# 需要導入模塊: from watchdog import events [as 別名]
# 或者: from watchdog.events import FileSystemEventHandler [as 別名]
def start_daemon(cls):
""" Start the watchdog observer thread.
"""
if cls.observer is None:
cls.observer = Observer()
cls.monitor = FileSystemEventHandler()
if not cls.observer.is_alive():
cls.observer.start()
示例8: log
# 需要導入模塊: from watchdog import events [as 別名]
# 或者: from watchdog.events import FileSystemEventHandler [as 別名]
def log(s):
print('[Monitor] %s' % s)
# 自定義的文件係統事件處理器,從watchdog.events.FileSystemEventHandler中繼承
示例9: __init__
# 需要導入模塊: from watchdog import events [as 別名]
# 或者: from watchdog.events import FileSystemEventHandler [as 別名]
def __init__(self, params):
self.file_types_whitelist = params.file_types
self.indexers = {}
# Build a list of indexers which correspond to the given file types
programming_languages = set()
for file_type in self.file_types_whitelist:
programming_languages.add(file_type_to_programming_language(file_type))
for programming_language in programming_languages:
self.indexers[programming_language] = SourceCodeIndexerFactory.getIndexer(programming_language, params)
# Setup the filesystem event monitoring
self.event_handler = FileSystemEventHandler(self)
self.observer = Observer()
self.observer.daemon = True
self.observer.schedule(self.event_handler, params.proj_root_directory, recursive=True)
# Print some debug information
logging.info("File extension whitelist: {0}".format(self.file_types_whitelist))
logging.info("Active indexers:")
for prog_language in programming_languages:
logging.info("For [{0}] programming language:".format(prog_language))
indexers = self.indexers[prog_language]
if indexers:
for indexer in indexers:
logging.info("\t\t {0}".format(indexer))
示例10: doc_watch
# 需要導入模塊: from watchdog import events [as 別名]
# 或者: from watchdog.events import FileSystemEventHandler [as 別名]
def doc_watch():
"""Watch for changes in the docs and rebuild HTML docs when changed."""
try:
from watchdog.events import FileSystemEventHandler
from watchdog.observers import Observer
except ImportError:
print_failure_message('Install the watchdog package to use this task, '
"i.e., `pip install watchdog'.")
raise SystemExit(1)
class RebuildDocsEventHandler(FileSystemEventHandler):
def __init__(self, base_paths):
self.base_paths = base_paths
def dispatch(self, event):
"""Dispatches events to the appropriate methods.
:param event: The event object representing the file system event.
:type event: :class:`watchdog.events.FileSystemEvent`
"""
for base_path in self.base_paths:
if event.src_path.endswith(base_path):
super(RebuildDocsEventHandler, self).dispatch(event)
# We found one that matches. We're done.
return
def on_modified(self, event):
print_failure_message('Modification detected. Rebuilding docs.')
# # Strip off the path prefix.
# import os
# if event.src_path[len(os.getcwd()) + 1:].startswith(
# CODE_DIRECTORY):
# # sphinx-build doesn't always pick up changes on code files,
# # even though they are used to generate the documentation. As
# # a workaround, just clean before building.
doc_html()
print_success_message('Docs have been rebuilt.')
print_success_message(
'Watching for changes in project files, press Ctrl-C to cancel...')
handler = RebuildDocsEventHandler(get_project_files())
observer = Observer()
observer.schedule(handler, path='.', recursive=True)
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()