John Stultz | accad87 | 2017-07-06 13:56:07 -0700 | [diff] [blame] | 1 | #!/usr/bin/python |
Vishal Bhoj | 9a67d91 | 2016-06-09 10:02:07 +0100 | [diff] [blame] | 2 | |
| 3 | import sys, os, argparse, ConfigParser |
| 4 | |
| 5 | default_filename='platforms.config' |
| 6 | |
| 7 | def list_platforms(): |
| 8 | for p in platforms: print p |
| 9 | |
| 10 | def shortlist_platforms(): |
| 11 | for p in platforms: print p, |
| 12 | |
| 13 | def get_images(): |
| 14 | if args.platform: |
| 15 | try: |
| 16 | value = config.get(args.platform, "EXTRA_FILES") |
| 17 | print value, |
| 18 | except: |
| 19 | pass |
| 20 | try: |
| 21 | value = config.get(args.platform, "BUILD_ATF") |
| 22 | if value == "yes": |
| 23 | print "bl1.bin fip.bin" |
| 24 | return True |
| 25 | except: |
| 26 | try: |
| 27 | value = config.get(args.platform, "UEFI_BIN") |
| 28 | print value |
| 29 | return True |
| 30 | except: |
| 31 | print "No images found!" |
| 32 | else: |
| 33 | print "No platform specified!" |
| 34 | |
| 35 | return False |
| 36 | |
| 37 | def get_option(): |
| 38 | if args.platform: |
| 39 | if args.option: |
| 40 | try: |
| 41 | value = config.get(args.platform, args.option) |
| 42 | if value: |
| 43 | print value |
| 44 | return True |
| 45 | except: |
| 46 | return True # Option not found, return True, and no output |
| 47 | else: |
| 48 | print "No option specified!" |
| 49 | else: |
| 50 | print "No platform specified!" |
| 51 | return False |
| 52 | |
| 53 | parser = argparse.ArgumentParser(description='Parses platform configuration for Linaro UEFI build scripts.') |
| 54 | parser.add_argument('-c', '--config-file', help='Specify a non-default platform config file.', required=False) |
| 55 | parser.add_argument('-p', '--platform', help='Read configuration for PLATFORM only.', required=False) |
| 56 | parser.add_argument('command', action="store", help='Action to perform') |
| 57 | parser.add_argument('-o', '--option', help='Option to retreive') |
| 58 | |
| 59 | args = parser.parse_args() |
| 60 | if args.config_file: |
| 61 | config_filename = args.config_file |
| 62 | else: |
| 63 | config_filename = os.path.dirname(os.path.realpath(sys.argv[0])) + '/' + default_filename |
| 64 | |
| 65 | config = ConfigParser.ConfigParser() |
| 66 | config.read(config_filename) |
| 67 | |
| 68 | platforms = config.sections() |
| 69 | |
| 70 | commands = {"shortlist": shortlist_platforms, |
| 71 | "list": list_platforms, |
| 72 | "images": get_images, |
| 73 | "get": get_option} |
| 74 | |
| 75 | try: |
| 76 | retval = commands[args.command]() |
| 77 | except: |
| 78 | print ("Unrecognized command '%s'" % args.command) |
| 79 | |
| 80 | if retval != True: |
| 81 | sys.exit(1) |