'Convert the sessionconfig.pickle file to triblerd.conf. Do nothing if we do not have a pickle file.
Remove the pickle file after we are done.'

def convert_session_config(self):

    old_filename = os.path.join(self.session.config.get_state_dir(), 'sessconfig.pickle')
    if (not os.path.exists(old_filename)):
        return
    with open(old_filename, 'rb') as old_file:
        sessconfig = pickle.load(old_file)
    new_config = self.session.config
    for (key, value) in sessconfig.iteritems():
        if (key == 'minport'):
            new_config.config['libtorrent']['port'] = value
        if (key in ['state_dir', 'install_dir', 'eckeypairfilename', 'megacache', 'videoanalyserpath']):
            new_config.config['general'][key] = value
        if (key == 'mainline_dht'):
            new_config.config['mainline_dht']['enabled'] = value
        if (key == 'mainline_dht_port'):
            new_config.config['mainline_dht']['port'] = value
        if (key == 'torrent_checking'):
            new_config.config['torrent_checking']['enabled'] = value
        if (key in ['torrent_collecting', 'torrent_collecting_max_torrents', 'torrent_collecting_dir']):
            new_config.config['torrent_collecting'][('enabled' if (key == 'torrent_collecting') else key)] = value
        if (key in ['libtorrent', 'lt_proxytype', 'lt_proxyserver', 'lt_proxyauth']):
            new_config.config['libtorrent'][('enabled' if (key == 'libtorrent') else key)] = value
        if (key in ['dispersy_port', 'dispersy']):
            new_config.config['dispersy'][('enabled' if (key == 'dispersy') else 'port')] = value
    new_config.write()
    os.remove(old_filename)
