'Fetch the package from one its URLs and save it in dest_dir.
If the the package already exists in dest_dir and the checksum
matches this code will not fetch it again.
Sets the \'verified_package\' attribute with the destination pathname.
:param dest_dir - The destination directory to save the local file.
If it does not exist it will be created.
:return: A boolean indicating if we the package is now in dest_dir.
:raise FetchError - When something unexpected happens.'

def fetch(self, dest_dir):

    if (not os.path.exists(dest_dir)):
        os.makedirs(dest_dir)
    local_path = os.path.join(dest_dir, self.local_filename)
    if os.path.exists(local_path):
        actual_hex_sum = _checksum_file(local_path)
        if (self.hex_sum == actual_hex_sum):
            logging.info('Good    checksum    for    existing    %s    package.', self.name)
            self.verified_package = local_path
            return True
        logging.warning('Bad    checksum    for    existing    %s    package.        Re-downloading', self.name)
        os.rename(local_path, (local_path + '.wrong-checksum'))
    for url in self.urls:
        logging.info('Fetching    %s', url)
        try:
            url_file = urllib2.urlopen(url)
        except (urllib2.URLError, EnvironmentError):
            logging.warning('Could    not    fetch    %s    package    from    %s.', self.name, url)
            continue
        data_length = int(url_file.info().get('Content-Length', _MAX_PACKAGE_SIZE))
        if ((data_length <= 0) or (data_length > _MAX_PACKAGE_SIZE)):
            raise FetchError(('%s    from    %s    fails    Content-Length    %d    sanity    check.' % (self.name, url, data_length)))
        checksum = utils.hash('sha1')
        total_read = 0
        output = open(local_path, 'wb')
        try:
            while (total_read < data_length):
                data = url_file.read(_READ_SIZE)
                if (not data):
                    break
                output.write(data)
                checksum.update(data)
                total_read += len(data)
        finally:
            output.close()
        if (self.hex_sum != checksum.hexdigest()):
            logging.warning('Bad    checksum    for    %s    fetched    from    %s.', self.name, url)
            logging.warning('Got    %s', checksum.hexdigest())
            logging.warning('Expected    %s', self.hex_sum)
            os.unlink(local_path)
            continue
        logging.info('Good    checksum.')
        self.verified_package = local_path
        return True
    else:
        return False
