mirror of
https://github.com/munki/munki.git
synced 2026-05-06 04:19:35 -05:00
Refectoring of munkilib/appleupdates and removal of unsued code
This commit is contained in:
@@ -279,9 +279,6 @@ class AppleUpdates(object):
|
||||
# No updates found
|
||||
self.applesync.clean_up_cache()
|
||||
return False
|
||||
os_version_tuple = osutils.getOsVersion(as_tuple=True)
|
||||
if os_version_tuple < (10, 11):
|
||||
self.applesync.write_filtered_catalog(product_ids)
|
||||
try:
|
||||
self.applesync.cache_update_metadata(product_ids)
|
||||
except sync.ReplicationError as err:
|
||||
@@ -349,8 +346,7 @@ class AppleUpdates(object):
|
||||
apple_updates = []
|
||||
|
||||
# first, try to get the list from com.apple.SoftwareUpdate preferences
|
||||
recommended_updates = su_prefs.pref(
|
||||
'RecommendedUpdates')
|
||||
recommended_updates = su_prefs.pref('RecommendedUpdates')
|
||||
if recommended_updates:
|
||||
for item in recommended_updates:
|
||||
try:
|
||||
@@ -402,8 +398,7 @@ class AppleUpdates(object):
|
||||
english_dist = self.applesync.distribution_for_product_key(
|
||||
product_key, 'English')
|
||||
if english_dist:
|
||||
english_su_info = dist.parse_su_dist(
|
||||
english_dist)
|
||||
english_su_info = dist.parse_su_dist(english_dist)
|
||||
su_info = dist.parse_su_dist(localized_dist)
|
||||
su_info['productKey'] = product_key
|
||||
if su_info['name'] == '':
|
||||
@@ -415,8 +410,7 @@ class AppleUpdates(object):
|
||||
su_info['apple_product_name'] = (
|
||||
english_su_info['apple_product_name'])
|
||||
if product_key in update_versions:
|
||||
su_info['version_to_install'] = (
|
||||
update_versions[product_key])
|
||||
su_info['version_to_install'] = update_versions[product_key]
|
||||
elif english_su_info:
|
||||
su_info['version_to_install'] = (
|
||||
english_su_info['version_to_install'])
|
||||
@@ -674,11 +668,6 @@ class AppleUpdates(object):
|
||||
# Get list of unattended_installs
|
||||
if only_unattended:
|
||||
msg = 'Installing unattended Apple Software Updates...'
|
||||
# Creating an 'unattended_install' filtered catalog
|
||||
# against the existing filtered catalog is not an option as
|
||||
# cached downloads are purged if they do not exist in the
|
||||
# filtered catalog. Instead, get a list of updates, and their
|
||||
# product_ids, that are eligible for unattended_install.
|
||||
unattended_install_items, unattended_install_product_ids = \
|
||||
self.get_unattended_installs()
|
||||
# ensure that we don't restart for unattended installations
|
||||
@@ -720,7 +709,7 @@ class AppleUpdates(object):
|
||||
# --no-scan option
|
||||
catalog_url = None
|
||||
else:
|
||||
# use our filtered local catalog
|
||||
# use our local catalog
|
||||
if not os.path.exists(self.applesync.local_catalog_path):
|
||||
display.display_error(
|
||||
'Missing local Software Update catalog at %s',
|
||||
@@ -777,12 +766,6 @@ class AppleUpdates(object):
|
||||
if retcode: # there was an error
|
||||
display.display_error('softwareupdate error: %s' % retcode)
|
||||
|
||||
# Refresh Applicable updates and catalogs
|
||||
# since we may have performed some unattended installs
|
||||
if only_unattended:
|
||||
product_ids = self.available_update_product_ids()
|
||||
self.applesync.write_filtered_catalog(product_ids)
|
||||
|
||||
# clean up our now stale local cache
|
||||
if not only_unattended:
|
||||
self.applesync.clean_up_cache()
|
||||
|
||||
@@ -80,11 +80,6 @@ APPLE_DOWNLOAD_CATALOG_NAME = 'apple.sucatalog'
|
||||
# The pristine, untouched, and extracted catalog.
|
||||
APPLE_EXTRACTED_CATALOG_NAME = 'apple_index.sucatalog'
|
||||
|
||||
# The catalog containing only applicable updates
|
||||
# This is used to replicate a subset of the software update
|
||||
# server data to our local cache.
|
||||
FILTERED_CATALOG_NAME = 'filtered_index.sucatalog'
|
||||
|
||||
# The catalog containing only updates to be downloaded and installed.
|
||||
# We use this one when downloading Apple updates.
|
||||
# In this case package URLs are still pointing to the
|
||||
@@ -150,8 +145,6 @@ class AppleUpdateSync(object):
|
||||
self.apple_download_catalog_path = os.path.join(
|
||||
self.temp_cache_dir, APPLE_DOWNLOAD_CATALOG_NAME)
|
||||
|
||||
self.filtered_catalog_path = os.path.join(
|
||||
self.local_catalog_dir, FILTERED_CATALOG_NAME)
|
||||
self.local_catalog_path = os.path.join(
|
||||
self.local_catalog_dir, LOCAL_CATALOG_NAME)
|
||||
self.extracted_catalog_path = os.path.join(
|
||||
@@ -373,7 +366,7 @@ class AppleUpdateSync(object):
|
||||
|
||||
for product_key in product_ids:
|
||||
if processes.stop_requested():
|
||||
break
|
||||
return
|
||||
display.display_status_minor(
|
||||
'Caching metadata for product ID %s', product_key)
|
||||
product = catalog['Products'][product_key]
|
||||
@@ -383,7 +376,7 @@ class AppleUpdateSync(object):
|
||||
|
||||
for package in product.get('Packages', []):
|
||||
if processes.stop_requested():
|
||||
break
|
||||
return
|
||||
if 'MetadataURL' in package:
|
||||
display.display_status_minor(
|
||||
'Caching package metadata for product ID %s',
|
||||
@@ -400,7 +393,7 @@ class AppleUpdateSync(object):
|
||||
distributions = product['Distributions']
|
||||
for dist_lang in distributions.keys():
|
||||
if processes.stop_requested():
|
||||
break
|
||||
return
|
||||
display.display_status_minor(
|
||||
'Caching %s distribution for product ID %s',
|
||||
dist_lang, product_key)
|
||||
@@ -413,9 +406,6 @@ class AppleUpdateSync(object):
|
||||
'Could not cache %s distribution for product ID %s',
|
||||
dist_lang, product_key)
|
||||
|
||||
if processes.stop_requested():
|
||||
return
|
||||
|
||||
if not os.path.exists(self.local_catalog_dir):
|
||||
try:
|
||||
os.makedirs(self.local_catalog_dir)
|
||||
@@ -504,25 +494,10 @@ class AppleUpdateSync(object):
|
||||
'Could not retrieve %s: %s', url, err)
|
||||
return None
|
||||
|
||||
def write_filtered_catalog(self, product_ids):
|
||||
"""Write out a sucatalog containing only the updates in product_ids.
|
||||
|
||||
Args:
|
||||
product_ids: list of str, ProductIDs.
|
||||
catalog_path: str, path of catalog to write.
|
||||
"""
|
||||
catalog = FoundationPlist.readPlist(self.extracted_catalog_path)
|
||||
product_ids = set(product_ids) # convert to set for O(1) lookups.
|
||||
for product_id in list(catalog.get('Products', [])):
|
||||
if product_id not in product_ids:
|
||||
del catalog['Products'][product_id]
|
||||
FoundationPlist.writePlist(catalog, self.filtered_catalog_path)
|
||||
|
||||
def clean_up_cache(self):
|
||||
"""Clean up our cache dir"""
|
||||
content_cache = os.path.join(self.cache_dir, 'content')
|
||||
if os.path.exists(content_cache):
|
||||
# TODO(unassigned): change this to Pythonic delete.
|
||||
dummy_retcode = subprocess.call(['/bin/rm', '-rf', content_cache])
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user