Skip to content

Instantly share code, notes, and snippets.

@marioidival
Created May 15, 2013 11: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 marioidival/5583319 to your computer and use it in GitHub Desktop.
Save marioidival/5583319 to your computer and use it in GitHub Desktop.
import os
import shutil
import itertools
import pyinotify
DIR_VERIFY = '/var/log/'
DIR_DESTINY = '/home/suporte/'
def get_root(find_file):
for root, direc, files in os.walk(DIR_VERIFY):
for fil in files:
if fil == find_file:
yield root
class MyEvent(pyinotify.ProcessEvent):
def process_IN_CREATE(self, event):
slash_file = event.pathname.split("/")
file_name = slash_file[3]
root_file = get_root(file_name)
shutil.move("%s %s" %(root_file.next(), file_name), DIR_DESTINY)
def main():
wm = pyinotify.WatchManager()
wm.add_watch(DIR_VERIFY, pyinotify.ALL_EVENTS, rec=True)
eh = MyEvent()
notifier = pyinotify.Notifier(wm, eh)
notifier.loop()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment