def download_url_to_cache(url, cache, force=False): """Take a URL and downloads it to a local cache.""" cache_path = os.path.join(cache, urllib2.unquote(getURLitemBasename(url))) custom_headers = [''] if BASIC_AUTH: # custom_headers = ['Authorization: Basic %s' % BASIC_AUTH] custom_headers = BASIC_AUTH if force: return getResourceIfChangedAtomically( url, cache_path, custom_headers=custom_headers, resume=True, expected_hash='no') return getResourceIfChangedAtomically( url, cache_path, custom_headers=custom_headers)
def download_url_to_cache(url, cache, force=False): """Take a URL and downloads it to a local cache.""" cache_path = os.path.join(cache, urllib2.unquote(getURLitemBasename(url))) custom_headers = [''] if BASIC_AUTH: # custom_headers = ['Authorization: Basic %s' % BASIC_AUTH] custom_headers = BASIC_AUTH if force: return getResourceIfChangedAtomically(url, cache_path, custom_headers=custom_headers, resume=True, expected_hash='no') return getResourceIfChangedAtomically(url, cache_path, custom_headers=custom_headers)
def download_icons(item_list, icon_dir): """Download icons for items in the list. Based on updatecheck.py, modified. Copied from https://github.com/munki/munki/blob/master/code/client/munkilib/updatecheck.py#L2824 Attempts to download icons (actually png files) for items in item_list """ icon_list = [] icon_known_exts = [ '.bmp', '.gif', '.icns', '.jpg', '.jpeg', '.png', '.psd', '.tga', '.tif', '.tiff', '.yuv' ] icon_base_url = (pref('IconURL') or pref('SoftwareRepoURL') + '/icons/') icon_base_url = icon_base_url.rstrip('/') + '/' for item in item_list: icon_name = item.get('icon_name') or item['name'] pkginfo_icon_hash = item.get('icon_hash') if not os.path.splitext(icon_name)[1] in icon_known_exts: icon_name += '.png' icon_list.append(icon_name) icon_url = icon_base_url + urllib2.quote(icon_name.encode('UTF-8')) icon_path = os.path.join(icon_dir, icon_name) if os.path.isfile(icon_path): xattr_hash = getxattr(icon_path, XATTR_SHA) if not xattr_hash: xattr_hash = getsha256hash(icon_path) writeCachedChecksum(icon_path, xattr_hash) else: xattr_hash = 'nonexistent' icon_subdir = os.path.dirname(icon_path) if not os.path.exists(icon_subdir): try: os.makedirs(icon_subdir, 0755) except OSError, err: print 'Could not create %s' % icon_subdir continue custom_headers = [''] if BASIC_AUTH: # custom_headers = ['Authorization: Basic %s' % BASIC_AUTH] custom_headers = BASIC_AUTH if pkginfo_icon_hash != xattr_hash: item_name = item.get('display_name') or item['name'] message = 'Getting icon %s for %s...' % (icon_name, item_name) try: dummy_value = getResourceIfChangedAtomically( icon_url, icon_path, custom_headers=custom_headers, message=message) except MunkiDownloadError, err: print('Could not retrieve icon %s from the server: %s', icon_name, err) else: if os.path.isfile(icon_path): writeCachedChecksum(icon_path)
def download_icons(item_list, icon_dir): """Download icons for items in the list. Based on updatecheck.py, modified. Copied from https://github.com/munki/munki/blob/master/code/client/munkilib/updatecheck.py#L2824 Attempts to download icons (actually png files) for items in item_list """ icon_list = [] icon_known_exts = ['.bmp', '.gif', '.icns', '.jpg', '.jpeg', '.png', '.psd', '.tga', '.tif', '.tiff', '.yuv'] icon_base_url = (pref('IconURL') or pref('SoftwareRepoURL') + '/icons/') icon_base_url = icon_base_url.rstrip('/') + '/' for item in item_list: icon_name = item.get('icon_name') or item['name'] pkginfo_icon_hash = item.get('icon_hash') if not os.path.splitext(icon_name)[1] in icon_known_exts: icon_name += '.png' icon_list.append(icon_name) icon_url = icon_base_url + urllib2.quote(icon_name.encode('UTF-8')) icon_path = os.path.join(icon_dir, icon_name) if os.path.isfile(icon_path): xattr_hash = getxattr(icon_path, XATTR_SHA) if not xattr_hash: xattr_hash = getsha256hash(icon_path) writeCachedChecksum(icon_path, xattr_hash) else: xattr_hash = 'nonexistent' icon_subdir = os.path.dirname(icon_path) if not os.path.exists(icon_subdir): try: os.makedirs(icon_subdir, 0755) except OSError, err: print 'Could not create %s' % icon_subdir continue custom_headers = [''] if BASIC_AUTH: # custom_headers = ['Authorization: Basic %s' % BASIC_AUTH] custom_headers = BASIC_AUTH if pkginfo_icon_hash != xattr_hash: item_name = item.get('display_name') or item['name'] message = 'Getting icon %s for %s...' % (icon_name, item_name) try: dummy_value = getResourceIfChangedAtomically( icon_url, icon_path, custom_headers=custom_headers, message=message) except MunkiDownloadError, err: print ('Could not retrieve icon %s from the server: %s', icon_name, err) else: if os.path.isfile(icon_path): writeCachedChecksum(icon_path)