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 plistlib
import subprocess
import re
import sys
import urlparse
import xattr
from xml.dom import minidom
from xml.parsers.expat import ExpatError
from operator import itemgetter
from distutils.version import LooseVersion
@ -367,6 +365,7 @@ def get_unsupported_models(filename):
unsupported_models = line.split(" ")[-1][:-1]
return unsupported_models
def download_and_parse_sucatalog(sucatalog, workdir, ignore_cache=False):
'''Downloads and returns a parsed softwareupdate catalog'''
try:
@ -539,8 +538,12 @@ def main():
'for the current device.')
parser.add_argument('--version', metavar='match_version',
default='',
help='Selects the lowest valid build ID matching'
'the selected version.')
help='Selects the lowest valid build ID matching '
'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()
# show this Mac's info
@ -618,16 +621,23 @@ def main():
# skip if build is not suitable for current device
# 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
# skip if a version is selected and it does not match
if args.version and args.version != product_info[product_id]['version']:
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
# 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:
lowest_valid_build
except NameError:
@ -705,6 +715,17 @@ def main():
exit(0)
else:
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:
try:
answer