#!/usr/bin/python """ Script by Chris Barker (chrisb@sneezingdog.com) to generate lists of Apple's flat package format they use for os and security updates and makes some useful documentation Copyright [2009] Chris Barker Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. """ import commands, os, sys, shutil from BeautifulSoup import BeautifulSoup def unFlattenPKG(pkg): dest = "/tmp/wtfupdate" flatStatus = commands.getstatusoutput("/usr/sbin/pkgutil --expand \"%s\" \"%s\"" % (pkg, dest) ) #print flatStatus return dest def getSUDescription(pkg): sud = open(pkg+'/Resources/English.lproj/SUDescription.html', 'r') soup = BeautifulSoup(sud) sud.close() return soup.body def getScripts(pkg, htmloutput): #htmloutput.write("""\n""") return htmloutput def writeHeaders(htmloutput): lines = """ wtfupdate """ htmloutput.writelines(lines) return htmloutput if __name__ == "__main__": #check for pkg if len(sys.argv) != 3: print 'Usage: %s file.pkg output.html' % sys.argv[0] sys.exit(1) elif os.path.splitext(sys.argv[1])[1] == '.pkg' and os.path.isfile(sys.argv[1]): pathToPKG = sys.argv[1] else: print 'Usage: %s file.pkg' % sys.argv[0] htmloutput = open(sys.argv[2], 'w') writeHeaders(htmloutput) pkg = unFlattenPKG(pathToPKG) for i in getSUDescription(pkg): htmloutput.writelines(str(i)) getScripts(pkg, htmloutput) for fileName in os.listdir(pkg): if os.path.splitext(fileName)[1] == '.pkg': getFileList(pkg, fileName, htmloutput) htmloutput.close() shutil.rmtree(pkg)