Created
November 18, 2014 14:30
-
-
Save evilkost/125bde890722bec64956 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
#!/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