1/12/2014

How you can use watchdog to improve your productivity.

Watchdog is a python API and shell utilities to monitor file system events.

I am using it for tasks like build sphinx docs or run tests after changes in file/directory. It's very easy to use.

For instance, you are writing documentation and after each saving file you have to run command like "make html". So, why you don't this automatically?
 
Simple command:
watchmedo shell-command --command="make html" --wait source
What does it? Watchdog began to watch source directory. If something in this directory will be changed, then watchdog will run your command (make html). Simply, right?

If you use Firefox you can install Auto Reload add-on. Auto Reload automatically reloads matching tabs when selected local files change. So, after saving file, your documentation will build automatically and Firefox automatically will refresh tab with documentation in browser, brilliant!

You can also use patterns. For example, you want to run tests after saving file:
watchmedo shell-command --wait --patterns="*.py" \
--command='py.test "${watch_src_path}"' \
--recursive your_project/tests/

# or shorter version
watchmedo shell-command --w -p="*.py" \
-c='py.test "${watch_src_path}"' -R your_project/tests/ 
You will find documentation here. I hope this post will be useful ;)