Exemplo n.º 1
0
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
Exemplo n.º 2
0
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
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)
Exemplo n.º 4
0
def main(): 
    fd = _inotify.create()
    wd = _inotify.add(fd, "cat", _inotify.ALL_EVENTS) 
    ep = select.epoll()
    ep.register(fd, select.EPOLLIN) 
    fcntl.fcntl(fd, fcntl.F_SETFL, os.O_NONBLOCK)
    while True:
        try:
            do_poll(ep)
        except Exception as e:
            print e
            break 
    ep.close()
    os.close(fd)
Exemplo n.º 5
0
def main():
    fd = _inotify.create()
    wd = _inotify.add(fd, "cat", _inotify.ALL_EVENTS)
    ep = select.epoll()
    ep.register(fd, select.EPOLLIN)
    fcntl.fcntl(fd, fcntl.F_SETFL, os.O_NONBLOCK)
    while True:
        try:
            do_poll(ep)
        except Exception as e:
            print e
            break
    ep.close()
    os.close(fd)
Exemplo n.º 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
Exemplo n.º 7
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