コード例 #1
0
ファイル: dirmon.py プロジェクト: yoe/veyepar
def main():
    args = parse_args()

    inotify_fd = _inotify.create()
    watch_directory = find_dir(".")
    print("Monitoring: {}".format(watch_directory))

    # we only want events where a file opened for write was
    # closed.
    # wd = _inotify.add(inotify_fd, watch_directory, _inotify.CLOSE_WRITE)

    # plan b: watch for open, look for files that need to be encoded
    # like the on that was just closed.
    # wd = _inotify.add(inotify_fd, watch_directory, _inotify.OPEN)

    # didn't work.  what happens with CLOSE
    # wd = _inotify.add(inotify_fd, watch_directory, _inotify.CLOSE)
    # no good either.  boo.

    wds[wd] = watch_directory
    while True:
        time.sleep(1)  # 1 second
        try:
            _inotify.read_event(inotify_fd, receive_event)
        except OSError as e:
            if e.errno != errno.EAGAIN:
                raise
コード例 #2
0
ファイル: dirmon.py プロジェクト: CarlFK/veyepar
def main():
    args = parse_args()

    inotify_fd = _inotify.create()
    watch_directory = find_dir(".") 
    print("Monitoring: {}".format(watch_directory))

    # we only want events where a file opened for write was
    # closed.
    # wd = _inotify.add(inotify_fd, watch_directory, _inotify.CLOSE_WRITE)

    # plan b: watch for open, look for files that need to be encoded
    # like the on that was just closed.
    # wd = _inotify.add(inotify_fd, watch_directory, _inotify.OPEN)

    # didn't work.  what happens with CLOSE
    # wd = _inotify.add(inotify_fd, watch_directory, _inotify.CLOSE)
    # no good either.  boo.
   
    wds[wd] = watch_directory
    while True:
        time.sleep(1) # 1 second
        try:
            _inotify.read_event(inotify_fd, receive_event)
        except OSError as e:
            if e.errno != errno.EAGAIN:
                raise
コード例 #3
0
def do_poll(ep): 
    for fd, event in ep.poll(1): 
        while True:
            try:
                _inotify.read_event(fd, callback)
            except OSError as e:
                if e.errno == errno.EAGAIN:
                   break 
コード例 #4
0
def do_poll(ep):
    for fd, event in ep.poll(1):
        while True:
            try:
                _inotify.read_event(fd, callback)
            except OSError as e:
                if e.errno == errno.EAGAIN:
                    break
コード例 #5
0
def mainloop():
    fd = _inotify.create()
    wddir = _inotify.add(fd, ROOTDIR, _inotify.CREATE | _inotify.MODIFY)

    todayfile = FILEPREFIX + time.strftime("%Y%m%d")
    # todayfile = "apsched20131221"
    lf = Logfile(FILEPREFIX, ROOTDIR, todayfile)

    while True:
    # blocking wait
        _inotify.read_event(fd, lf.action)
        time.sleep(0.1)
コード例 #6
0
    if mask & _inotify.ACCESS:
        on_read(event)
    elif mask & _inotify.MODIFY:
        on_write(event)
    elif mask & _inotify.ATTRIB:
        on_attrib(event)
    elif mask & _inotify.OPEN:
        on_open(event)
    elif mask & _inotify.CLOSE:
        on_close(event)
    elif mask & _inotify.MOVE:
        on_move(event)
    elif mask & _inotify.DELETE_SELF:
        on_delete_self(event)
    elif mask & _inotify.DELETE:
        on_delete(event)
    elif mask & _inotify.CREATE:
        on_create(event)


fd = _inotify.create()
wd = _inotify.add(fd, "example", _inotify.ALL_EVENTS)

while True:
    time.sleep(0.5)
    try:
        _inotify.read_event(fd, response)
    except OSError as e:
        if e.errno == errno.EAGAIN:
            pass
コード例 #7
0
ファイル: watchfile.py プロジェクト: deanyou/python_inotify
            _inotify.MOVE_SELF: "Watched file/directory was itself moved",
            _inotify.MOVED_FROM: "File moved out of watched directory",
            _inotify.MOVED_TO: "File moved into watched directory",
            _inotify.OPEN: "File was opened",
            _inotify.IGNORED: "Watch was removed explictily",
            _inotify.ISDIR: "Subject of this event is a directory",
            _inotify.Q_OVERFLOW: "Event queue overflowed",
            _inotify.UNMOUNT: "File system containing watched object was unmounted",
            _inotify.IGNORED: "Watch was removed explictly or automatically",
            _inotify.ISDIR: "Subject of this event is a directory",
            _inotify.Q_OVERFLOW: "Event queue overflowed",
            _inotify.UNMOUNT: "File system containing watched object was unmounted"
    } 
            
    def callback(event): 
        mask = event["mask"]
        for k, v in consts.items():
            if mask & k: 
                print("%s: %s" % (target, v)) 

    fd = _inotify.create()
    wd = _inotify.add(fd, target, _inotify.ALL_EVENTS)
    while True:
        time.sleep(0.1)
        try:
            _inotify.read_event(fd, callback) 
        except OSError as e:
            if e.errno == errno.EAGAIN:
                pass
        
コード例 #8
0
#! /usr/bin/env python
import os
import time
import _inotify


def rev(event):
    print event


fd = _inotify.create()
wd = _inotify.add(fd, "test", _inotify.ALL_EVENTS)

while True:
    time.sleep(0.5)
    _inotify.read_event(fd, rev_event)
コード例 #9
0
        _inotify.MOVE_SELF: "Watched file/directory was itself moved",
        _inotify.MOVED_FROM: "File moved out of watched directory",
        _inotify.MOVED_TO: "File moved into watched directory",
        _inotify.OPEN: "File was opened",
        _inotify.IGNORED: "Watch was removed explictily",
        _inotify.ISDIR: "Subject of this event is a directory",
        _inotify.Q_OVERFLOW: "Event queue overflowed",
        _inotify.UNMOUNT:
        "File system containing watched object was unmounted",
        _inotify.IGNORED: "Watch was removed explictly or automatically",
        _inotify.ISDIR: "Subject of this event is a directory",
        _inotify.Q_OVERFLOW: "Event queue overflowed",
        _inotify.UNMOUNT: "File system containing watched object was unmounted"
    }

    def callback(event):
        mask = event["mask"]
        for k, v in consts.items():
            if mask & k:
                print("%s: %s" % (target, v))

    fd = _inotify.create()
    wd = _inotify.add(fd, target, _inotify.ALL_EVENTS)
    while True:
        time.sleep(0.1)
        try:
            _inotify.read_event(fd, callback)
        except OSError as e:
            if e.errno == errno.EAGAIN:
                pass
コード例 #10
0
ファイル: test.py プロジェクト: deanyou/python_inotify
#! /usr/bin/env python
import os 
import time
import _inotify 

def rev(event):
    print event

fd = _inotify.create()
wd = _inotify.add(fd, "test", _inotify.ALL_EVENTS);

while True:
    time.sleep(0.5)
    _inotify.read_event(fd, rev_event)

コード例 #11
0
def response(event): 
    mask = event['mask']
    if mask & _inotify.ACCESS:
        on_read(event)
    elif mask & _inotify.MODIFY:
        on_write(event)
    elif mask & _inotify.ATTRIB:
        on_attrib(event)
    elif mask & _inotify.OPEN:
        on_open(event)
    elif mask & _inotify.CLOSE:
        on_close(event) 
    elif mask & _inotify.MOVE:
        on_move(event)
    elif mask & _inotify.DELETE_SELF:
        on_delete_self(event)
    elif mask & _inotify.DELETE:
        on_delete(event)
    elif mask & _inotify.CREATE:
        on_create(event)
    

fd = _inotify.create()
wd = _inotify.add(fd, "example", _inotify.ALL_EVENTS) 

while True:
    time.sleep(0.5)
    _inotify.read_event(fd, response)