#!bin/python
"""
run this on any machine that could notice files (images or rdf data)
getting written to the pic areas. It would be nice to run this only on
the nfs server, but that's solaris and doesn't have any FAM system
that I'm aware of. So instead I run this on every linux box that might
write to the pic dirs.

todo: there's a bug where if someone makes a dir and writes a file in
it right away, we only send a message about the dir. Annoying!

"""

import boot
from fileschanged import fileschanged
from restkit import Resource
from picdirs import picSubDirs
log = boot.log

syncImportEndpoint = Resource("http://bang:9042/") # should be a PSHB hub

def post(f):
    if f.endswith(('.filepart')):
        return
    syncImportEndpoint.post(
        payload=dict(file=f),
        headers={'Content-Type' : 'application/x-www-form-urlencoded'})

topDirs = picSubDirs()
fileschanged(topDirs, post)
