Created
January 14, 2015 13:42
-
-
Save srgrn/3879f077588c4c31f613 to your computer and use it in GitHub Desktop.
a simple script to get details from provisioning profiles on mac
This file contains 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
import optparse | |
import os | |
import plistlib | |
import sys | |
import traceback | |
PLIST_START = '<?xml' | |
PLIST_END = '</plist>' | |
def parse_provisioning(fn): | |
fn = os.path.expanduser(fn) | |
with open(fn) as fp: | |
data = fp.read() | |
xml = data[data.find(PLIST_START) : data.find(PLIST_END) + len(PLIST_END)] | |
pl = plistlib.readPlistFromString(xml) | |
details = [pl.get('UUID'), pl.get('ExpirationDate').strftime("%X - %x"), pl.get('Name'),pl.get('AppIDName',""),pl.get('Entitlements')['application-identifier']] | |
return details | |
def main(): | |
parser = optparse.OptionParser() | |
parser.add_option('-f', '--file', dest='filename', help='plist details', metavar='FILE') | |
parser.add_option('-p', '--path', dest='path', help='Directory to serach plist in') | |
(options, args) = parser.parse_args() | |
output = [['UUID', 'Expiration Date', 'Name', 'App Name', 'Application Identifier']] | |
if options.filename: | |
try: | |
prov_details = parse_provisioning(options.filename) | |
except Exception as e: | |
sys.stderr.write('Error reading details from %s\n' % options.filename) | |
return 1 | |
if prov_details: | |
output.append(prov_details) | |
elif options.path: | |
for file in os.listdir(options.path): | |
prov_details = [] | |
if file.endswith(".mobileprovision"): | |
try: | |
prov_details = parse_provisioning(os.path.join(options.path,file)) | |
except Exception as e: | |
traceback.print_exc() | |
sys.stderr.write('Error reading details from %s\n' % os.path.join(options.path,file)) | |
if prov_details: | |
output.append(prov_details) | |
else: | |
parser.print_help() | |
return 1 | |
if len(output) > 1: | |
csv = [",".join(x) for x in output] | |
print "\n".join(csv) | |
if __name__ == '__main__': | |
sys.exit(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment