The US Department of Justice has reached a settlement with General David Petraeus allowing the former military leader and ex-head of the CIA to avoid prison for handing over classified information to his lover.