本文整理匯總了Python中pyinotify.ProcessEvent方法的典型用法代碼示例。如果您正苦於以下問題:Python pyinotify.ProcessEvent方法的具體用法?Python pyinotify.ProcessEvent怎麽用?Python pyinotify.ProcessEvent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pyinotify
的用法示例。
在下文中一共展示了pyinotify.ProcessEvent方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _loop_linux
# 需要導入模塊: import pyinotify [as 別名]
# 或者: from pyinotify import ProcessEvent [as 別名]
def _loop_linux(self, loop_callback):
"""loop implementation for linux platform"""
import pyinotify
handler = self._handle
class EventHandler(pyinotify.ProcessEvent):
def process_default(self, event):
handler(event)
watch_manager = pyinotify.WatchManager()
event_handler = EventHandler()
notifier = pyinotify.Notifier(watch_manager, event_handler)
mask = pyinotify.IN_CLOSE_WRITE | pyinotify.IN_MOVED_TO
for watch_this in self.watch_dirs:
watch_manager.add_watch(watch_this, mask)
notifier.loop(loop_callback)
示例2: watch
# 需要導入模塊: import pyinotify [as 別名]
# 或者: from pyinotify import ProcessEvent [as 別名]
def watch(parent_id=None, mount=False):
"Watch a folder for new torrents to add"
if parent_id == None:
parent_id = app.config.get('PUTIO_ROOT', 0)
if mount and not os.path.exists(app.config['TORRENTS']):
subprocess.call([
'mount',
'-a'
])
add()
class EventHandler(pyinotify.ProcessEvent):
"Event handler for responding to a new or updated torrent file"
def process_IN_CLOSE_WRITE(self, event):
"Do the above"
app.logger.debug('adding torrent, received event: %s' % event)
transfer = app.client.Transfer.add_torrent(event.pathname, parent_id=parent_id)
os.unlink(event.pathname)
app.logger.info('added transfer: %s' % transfer)
watch_manager = pyinotify.WatchManager()
mask = pyinotify.IN_CLOSE_WRITE
handler = EventHandler()
notifier = pyinotify.Notifier(watch_manager, handler)
wdd = watch_manager.add_watch(app.config['TORRENTS'], mask, rec=True)
app.logger.debug('added watch: %s' % wdd)
notifier.loop()
示例3: code_changed
# 需要導入模塊: import pyinotify [as 別名]
# 或者: from pyinotify import ProcessEvent [as 別名]
def code_changed(self):
notify_mask = (
pyinotify.IN_MODIFY |
pyinotify.IN_DELETE |
pyinotify.IN_ATTRIB |
pyinotify.IN_MOVED_FROM |
pyinotify.IN_MOVED_TO |
pyinotify.IN_CREATE |
pyinotify.IN_DELETE_SELF |
pyinotify.IN_MOVE_SELF
)
class EventHandler(pyinotify.ProcessEvent):
def process_default(self, event):
pass
watch_manager = pyinotify.WatchManager()
self.notifier = pyinotify.Notifier(watch_manager, EventHandler())
file_names = self.get_watch_file_names(only_new=True)
for file_name in file_names:
watch_manager.add_watch(file_name, notify_mask)
self.notifier.check_events(timeout=None)
if self.watching:
self.notifier.read_events()
self.notifier.process_events()
self.notifier.stop()
self.notifier = None
# If we are here, then one or more files must have changed
return True
return False
示例4: inotify_code_changed
# 需要導入模塊: import pyinotify [as 別名]
# 或者: from pyinotify import ProcessEvent [as 別名]
def inotify_code_changed():
"""
Checks for changed code using inotify. After being called
it blocks until a change event has been fired.
"""
class EventHandler(pyinotify.ProcessEvent):
modified_code = None
def process_default(self, event):
if event.path.endswith('.mo'):
EventHandler.modified_code = I18N_MODIFIED
else:
EventHandler.modified_code = FILE_MODIFIED
wm = pyinotify.WatchManager()
notifier = pyinotify.Notifier(wm, EventHandler())
def update_watch(sender=None, **kwargs):
if sender and getattr(sender, 'handles_files', False):
# No need to update watches when request serves files.
# (sender is supposed to be a django.core.handlers.BaseHandler subclass)
return
mask = (
pyinotify.IN_MODIFY |
pyinotify.IN_DELETE |
pyinotify.IN_ATTRIB |
pyinotify.IN_MOVED_FROM |
pyinotify.IN_MOVED_TO |
pyinotify.IN_CREATE |
pyinotify.IN_DELETE_SELF |
pyinotify.IN_MOVE_SELF
)
for path in gen_filenames(only_new=True):
wm.add_watch(path, mask)
# New modules may get imported when a request is processed.
request_finished.connect(update_watch)
# Block until an event happens.
update_watch()
notifier.check_events(timeout=None)
notifier.read_events()
notifier.process_events()
notifier.stop()
# If we are here the code must have changed.
return EventHandler.modified_code
示例5: inotify_code_changed
# 需要導入模塊: import pyinotify [as 別名]
# 或者: from pyinotify import ProcessEvent [as 別名]
def inotify_code_changed():
"""
Check for changed code using inotify. After being called
it blocks until a change event has been fired.
"""
class EventHandler(pyinotify.ProcessEvent):
modified_code = None
def process_default(self, event):
if event.path.endswith('.mo'):
EventHandler.modified_code = I18N_MODIFIED
else:
EventHandler.modified_code = FILE_MODIFIED
wm = pyinotify.WatchManager()
notifier = pyinotify.Notifier(wm, EventHandler())
def update_watch(sender=None, **kwargs):
if sender and getattr(sender, 'handles_files', False):
# No need to update watches when request serves files.
# (sender is supposed to be a django.core.handlers.BaseHandler subclass)
return
mask = (
pyinotify.IN_MODIFY |
pyinotify.IN_DELETE |
pyinotify.IN_ATTRIB |
pyinotify.IN_MOVED_FROM |
pyinotify.IN_MOVED_TO |
pyinotify.IN_CREATE |
pyinotify.IN_DELETE_SELF |
pyinotify.IN_MOVE_SELF
)
for path in gen_filenames(only_new=True):
wm.add_watch(path, mask)
# New modules may get imported when a request is processed.
request_finished.connect(update_watch)
# Block until an event happens.
update_watch()
notifier.check_events(timeout=None)
notifier.read_events()
notifier.process_events()
notifier.stop()
# If we are here the code must have changed.
return EventHandler.modified_code