Add argparse with help.

This commit is contained in:
Jeffrey Townsend
2016-06-14 15:55:31 +00:00
parent a7d40d3898
commit 6adf798d6f

19
tools/onlplatform.py Normal file → Executable file
View File

@@ -8,6 +8,7 @@ the platform package metadata.
import sys, os
import itertools
import argparse
toolsdir = os.path.dirname(os.path.abspath(__file__))
sys.path.append(toolsdir)
@@ -23,9 +24,11 @@ from onlpm import *
pm = defaultPm()
platform = sys.argv[1]
arch = sys.argv[2]
key = sys.argv[3]
ap = argparse.ArgumentParser("ONL Platform Data Extractor.")
ap.add_argument("platform", help="Platform name")
ap.add_argument("arch", help="Architecture")
ap.add_argument("key", help="Lookup key.")
ops = ap.parse_args()
def extractKey(platform, arch, key):
@@ -71,12 +74,12 @@ def extractVendor(platform, arch):
l = [x for x in l if x.startswith('onl-vendor-config-')]
return "\n".join(l)
if key in ('kernel', 'initrd', 'dtb', 'itb',):
print extractKey(platform, arch, key)
if ops.key in ('kernel', 'initrd', 'dtb', 'itb',):
print extractKey(ops.platform, ops.arch, ops.key)
sys.exit(0)
if key == 'vendor':
print extractVendor(platform, arch)
if ops.key == 'vendor':
print extractVendor(ops.platform, ops.arch)
sys.exit(0)
raise SystemExit("invalid key %s" % key)
raise SystemExit("invalid key %s" % ops.key)