Michael280
Michael280

Reputation: 48

Run Python script when Directory is updated

I have a script which i want to execute when specific directory is updated. To be more specific: development team have 4 directories (lets say "a", "b", "c" and "d") which they update from time to time. I have a script which take as a parameter name of directory. I wan to execute this script with parameter "a" when directory "a" is updated. Is it Possible to do with Jenkins? If so, can I do same thing using SVN?

Upvotes: 1

Views: 553

Answers (1)

Vinayak Kolagi
Vinayak Kolagi

Reputation: 1881

You can do that using python itself, with watchdog library.

from watchdog.observers import Observer  
from watchdog.events import PatternMatchingEventHandler 

class FileHandler(PatternMatchingEventHandler):
    def process(self, event):
        print event.src_path, event.event_type  # print now only for degug

    def on_modified(self, event):
        self.process(event)

    def on_created(self, event):
        self.process(event)

if __name__ == '__main__':
    args = sys.argv[1:]
    observer = Observer()
    observer.schedule(MyHandler(), path=args[0] if args else '.')
    observer.start()

    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        observer.stop()

    observer.join()

Upvotes: 2

Related Questions