From 2611bfa207243a29f674883e51cf6af2112a5f9d Mon Sep 17 00:00:00 2001 From: spashabk-in Date: Mon, 17 Jul 2017 06:59:08 -0500 Subject: Removal of argparse module dependency in compression Change-Id: Id7c5d0e644477e33581b70fd909cc4c3878c9e73 Reviewed-on: http://ralgit01.raleigh.ibm.com/gerrit1/43205 Tested-by: Jenkins Server Tested-by: FSP CI Jenkins Reviewed-by: Sachin Gupta --- src/boot/sbeCompression.py | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) (limited to 'src/boot') diff --git a/src/boot/sbeCompression.py b/src/boot/sbeCompression.py index a9ac9a23..510b2cc3 100755 --- a/src/boot/sbeCompression.py +++ b/src/boot/sbeCompression.py @@ -30,7 +30,7 @@ import random import sys import binascii import fileinput -import argparse +import getopt import struct import operator err = False @@ -86,7 +86,7 @@ def compress(inputFile, compressedFile): strBits = "" count = 0 - #Create a bitmap for each four bytes of binary. + #Create a bitmap for each four bytes of binary. for i in range(0, os.stat(inputFile).st_size / 4 ): fourByt = f.read(4) @@ -128,15 +128,35 @@ def compress(inputFile, compressedFile): f.close() fW.close() -def main( argv ): +def usage(): + print "usage: sbeCompression.py [-h] [-l ] [-i ]" + print "SBE Compression Parser" + print "Arguments:" + print "-h, --help\t\tshow this help message and exit" + print "-l, --imageLoc\t\tSeeprom Binary Location" + print "-i, --image\t\tSeeprom Binary" + return 1 - parser = argparse.ArgumentParser( description = "SBE Compression Parser" ) - parser.add_argument( '-l', '--imageLoc', type=str, help = 'Seeprom Binary Location' ) - parser.add_argument( '-i', '--image', type=str, help = 'Seeprom Binary ' ) +def main( argv ): - args = parser.parse_args() - imagePath = args.imageLoc - image = args.image + try: + opts, args = getopt.getopt(argv[1:], "l:i:h", ['imageLoc=', 'image=', 'help']) + except getopt.GetoptError as err: + print str(err) + usage() + exit(1) + + imagePath = '' + image = '' + + for opt, arg in opts: + if opt in ('-l', '--imageLoc'): + imagePath = arg + elif opt in ('-i', '--image'): + image = arg + else: + usage() + exit(1) #Make a copy of SEEPROM binary. cmd1 = "cp " + imagePath + "/" + image + " " + imagePath + "/" + image + ".orig" -- cgit v1.2.1