We already have a helper class/module for this. IIRC the yum action uses it.