def download_installeritem(item_pl, installinfo, uninstalling=False):

    download_item_key = 'installer_item_location'
    item_hash_key = 'installer_item_hash'
    if uninstalling and 'uninstaller_item_location' in item_pl:
        download_item_key = 'uninstaller_item_location'
        item_hash_key = 'uninstaller_item_hash'

    location = item_pl.get(download_item_key)
    if not location:
        raise fetch.MunkiDownloadError(
            "No %s in item info." % download_item_key)

    # allow pkginfo preferences to override system munki preferences
    downloadbaseurl = item_pl.get('PackageCompleteURL') or \
                      item_pl.get('PackageURL') or \
                      munkicommon.pref('PackageURL') or \
                      munkicommon.pref('SoftwareRepoURL') + '/pkgs/'

    # build a URL, quoting the the location to encode reserved characters
    if item_pl.get('PackageCompleteURL'):
        pkgurl = downloadbaseurl
    else:
        if not downloadbaseurl.endswith('/'):
            downloadbaseurl = downloadbaseurl + '/'
        pkgurl = downloadbaseurl + urllib2.quote(location.encode('UTF-8'))

    pkgname = getInstallerItemBasename(location)
    munkicommon.display_debug2('Download base URL is: %s', downloadbaseurl)
    munkicommon.display_debug2('Package name is: %s', pkgname)
    munkicommon.display_debug2('Download URL is: %s', pkgurl)

    ManagedInstallDir = munkicommon.pref('ManagedInstallDir')
    mycachedir = os.path.join(ManagedInstallDir, 'Cache')
    destinationpath = getDownloadCachePath(mycachedir, location)
    munkicommon.display_debug2('Downloading to: %s', destinationpath)

    munkicommon.display_detail('Downloading %s from %s', pkgname, location)

    if not os.path.exists(destinationpath):
        # check to see if there is enough free space to download and install
        if not enoughDiskSpace(item_pl, installinfo['managed_installs'],
                               uninstalling=uninstalling):
            raise fetch.MunkiDownloadError(
                'Insufficient disk space to download and install %s' % pkgname)
        else:
            munkicommon.display_detail(
                'Downloading %s from %s', pkgname, location)

    dl_message = 'Downloading %s...' % pkgname
    expected_hash = item_pl.get(item_hash_key, None)
    try:
        return getResourceIfChangedAtomically(pkgurl, destinationpath,
                                              resume=True,
                                              message=dl_message,
                                              expected_hash=expected_hash,
                                              verify=True)
    except fetch.MunkiDownloadError:
        raise
Downloads an (un)installer item.
dataset/ETHPy150Open munki/munki/code/client/munkilib/updatecheck.py/download_installeritem