Created
January 6, 2012 21:41
-
-
Save eklipse2k8/1572524 to your computer and use it in GitHub Desktop.
Helps for developing scripts that need to know the actual SDK path.
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
#!/usr/bin/python | |
import plistlib | |
import os | |
import commands | |
import argparse | |
DEVELOPER_DIR = commands.getoutput('/usr/bin/xcode-select -print-path') | |
PLATFORMS_DIRECTORY = os.path.join(DEVELOPER_DIR, "Platforms") | |
IPHONE_PLATFORM = "iPhoneOS.platform" | |
SIMULATOR_PLATFORM = "iPhoneSimulator.platform" | |
PLIST_FILE = "Info.plist" | |
def find_version(platform): | |
path = None | |
if (platform == 'iphoneos'): | |
path = os.path.join(PLATFORMS_DIRECTORY, IPHONE_PLATFORM, PLIST_FILE) | |
elif (platform == 'iphonesimulator'): | |
path = os.path.join(PLATFORMS_DIRECTORY, SIMULATOR_PLATFORM, PLIST_FILE) | |
else: | |
return None | |
version = plistlib.readPlist(path).CFBundleShortVersionString | |
return version | |
def get_sdk_path(platform, version): | |
path = None | |
if (platform == 'iphoneos'): | |
path = os.path.join(PLATFORMS_DIRECTORY, IPHONE_PLATFORM, "Developer", "SDKs", "iPhoneOS{0}.sdk".format(version)) | |
elif (platform == 'iphonesimulator'): | |
path = os.path.join(PLATFORMS_DIRECTORY, SIMULATOR_PLATFORM, "Developer", "SDKs", "iPhoneSimulator{0}.sdk".format(version)) | |
else: | |
return None | |
return path | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser(description='Returns the version of the currently installed platform sdk.') | |
parser.add_argument('-iphoneos', action='store_const', dest='platform', const='iphoneos') | |
parser.add_argument('-iphonesimulator', action='store_const', dest='platform', const='iphonesimulator') | |
parser.add_argument('-path', action='store_true', dest='showPath', default=False) | |
args = parser.parse_args() | |
if args.platform is None: | |
parser.print_help() | |
exit(0) | |
version = find_version(args.platform) | |
if (args.showPath): | |
print get_sdk_path(args.platform, version) | |
else: | |
print version |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment