Skip to content

Instantly share code, notes, and snippets.

@s1lvester
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save s1lvester/c33937c10f6db9ffdc83 to your computer and use it in GitHub Desktop.
Save s1lvester/c33937c10f6db9ffdc83 to your computer and use it in GitHub Desktop.
Jolla Photouploader. Requires pyinotify (pyhton3)
#!/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