Added --os option which can specify an OS version, which is different to --version which matches a point release.

This commit is contained in:
grahampugh 2019-03-28 21:20:12 +01:00
parent 75577caa87
commit 0fdcc32967

View File

@ -29,13 +29,11 @@ import gzip
import os import os
import plistlib import plistlib
import subprocess import subprocess
import re
import sys import sys
import urlparse import urlparse
import xattr import xattr
from xml.dom import minidom from xml.dom import minidom
from xml.parsers.expat import ExpatError from xml.parsers.expat import ExpatError
from operator import itemgetter
from distutils.version import LooseVersion from distutils.version import LooseVersion
@ -366,6 +364,7 @@ def get_unsupported_models(filename):
if 'nonSupportedModels' in line: if 'nonSupportedModels' in line:
unsupported_models = line.split(" ")[-1][:-1] unsupported_models = line.split(" ")[-1][:-1]
return unsupported_models return unsupported_models
def download_and_parse_sucatalog(sucatalog, workdir, ignore_cache=False): def download_and_parse_sucatalog(sucatalog, workdir, ignore_cache=False):
'''Downloads and returns a parsed softwareupdate catalog''' '''Downloads and returns a parsed softwareupdate catalog'''
@ -539,8 +538,12 @@ def main():
'for the current device.') 'for the current device.')
parser.add_argument('--version', metavar='match_version', parser.add_argument('--version', metavar='match_version',
default='', default='',
help='Selects the lowest valid build ID matching' help='Selects the lowest valid build ID matching '
'the selected version.') 'the selected version (e.g. 10.14.3).')
parser.add_argument('--os', metavar='match_os',
default='',
help='Selects the lowest valid build ID matching '
'the selected OS version (e.g. 10.14).')
args = parser.parse_args() args = parser.parse_args()
# show this Mac's info # show this Mac's info
@ -618,16 +621,23 @@ def main():
# skip if build is not suitable for current device # skip if build is not suitable for current device
# and a validation parameter was chosen # and a validation parameter was chosen
if not_valid and (args.validate or args.auto or args.version): if not_valid and (args.validate or args.auto or args.version or args.os):
continue continue
# skip if a version is selected and it does not match # skip if a version is selected and it does not match
if args.version and args.version != product_info[product_id]['version']: if args.version and args.version != product_info[product_id]['version']:
continue continue
# skip if a version is selected and it does not match
if args.os:
major = product_info[product_id]['version'].split('.', 2)[:2]
os_version = '.'.join(major)
if args.os != os_version:
continue
# determine the lowest valid build ID and select this # determine the lowest valid build ID and select this
# when using auto and version options # when using auto and version options
if (args.auto or args.version) and 'Beta' not in product_info[product_id]['title']: if (args.auto or args.version or args.os) and 'Beta' not in product_info[product_id]['title']:
try: try:
lowest_valid_build lowest_valid_build
except NameError: except NameError:
@ -705,6 +715,17 @@ def main():
exit(0) exit(0)
else: else:
print '\nBuild %s selected. Downloading #%s...\n' % (lowest_valid_build, answer) print '\nBuild %s selected. Downloading #%s...\n' % (lowest_valid_build, answer)
elif args.os:
try:
answer
except NameError:
print ('\n'
'Item # %s is not available. '
'Run again without --os argument '
'to select a valid build to download.\n' % args.os)
exit(0)
else:
print '\nBuild %s selected. Downloading #%s...\n' % (lowest_valid_build, answer)
elif args.auto: elif args.auto:
try: try:
answer answer