decided to drop this here in case someone needs it.
“command allow compacting/expanding of selected rules.
multiple selections are supported.
commands are applied to rules which are covered by selection
if there’s a single empty selection then the command is applied to all rules within the document”
you can locate it here https://gist.github.com/2863474
comments and advices are appreciated since those were my first python lines.