Resync with the sugar-build implementation of tree.py

Development continued there for a while. Now I will remove it
and used the toolkit implementation instead.

Changes:

* Retry faster
* Handle GLib errors
* Don't always dump the tree
* Support master atspi api