Good question, and I have an answer for you, although not a python one, but it looks like you would be fine with just getting it done somehow.
Ok, so first you select all your layers. The shortcut to doing this is clicking on the first one, holding SHIFT, and then clicking on the last one. After that you click on one of the plusses/minusses while you're holding CTRL and all of your layers will expand/collapse.