'Create BT torrent file by reading the files added with
add_content() and calculate the torrent file\'s infohash.
Creating the torrent file can take a long time and will be carried out
by the calling thread. The process can be made interruptable by passing
a threading.Event() object via the userabortflag and setting it when
the process should be aborted. The also optional userprogresscallback
will be called by the calling thread periodically, with a progress
percentage as argument.
The userprogresscallback function will be called by the calling thread.
@param userabortflag threading.Event() object
@param userprogresscallback Function accepting a fraction as first
argument.'

def finalize(self, userabortflag=None, userprogresscallback=None):

    if self.metainfo_valid:
        return
    (infohash, metainfo) = maketorrent.make_torrent_file(self.input, userabortflag=userabortflag, userprogresscallback=userprogresscallback)
    if (infohash is not None):
        self.infohash = infohash
        self.metainfo = metainfo
        self.input['name'] = metainfo['info']['name']
        self.input['piece    length'] = metainfo['info']['piece    length']
        self.metainfo_valid = True
    assert ((self.infohash is None) or isinstance(self.infohash, str)), ('INFOHASH    has    invalid    type:    %s' % type(self.infohash))
    assert ((self.infohash is None) or (len(self.infohash) == INFOHASH_LENGTH)), ('INFOHASH    has    invalid    length:    %d' % len(self.infohash))
