summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeif Lindholm <leif.lindholm@linaro.org>2019-03-28 15:51:29 +0000
committerLeif Lindholm <leif.lindholm@linaro.org>2019-03-28 15:51:29 +0000
commit4507234240197ee0dc1830add75ab7fca0f3d6e6 (patch)
tree5717d3932c52e1f22033fb3c930834255a52ffea
parenta34412f33d9cdd1a646e02b92644431bfb14a2a3 (diff)
parse-platforms.py: make Python 3 *and* Python 2 compatible
Python 3 support requires the "configparser" module to be installed. Remains compatible with existing users without intervention thanks to contribution from Thierry Reding. Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org> Reported-by: Thierry Reding <treding@nvidia.com> Reviewed-by: Thierry Reding <treding@nvidia.com>
-rwxr-xr-xparse-platforms.py41
1 files changed, 26 insertions, 15 deletions
diff --git a/parse-platforms.py b/parse-platforms.py
index 7483749..0e16fc3 100755
--- a/parse-platforms.py
+++ b/parse-platforms.py
@@ -1,36 +1,49 @@
#!/usr/bin/python
-import sys, os, argparse, ConfigParser
+from __future__ import print_function
+
+import sys, os, argparse
+
+try:
+ # try Python 3 configparser module first
+ from configparser import ConfigParser
+except:
+ # fallback to Python 2 ConfigParser
+ try:
+ from ConfigParser import ConfigParser
+ except:
+ print("Unable to load configparser/ConfigParser - exiting!")
+ sys.exit(1)
default_filename='platforms.config'
def list_platforms():
- for p in platforms: print p
+ for p in platforms: print(p)
def shortlist_platforms():
- for p in platforms: print p,
+ for p in platforms: print(p, end = ' ')
def get_images():
if args.platform:
try:
value = config.get(args.platform, "EXTRA_FILES")
- print value,
+ print(value, end = ' ')
except:
pass
try:
value = config.get(args.platform, "BUILD_ATF")
if value == "yes":
- print "bl1.bin fip.bin"
+ print("bl1.bin fip.bin")
return True
except:
try:
value = config.get(args.platform, "UEFI_BIN")
- print value
+ print(value)
return True
except:
- print "No images found!"
+ print("No images found!")
else:
- print "No platform specified!"
+ print("No platform specified!")
return False
@@ -43,7 +56,7 @@ def get_executables():
except:
return False
- print "%s/%s" % (arch, value)
+ print("%s/%s" % (arch, value))
return True
except:
pass
@@ -56,14 +69,14 @@ def get_option():
try:
value = config.get(args.platform, args.option)
if value:
- print value
+ print(value)
return True
except:
return True # Option not found, return True, and no output
else:
- print "No option specified!"
+ print("No option specified!")
else:
- print "No platform specified!"
+ print("No platform specified!")
return False
parser = argparse.ArgumentParser(description='Parses platform configuration for Linaro UEFI build scripts.')
@@ -78,7 +91,7 @@ if args.config_file:
else:
config_filename = os.path.dirname(os.path.realpath(sys.argv[0])) + '/' + default_filename
-config = ConfigParser.ConfigParser()
+config = ConfigParser()
config.read(config_filename)
platforms = config.sections()
@@ -93,6 +106,4 @@ try:
retval = commands[args.command]()
except:
print ("Unrecognized command '%s'" % args.command)
-
-if retval != True:
sys.exit(1)