本文整理汇总了Python中watchdog.utils.has_attribute函数的典型用法代码示例。如果您正苦于以下问题:Python has_attribute函数的具体用法?Python has_attribute怎么用?Python has_attribute使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了has_attribute函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: dispatch
def dispatch(self, event):
"""Dispatches events to the appropriate methods.
:param event:
The event object representing the file system event.
:type event:
:class:`FileSystemEvent`
"""
if self.ignore_directories and event.is_directory:
return
if has_attribute(event, 'src_path') and has_attribute(event, 'dest_path'):
paths = [event.src_path, event.dest_path]
elif has_attribute(event, 'src_path'):
paths = [event.src_path]
elif has_attribute(event, 'dest_path'):
paths = [event.dest_path]
else:
paths = []
if match_any_paths(paths,
included_patterns=self.patterns,
excluded_patterns=self.ignore_patterns,
case_sensitive=self.case_sensitive):
self.on_any_event(event)
_method_map = {
EVENT_TYPE_MODIFIED: self.on_modified,
EVENT_TYPE_MOVED: self.on_moved,
EVENT_TYPE_CREATED: self.on_created,
EVENT_TYPE_DELETED: self.on_deleted,
}
event_type = event.event_type
_method_map[event_type](event)
示例2: on_any_event
def on_any_event(self, event):
from string import Template
if self.drop_during_process and self.process and self.process.poll() is None:
return
if event.is_directory:
object_type = 'directory'
else:
object_type = 'file'
context = {
'watch_src_path': event.src_path,
'watch_dest_path': '',
'watch_event_type': event.event_type,
'watch_object': object_type,
}
if self.shell_command is None:
if has_attribute(event, 'dest_path'):
context.update({'dest_path': event.dest_path})
command = 'echo "${watch_event_type} ${watch_object} from ${watch_src_path} to ${watch_dest_path}"'
else:
command = 'echo "${watch_event_type} ${watch_object} ${watch_src_path}"'
else:
if has_attribute(event, 'dest_path'):
context.update({'watch_dest_path': event.dest_path})
command = self.shell_command
command = Template(command).safe_substitute(**context)
self.process = subprocess.Popen(command, shell=True)
if self.wait_for_process:
self.process.wait()
示例3: on_any_event
def on_any_event(self, event):
from string import Template
if event.is_directory:
object_type = "directory"
else:
object_type = "file"
context = {
"watch_src_path": event.src_path,
"watch_dest_path": "",
"watch_event_type": event.event_type,
"watch_object": object_type,
}
if self.shell_command is None:
if has_attribute(event, "dest_path"):
context.update({"dest_path": event.dest_path})
command = 'echo "${watch_event_type} ${watch_object} from ${watch_src_path} to ${watch_dest_path}"'
else:
command = 'echo "${watch_event_type} ${watch_object} ${watch_src_path}"'
else:
if has_attribute(event, "dest_path"):
context.update({"watch_dest_path": event.dest_path})
command = self.shell_command
command = Template(command).safe_substitute(**context)
process = subprocess.Popen(command, shell=True)
if self.wait_for_process:
process.wait()
示例4: get_file_event_paths
def get_file_event_paths(events):
for event in events:
for key in ('dest_path', 'src_path'):
if has_attribute(event, key):
path = unicode_paths.decode(getattr(event, key))
if not (path.startswith('.autocheck.') or os.path.isdir(path)):
yield os.path.relpath(path)
示例5: dispatch
def dispatch(self, event):
"""Dispatches events to the appropriate methods.
:param event:
The event object representing the file system event.
:type event:
:class:`FileSystemEvent`
"""
if self.ignore_directories and event.is_directory:
return
paths = []
if has_attribute(event, 'dest_path'):
paths.append(unicode_paths.decode(event.dest_path))
if event.src_path:
paths.append(unicode_paths.decode(event.src_path))
if any(r.match(p) for r in self.ignore_regexes for p in paths):
return
if any(r.match(p) for r in self.regexes for p in paths):
self.on_any_event(event)
_method_map = {
EVENT_TYPE_MODIFIED: self.on_modified,
EVENT_TYPE_ATTR_MODIFIED: self.on_attr_modified,
EVENT_TYPE_MOVED: self.on_moved,
EVENT_TYPE_CREATED: self.on_created,
EVENT_TYPE_DELETED: self.on_deleted,
}
event_type = event.event_type
_method_map[event_type](event)
示例6: on_any_event
def on_any_event(self, event):
if self.drop_during_process and self.process and self.process.poll() is None:
return
if event.is_directory:
object_type = 'directory'
else:
object_type = 'file'
env = os.environ.copy()
env.update({
'WATCH_SRC_PATH': event.src_path,
'WATCH_EVENT_TYPE': event.event_type,
'WATCH_OBJECT': object_type,
})
if has_attribute(event, 'dest_path'):
env['WATCH_DEST_PATH'] = event.dest_path
if self.shell_command is None:
if 'WATCH_DEST_PATH' in env:
command = 'echo "$WATCH_EVENT_TYPE $WATCH_OBJECT from $WATCH_SRC_PATH to $WATCH_DEST_PATH"'
else:
command = 'echo "$WATCH_EVENT_TYPE $WATCH_OBJECT $WATCH_SRC_PATH"'
else:
command = self.shell_command
self.process = subprocess.Popen(command, shell=True, env=env)
if self.wait_for_process:
self.process.wait()
示例7: assert_patterns
def assert_patterns(event):
if has_attribute(event, 'dest_path'):
paths = [event.src_path, event.dest_path]
else:
paths = [event.src_path]
filtered_paths = filter_paths(paths, patterns, ignore_patterns)
assert_true(filtered_paths)
示例8: dispatch
def dispatch(self, event):
if has_attribute(event, 'dest_path'):
paths = [event.src_path, event.dest_path]
else:
paths = [event.src_path]
if match_any_paths(paths,
included_patterns=self.patterns,
excluded_patterns=self.ignore_patterns):
self.on_any_event(event)
示例9: assert_patterns
def assert_patterns(event):
if has_attribute(event, 'dest_path'):
paths = [event.src_path, event.dest_path]
else:
paths = [event.src_path]
filtered_paths = filter_paths(paths,
included_patterns=patterns,
excluded_patterns=ignore_patterns,
case_sensitive=False)
self.assertTrue(filtered_paths)
示例10: assert_regexes
def assert_regexes(handler, event):
if has_attribute(event, 'dest_path'):
paths = [event.src_path, event.dest_path]
else:
paths = [event.src_path]
filtered_paths = set()
for p in paths:
if any(r.match(p) for r in handler.regexes):
filtered_paths.add(p)
self.assertTrue(filtered_paths)
示例11: assert_patterns
def assert_patterns(event):
if has_attribute(event, 'dest_path'):
paths = [event.src_path, event.dest_path]
else:
paths = [event.src_path]
filtered_paths = filter_paths(
paths,
included_patterns=['*.py', '*.txt'],
excluded_patterns=["*.pyc"],
case_sensitive=False)
assert filtered_paths
示例12: dispatch
def dispatch(self, event):
if self.ignore_directories and event.is_directory:
return
paths = []
if has_attribute(event, 'dest_path'):
paths.append(unicode_paths.decode(event.dest_path))
if event.src_path:
paths.append(unicode_paths.decode(event.src_path))
if match_any_paths(paths, included_patterns=self.patterns, excluded_patterns=self.ignore_patterns, case_sensitive=self.case_sensitive):
self.on_any_event(event)
_method_map = {EVENT_TYPE_MODIFIED: self.on_modified,
EVENT_TYPE_MOVED: self.on_moved,
EVENT_TYPE_CREATED: self.on_created,
EVENT_TYPE_DELETED: self.on_deleted}
event_type = event.event_type
_method_map[event_type](event)
示例13: dispatch
def dispatch(self, event):
try:
paths = [event.src_path]
if has_attribute(event, 'dest_path'):
paths.append(event.dest_path)
paths = [os.path.relpath(os.path.normpath(os.path.abspath(path)), start=self.source_base_path) for path in paths]
event_type_to_name = {EVENT_TYPE_MOVED: "move", EVENT_TYPE_CREATED: "create",
EVENT_TYPE_MODIFIED: "modify", EVENT_TYPE_DELETED: "delete"}
vprint("local change type: {} paths: {}", event_type_to_name[event.event_type], paths)
for path in paths:
pattern = find_matching_pattern(path, self.source_ignore_patterns, match_subpath=True)
if pattern:
vprint("ignoring change for path {}, pattern: {}", path, pattern)
return
self.queue.put(event)
except:
import traceback
traceback.print_exc()
示例14: dispatch
def dispatch(self, event):
"""Only dispatch if the event does not correspond to an ignored file.
Args:
event (watchdog.events.FileSystemEvent)
"""
if event.is_directory:
return
paths = []
if has_attribute(event, 'dest_path'):
paths.append(os.path.realpath(
unicode_paths.decode(event.dest_path)))
if event.src_path:
paths.append(os.path.realpath(
unicode_paths.decode(event.src_path)))
paths = [p for p in paths
if not p.startswith(os.path.realpath(self.vcs.repository_dir()))
and not self.vcs.path_is_ignored(p)]
if len(paths) > 0:
super(VcsEventHandler, self).dispatch(event)
示例15: dispatch
def dispatch(self, event):
"""Dispatch an event after filtering. We handle
creation and move events only.
:param event: watchdog event.
:returns: None
"""
if event.event_type not in (EVENT_TYPE_CREATED, EVENT_TYPE_MOVED):
return
if self.ignore_directories and event.is_directory:
return
paths = []
if has_attribute(event, 'dest_path'):
paths.append(unicode_paths.decode(event.dest_path))
if event.src_path:
paths.append(unicode_paths.decode(event.src_path))
if any(r.match(p) for r in self.ignore_regexes for p in paths):
return
if any(r.match(p) for r in self.regexes for p in paths):
self._loop.call_soon_threadsafe(asyncio.async, self._process_file(event))