Maybe you can use code from the reoback. Reoback have an purge option that works great.
http://sourceforge.net/projects/reoback/ -- Purge option https://launchpad.net/bugs/53349 -- ubuntu-bugs mailing list ubuntu-bugs@lists.ubuntu.com https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs