Last active
April 11, 2017 18:35
-
-
Save lazymutt/de26a6d3002b710da9fece810b4540df to your computer and use it in GitHub Desktop.
I sometimes redistribute Apple Mac OS update packages to team members. Apple's Software Update Server doesn't make it easy to find where the packages are stored. This script will find the proper directory and open it in the Finder for you.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
""" | |
# Copyright (c) 2017 University of Utah Student Computing Labs. ################ | |
# All Rights Reserved. | |
# | |
# Permission to use, copy, modify, and distribute this software and | |
# its documentation for any purpose and without fee is hereby granted, | |
# provided that the above copyright notice appears in all copies and | |
# that both that copyright notice and this permission notice appear | |
# in supporting documentation, and that the name of The University | |
# of Utah not be used in advertising or publicity pertaining to | |
# distribution of the software without specific, written prior | |
# permission. This software is supplied as is without expressed or | |
# implied warranties of any kind. | |
################################################################################ | |
""" | |
from __future__ import print_function | |
import glob | |
import os | |
import subprocess | |
import sys | |
import xml.etree.cElementTree | |
def main(): | |
r""" | |
# make a tool that automates this: | |
# cd /Library/Server/Software\ Update/ ; find . -name '031-97236' | |
# cd ./Data/html/content/downloads/57/03/031-97236/6cil6325mcnct1bpp7wmg7hzb9xcvnl7os/ | |
# open . | |
# usage: SUS_update_finder.py 031-97236 | |
# output: | |
# Searching for: 091-04692 | |
# Found: /Library/Server/Software Update/Data/html/content/downloads/33/24/091-04692/kmw11cvk7g73o86grl5z0fn5s9sia060vz | |
# Opening... | |
# ________ | |
# --/ Output \----------------------------------------- | |
# title: GatekeeperConfigData | |
# Verson A: 110 | |
# Verson B: 110.1.1490377414 | |
# Verson C: 110 | |
# __________________________ | |
# ---/ Archive name suggestions \---------------------- | |
# GatekeeperConfigData_110 | |
# GatekeeperConfigData_110.1.1490377414 | |
# GatekeeperConfigData_110 | |
""" | |
update_name = sys.argv[1] | |
version_b = '' | |
version_c = '' | |
sus_file_root = '/Library/Server/Software Update/' | |
print('Searching for: %s' % update_name) | |
os.chdir(sus_file_root) | |
find_output = [x for x in subprocess.check_output(['/usr/bin/find', '.', '-name', update_name]).split('\n') if x] | |
if len(find_output) != 1: | |
print('Too much output from find: %r\nExiting...' % find_output) | |
sys.exit(1) | |
else: | |
os.chdir(sus_file_root + find_output[0]) | |
ls_output = [x for x in subprocess.check_output(['ls', os.getcwd()]).split('\n') if x] | |
if len(find_output) != 1: | |
print('Too much output from ls: %r\nExiting...' % ls_output) | |
sys.exit(1) | |
else: | |
os.chdir(ls_output[0]) | |
print('Found: %s\nOpening...' % os.getcwd()) | |
subprocess.call(['/usr/bin/open', os.getcwd()]) | |
pkg_output = glob.glob(os.path.join(os.getcwd(), '*')) | |
for item in pkg_output: | |
if '.pkm' in item: | |
pkm_file = item | |
elif '.dist' in item: | |
dist_file = item | |
pkm_tree = xml.etree.cElementTree.parse(pkm_file).getroot() | |
for node in pkm_tree.iter('bundle'): | |
version = node.attrib.get('CFBundleShortVersionString') | |
for node in pkm_tree.iter('pkg-info'): | |
version_b = node.attrib.get('version') | |
dist_tree = xml.etree.cElementTree.parse(dist_file).getroot() | |
for node in dist_tree.iter('pkg-ref'): | |
title = node.attrib.get('id') | |
for node in dist_tree.iter('localization'): | |
for sub_node in node.iter('strings'): | |
version_c_raw = sub_node.text | |
version_c_raw = version_c_raw.split(';\n') | |
for item in version_c_raw: | |
if 'SU_VERS' in item: | |
version_c_raw = item.split(' = ') | |
if version_c_raw[1].split('"')[1]: | |
version_c = version_c_raw[1].split('"')[1] | |
print(' ________') | |
print('--/ Output \\' + '-' * 41) | |
print(' {:<20} {}'.format('title:', title)) | |
print(' {:<20} {}'.format('Version A: ', version)) | |
print(' {:<20} {}'.format('Version B: ', version_b)) | |
print(' {:<20} {}'.format('Version C: ', version_c)) | |
print(' __________________________') | |
print('---/ Archive name suggestions \\' + '-' * 22) | |
print(' %s' % (title + '_' + version)) | |
print(' %s' % (title + '_' + version_b)) | |
print(' %s' % (title + '_' + version_c)) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment