Skip to content

Instantly share code, notes, and snippets.

@evilkost
Created November 18, 2014 14:30
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 evilkost/125bde890722bec64956 to your computer and use it in GitHub Desktop.
Save evilkost/125bde890722bec64956 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import os
from time import sleep
import plumbum as pb
import plumbum.cli as cli
from plumbum.cmd import inotifywait
EVENTS = ["CREATE", "CLOSE_WRITE", "DELETE",
"MODIFY", "MOVED_FROM", "MOVED_TO"]
class App(cli.Application):
def __init__(self,*args, **kwargs):
super(App, self).__init__(*args, **kwargs)
self.watched_location = None
@cli.switch(["-l", "--location"], str)
def location(self, location):
self.watched_location = location
def main(self, on_change):
cmd = inotifywait[
"-r", "--format", "'%:e %f'",
"-e", "{}".format(",".join(EVENTS)),
self.watched_location or "."
]
while True:
print(" Overwatch! ")
stdout = cmd()
os.system(on_change)
if __name__ == "__main__":
App.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment