Fix to add SeedProgram extended attribute to the install application if --seedprogram option is used

This commit is contained in:
Greg Neagle 2019-07-03 10:02:31 -07:00
parent 9d9bb51ab1
commit ebd27a06c2

View File

@ -69,7 +69,7 @@ def get_input(prompt=None):
return input(prompt) return input(prompt)
def readPlist(filepath): def read_plist(filepath):
'''Wrapper for the differences between Python 2 and Python 3's plistlib''' '''Wrapper for the differences between Python 2 and Python 3's plistlib'''
try: try:
with open(filepath, "rb") as fileobj: with open(filepath, "rb") as fileobj:
@ -79,10 +79,10 @@ def readPlist(filepath):
return plistlib.readPlist(filepath) return plistlib.readPlist(filepath)
def readPlistFromString(bytestring): def read_plist_from_string(bytestring):
'''Wrapper for the differences between Python 2 and Python 3's plistlib''' '''Wrapper for the differences between Python 2 and Python 3's plistlib'''
try: try:
return plistlib.loads(bytestring) return plistlib.loads(bytestring)
except AttributeError: except AttributeError:
# plistlib module doesn't have a load function (as in Python 2) # plistlib module doesn't have a load function (as in Python 2)
return plistlib.readPlistFromString(bytestring) return plistlib.readPlistFromString(bytestring)
@ -91,7 +91,7 @@ def readPlistFromString(bytestring):
def get_seeding_program(sucatalog_url): def get_seeding_program(sucatalog_url):
'''Returns a seeding program name based on the sucatalog_url''' '''Returns a seeding program name based on the sucatalog_url'''
try: try:
seed_catalogs = readPlist(SEED_CATALOGS_PLIST) seed_catalogs = read_plist(SEED_CATALOGS_PLIST)
for key, value in seed_catalogs.items(): for key, value in seed_catalogs.items():
if sucatalog_url == value: if sucatalog_url == value:
return key return key
@ -103,7 +103,7 @@ def get_seeding_program(sucatalog_url):
def get_seed_catalog(seedname='DeveloperSeed'): def get_seed_catalog(seedname='DeveloperSeed'):
'''Returns the developer seed sucatalog''' '''Returns the developer seed sucatalog'''
try: try:
seed_catalogs = readPlist(SEED_CATALOGS_PLIST) seed_catalogs = read_plist(SEED_CATALOGS_PLIST)
return seed_catalogs.get(seedname) return seed_catalogs.get(seedname)
except (OSError, ExpatError, AttributeError, KeyError): except (OSError, ExpatError, AttributeError, KeyError):
return '' return ''
@ -112,7 +112,7 @@ def get_seed_catalog(seedname='DeveloperSeed'):
def get_seeding_programs(): def get_seeding_programs():
'''Returns the list of seeding program names''' '''Returns the list of seeding program names'''
try: try:
seed_catalogs = readPlist(SEED_CATALOGS_PLIST) seed_catalogs = read_plist(SEED_CATALOGS_PLIST)
return list(seed_catalogs.keys()) return list(seed_catalogs.keys())
except (OSError, ExpatError, AttributeError, KeyError): except (OSError, ExpatError, AttributeError, KeyError):
return '' return ''
@ -134,7 +134,7 @@ def make_sparse_image(volume_name, output_path):
print(err, file=sys.stderr) print(err, file=sys.stderr)
exit(-1) exit(-1)
try: try:
return readPlistFromString(output)[0] return read_plist_from_string(output)[0]
except IndexError as err: except IndexError as err:
print('Unexpected output from hdiutil: %s' % output, file=sys.stderr) print('Unexpected output from hdiutil: %s' % output, file=sys.stderr)
exit(-1) exit(-1)
@ -177,7 +177,7 @@ def mountdmg(dmgpath):
file=sys.stderr) file=sys.stderr)
return None return None
if pliststr: if pliststr:
plist = readPlistFromString(pliststr) plist = read_plist_from_string(pliststr)
for entity in plist['system-entities']: for entity in plist['system-entities']:
if 'mount-point' in entity: if 'mount-point' in entity:
mountpoints.append(entity['mount-point']) mountpoints.append(entity['mount-point'])
@ -258,7 +258,7 @@ def parse_server_metadata(filename):
title = '' title = ''
vers = '' vers = ''
try: try:
md_plist = readPlist(filename) md_plist = read_plist(filename)
except (OSError, IOError, ExpatError) as err: except (OSError, IOError, ExpatError) as err:
print('Error reading %s: %s' % (filename, err), file=sys.stderr) print('Error reading %s: %s' % (filename, err), file=sys.stderr)
return {} return {}
@ -342,7 +342,7 @@ def download_and_parse_sucatalog(sucatalog, workdir, ignore_cache=False):
with gzip.open(localcatalogpath) as the_file: with gzip.open(localcatalogpath) as the_file:
content = the_file.read() content = the_file.read()
try: try:
catalog = readPlistFromString(content) catalog = read_plist_from_string(content)
return catalog return catalog
except ExpatError as err: except ExpatError as err:
print('Error reading %s: %s' % (localcatalogpath, err), print('Error reading %s: %s' % (localcatalogpath, err),
@ -350,7 +350,7 @@ def download_and_parse_sucatalog(sucatalog, workdir, ignore_cache=False):
exit(-1) exit(-1)
else: else:
try: try:
catalog = readPlist(localcatalogpath) catalog = read_plist(localcatalogpath)
return catalog return catalog
except (OSError, IOError, ExpatError) as err: except (OSError, IOError, ExpatError) as err:
print('Error reading %s: %s' % (localcatalogpath, err), print('Error reading %s: %s' % (localcatalogpath, err),
@ -546,10 +546,12 @@ def main():
unmountdmg(mountpoint) unmountdmg(mountpoint)
exit(-1) exit(-1)
# add the seeding program xattr to the app if applicable # add the seeding program xattr to the app if applicable
seeding_program = get_seeding_program(args.catalogurl) seeding_program = get_seeding_program(su_catalog_url)
if seeding_program: if seeding_program:
installer_app = find_installer_app(mountpoint) installer_app = find_installer_app(mountpoint)
if installer_app: if installer_app:
print("Adding seeding program %s extended attribute to app"
% seeding_program)
xattr.setxattr(installer_app, 'SeedProgram', seeding_program) xattr.setxattr(installer_app, 'SeedProgram', seeding_program)
print('Product downloaded and installed to %s' % sparse_diskimage_path) print('Product downloaded and installed to %s' % sparse_diskimage_path)
if args.raw: if args.raw: