Ejemplo n.º 1
0
def file_watcher(stop):
    import sys, os
    from fsmonitor import FSMonitor

    m = FSMonitor()
    m.add_dir_watch('.')

    while True:
        for evt in m.read_events():
            stop.set()
            print "%s %s %s" % (evt.action_name, evt.watch.path, evt.name)
Ejemplo n.º 2
0
def monitor( directory ):
    """Monitor the given directory for changes.  When a new feed file
    arrives, perform the format and push operations.

    The config identifies specific filenames to be watched in the given
    directory.

    The ``'"capture" : { "extract_filename": "hrtrtf.txt", }'`` file
    is specifically targeted as the source for a feed.

    :param source: The file name to monitor for changes.
    :param config: A global configuration as read by :func:`get_config`.
    """
    m = FSMonitor()
    watch= m.add_dir_watch( directory )
    filename= settings.capture_extract_filename
    try:
        while True:
            for evt in m.read_events():
                if evt.action_name in ( "modify", "create", "move to" ) and evt.name == filename:
                    source= os.path.join( directory, filename )
                    mtime, size= os.path.getmtime(source), os.path.getsize(source)
                    dt= datetime.datetime.fromtimestamp(mtime)
                    logger.info( "Event: {0.action_name} {0.name}: {1}, {2}".format(evt, dt, size) )
                    format_push( source )
                else:
                    logger.debug( "Ignoring {0.action_name} {0.path}/{0.name}".format( evt ) )
    except (SystemExit, KeyboardInterrupt) as ex:
        pass
Ejemplo n.º 3
0
    def start(self):
        m = FSMonitor()
        if type(self.folder_to_watch) == list:  # meh
            [m.add_dir_watch(f) for f in self.folder_to_watch]
        else:
            m.add_dir_watch(self.folder_to_watch)

        while True:
            for evt in m.read_events():
                #print "action_name: %s, evt.watch.path: %s, evt.name: %s" % (
                        #evt.action_name, evt.watch.path, evt.name)
                if evt.action_name == 'create':
                    self.notify_observers(created_files=
                            os.path.join(evt.watch.path, evt.name))
                elif evt.action_name == 'attrib':
                    self.notify_observers(attribd_files=
                            os.path.join(evt.watch.path, evt.name))
Ejemplo n.º 4
0
#!/usr/bin/env python

import sys, os
sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
from fsmonitor import FSMonitor

if len(sys.argv) < 2:
    print "usage: dirwatch.py [DIRS...]"
    sys.exit(1)

m = FSMonitor()
for arg in sys.argv[1:]:
    m.add_dir_watch(arg)

while True:
    for evt in m.read_events():
        print "%s %s %s" % (evt.action_name, evt.watch.path, evt.name)
Ejemplo n.º 5
0
#!/usr/bin/env python

import sys, os
sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
from fsmonitor import FSMonitor

if len(sys.argv) < 2:
    print "usage: dirwatch.py [DIRS...]"
    sys.exit(1)

m = FSMonitor()
for arg in sys.argv[1:]:
    m.add_dir_watch(arg)

while True:
    for evt in m.read_events():
        print "%s %s %s" % (evt.action_name, evt.watch.path, evt.name)
Ejemplo n.º 6
0
    # Grab a random post message
    postmsg = choice(POST_MESSAGES)

    try:
        photo = photo = open(fullFilePath, 'rb')
        t.update_status_with_media(status=postmsg, media=photo)
    except Exception, msg:
        print msg

    # Once the image has been posted we can remove it (twitter is the archive)
    print "Post created, removing local image..."
    os.remove(fullFilePath)


######## MAIN #########

# Images are captured and placed in the "captures" directory as the
# camera.py script detects movement.  We monitor the "captures"
# directory for new files and process when detected.
m = FSMonitor()
watch = m.add_dir_watch(CAMERA_CAPTURES_DIR)

while True:
    for evt in m.read_events():
        # The FSMonitor evt.action_name we care about is "move to" (the file
        # is created in another dir and moved as a whole)
        # Note: the evt.name will be the name of the new file
        if evt.action_name == 'move to':
            time.sleep(10)  # Let the full file be written before continuing...
            postNewMessage(evt.name)