Fix #2303 : Torrent state not updated until after emitting TorrentFinishedEvent
Cleanup torrentmanger code

 * Remove legacy/old state file code
 * Passes flake8 cleanly
 * Most pylint messages dealt with
 * Code now uses >=Python 2.6 'with' and 'as' statements