Example #1
0
    def run_test_command(self, cmd):
        observer = FSEventsObserver()
        shared_queue = Queue.Queue()
        handler = ChangeHandler(shared_queue)
        observer.schedule(handler, self.temp_dir)
        observer.start()

        args = ['./webnull.py'] + cmd
        env = os.environ.copy()
        if 'DEV_MODE' in env:
            del env['DEV_MODE']
        env['HOSTFILE_PATH'] = self.hostfile_path
        env['TEST_DURATION'] = '0.02'
        process = subprocess.Popen(args, env=env)
        process.wait()
        time.sleep(
            .09
        )  # if we just quit, the observer doesn't see the final file action.

        bodies = []
        while not shared_queue.empty():
            bodies.append(shared_queue.get())

        observer.stop()
        observer.join()
        return bodies
def initiate_download(PDF,download_folder):
	file_location = download_folder
	global check
	check = 0
	time_passed = 0
	observer = Observer()
	event_handler = MyEventHandler(observer)
	observer.schedule(event_handler, file_location)
	observer.start()
	PDF.click()
	while(check == 0):
		time.sleep(1) # wait for download signal
		time_passed += 1
		if(time_passed > 10):
			observer.stop()
			observer.join()
			return -1
	observer.stop()
	observer.join()
	return 0
def initiate_download(PDF, download_folder):
    file_location = download_folder
    global check
    check = 0
    time_passed = 0
    observer = Observer()
    event_handler = MyEventHandler(observer)
    observer.schedule(event_handler, file_location)
    observer.start()
    PDF.click()
    while (check == 0):
        time.sleep(1)  # wait for download signal
        time_passed += 1
        if (time_passed > 10):
            observer.stop()
            observer.join()
            return -1
    observer.stop()
    observer.join()
    return 0
Example #4
0
# git clone git://github.com/gorakhargosh/watchdog.git
# cd watchdog
# python setup.py install

# watchmedo log --debug-force-fsevents --patterns="*.py;*.txt" --ignore-directories --recursive ~/

#!/usr/bin/python
import time
#from watchdog.observers import Observer
from watchdog.observers.fsevents import FSEventsObserver as Observer
from watchdog.events import FileSystemEventHandler


class MyHandler(FileSystemEventHandler):
    def on_modified(self, event):
        print(f'event type: {event.event_type}  path : {event.src_path}')


if __name__ == "__main__":
    event_handler = MyHandler()
    observer = Observer()
    observer.schedule(event_handler, path='/data/', recursive=False)
    observer.start()

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