Last active
August 29, 2015 14:23
-
-
Save s1lvester/c33937c10f6db9ffdc83 to your computer and use it in GitHub Desktop.
Jolla Photouploader. Requires pyinotify (pyhton3)
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
#!/usr/bin/env python | |
""" | |
jolla-photoupload | |
@license: MIT Licence | |
@contact: s1lvester@bockhacker.me | |
""" | |
import pyinotify | |
import os | |
directorytowatch = "/home/nemo/Pictures/Camera" | |
command = "rsync -ruvP --delete-after " + directorytowatch + " server:~/owncloud/Incoming/" | |
# Which Events to watch | |
mask = pyinotify.IN_DELETE | pyinotify.IN_MODIFY | pyinotify.IN_CREATE | |
# Create an Eventhandler | |
class EventHandler(pyinotify.ProcessEvent): | |
def make(self): | |
os.system(command) | |
def process_IN_DELETE(self, event): | |
print("Writing", event.pathname) | |
self.make() | |
def process_IN_MODIFY(self, event): | |
print("Removing", event.pathname) | |
self.make() | |
def process_IN_CREATE(self, event): | |
print("Removing", event.pathname) | |
self.make() | |
wm = pyinotify.WatchManager() | |
handler = EventHandler() | |
notifyer = pyinotify.Notifier(wm, handler) | |
# Create the watch (RECursive = true, AUTO_ADD newly created directories) | |
wm.add_watch(directorytowatch, mask, rec=True, auto_add=True) | |
# initial sync after script-init | |
os.system(command) | |
# Start the daemon | |
notifyer.loop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment