Created
March 26, 2015 15:01
-
-
Save autrilla/ce19a05cd18fc1a4a7f9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# SETTINGS | |
# Tuple of tuples of directories to be watched and corresponding AWS S3 bucket | |
watch_directories = ( | |
('/home/autrilla/Documents/Scripts/test/', 's3://test/'), | |
) | |
aws_sqs_url = 'https://sqs.eu-west-1.amazonaws.com/198042352723/FAVEGASync' | |
sqs_update_interval = 1 | |
# ---------------------------------------------------------------------------- | |
try: | |
import boto3 | |
import pyinotify | |
except ImportError: | |
print("FAVEGASync requires twisted and boto3") | |
exit(1) | |
handled_messages = list() | |
class EventHandler(pyinotify.ProcessEvent): | |
def process_IN_DELETE(self, event): | |
for directory in watch_directories: | |
if directory[0] in event.pathname: | |
handled_messages.append(queue.send_message("DELETE " + | |
directory[1] + event.pathname | |
.replace(directory[0], "")))[ | |
'MessageId'] | |
def process_IN_CLOSE_WRITE(self, event): | |
for directory in watch_directories: | |
if directory[0] in event.pathname: | |
handled_messages.append(queue.send_message("WRITE " + | |
directory[1] + event.pathname | |
.replace(directory[0], "")))[ | |
'MessageId'] | |
sqs = boto3.resource('sqs') | |
queue = boto3.resource('sqs').Queue(aws_sqs_url) | |
wm = pyinotify.WatchManager() | |
notifier = pyinotify.Notifier(wm, EventHandler()) | |
for directory in watch_directories: | |
wm.add_watch(directory[0], | |
pyinotify.IN_CLOSE_WRITE | pyinotify.IN_DELETE, rec=True) | |
notifier.loop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment