Yeah, look at what is being done in salt/modules/apt.py.