mirror of https://github.com/acidanthera/audk.git
BaseTools/BinToPcd: Follow PEP-8 indent of 4 spaces
https://www.python.org/dev/peps/pep-0008/ Cc: Yanyan Sun <yanyan.sun@intel.com> Cc: Yonghong Zhu <yonghong.zhu@intel.com> Cc: Liming Gao <liming.gao@intel.com> Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
This commit is contained in:
parent
d0f946f30d
commit
0c805f4f8f
|
@ -33,22 +33,22 @@ if __name__ == '__main__':
|
||||||
Value = int (Argument, 0)
|
Value = int (Argument, 0)
|
||||||
except:
|
except:
|
||||||
Message = '{Argument} is not a valid integer value.'.format (Argument = Argument)
|
Message = '{Argument} is not a valid integer value.'.format (Argument = Argument)
|
||||||
raise argparse.ArgumentTypeError(Message)
|
raise argparse.ArgumentTypeError (Message)
|
||||||
if Value < 0:
|
if Value < 0:
|
||||||
Message = '{Argument} is a negative value.'.format (Argument = Argument)
|
Message = '{Argument} is a negative value.'.format (Argument = Argument)
|
||||||
raise argparse.ArgumentTypeError(Message)
|
raise argparse.ArgumentTypeError (Message)
|
||||||
return Value
|
return Value
|
||||||
|
|
||||||
def ValidatePcdName (Argument):
|
def ValidatePcdName (Argument):
|
||||||
if re.split('[a-zA-Z\_][a-zA-Z0-9\_]*\.[a-zA-Z\_][a-zA-Z0-9\_]*', Argument) != ['','']:
|
if re.split ('[a-zA-Z\_][a-zA-Z0-9\_]*\.[a-zA-Z\_][a-zA-Z0-9\_]*', Argument) != ['','']:
|
||||||
Message = '{Argument} is not in the form <PcdTokenSpaceGuidCName>.<PcdCName>'.format (Argument = Argument)
|
Message = '{Argument} is not in the form <PcdTokenSpaceGuidCName>.<PcdCName>'.format (Argument = Argument)
|
||||||
raise argparse.ArgumentTypeError(Message)
|
raise argparse.ArgumentTypeError (Message)
|
||||||
return Argument
|
return Argument
|
||||||
|
|
||||||
def ValidateGuidName (Argument):
|
def ValidateGuidName (Argument):
|
||||||
if re.split('[a-zA-Z\_][a-zA-Z0-9\_]*', Argument) != ['','']:
|
if re.split ('[a-zA-Z\_][a-zA-Z0-9\_]*', Argument) != ['','']:
|
||||||
Message = '{Argument} is not a valid GUID C name'.format (Argument = Argument)
|
Message = '{Argument} is not a valid GUID C name'.format (Argument = Argument)
|
||||||
raise argparse.ArgumentTypeError(Message)
|
raise argparse.ArgumentTypeError (Message)
|
||||||
return Argument
|
return Argument
|
||||||
|
|
||||||
def ByteArray (Buffer, Xdr = False):
|
def ByteArray (Buffer, Xdr = False):
|
||||||
|
@ -57,55 +57,55 @@ if __name__ == '__main__':
|
||||||
# If Xdr flag is set then encode data using the Variable-Length Opaque
|
# If Xdr flag is set then encode data using the Variable-Length Opaque
|
||||||
# Data format of RFC 4506 External Data Representation Standard (XDR).
|
# Data format of RFC 4506 External Data Representation Standard (XDR).
|
||||||
#
|
#
|
||||||
XdrEncoder = xdrlib.Packer()
|
XdrEncoder = xdrlib.Packer ()
|
||||||
for Item in Buffer:
|
for Item in Buffer:
|
||||||
XdrEncoder.pack_bytes(Item)
|
XdrEncoder.pack_bytes (Item)
|
||||||
Buffer = bytearray(XdrEncoder.get_buffer())
|
Buffer = bytearray (XdrEncoder.get_buffer ())
|
||||||
else:
|
else:
|
||||||
#
|
#
|
||||||
# If Xdr flag is not set, then concatenate all the data
|
# If Xdr flag is not set, then concatenate all the data
|
||||||
#
|
#
|
||||||
Buffer = b''.join(Buffer)
|
Buffer = b''.join (Buffer)
|
||||||
#
|
#
|
||||||
# Return a PCD value of the form '{0x01, 0x02, ...}' along with the PCD length in bytes
|
# Return a PCD value of the form '{0x01, 0x02, ...}' along with the PCD length in bytes
|
||||||
#
|
#
|
||||||
return '{' + (', '.join(['0x{Byte:02X}'.format(Byte = Item) for Item in Buffer])) + '}', len (Buffer)
|
return '{' + (', '.join (['0x{Byte:02X}'.format (Byte = Item) for Item in Buffer])) + '}', len (Buffer)
|
||||||
|
|
||||||
#
|
#
|
||||||
# Create command line argument parser object
|
# Create command line argument parser object
|
||||||
#
|
#
|
||||||
parser = argparse.ArgumentParser(prog = __prog__,
|
parser = argparse.ArgumentParser (prog = __prog__,
|
||||||
description = __description__ + __copyright__,
|
description = __description__ + __copyright__,
|
||||||
conflict_handler = 'resolve')
|
conflict_handler = 'resolve')
|
||||||
parser.add_argument("-i", "--input", dest = 'InputFile', type = argparse.FileType('rb'), action='append', required = True,
|
parser.add_argument ("-i", "--input", dest = 'InputFile', type = argparse.FileType ('rb'), action='append', required = True,
|
||||||
help = "Input binary filename. Multiple input files are combined into a single PCD.")
|
help = "Input binary filename. Multiple input files are combined into a single PCD.")
|
||||||
parser.add_argument("-o", "--output", dest = 'OutputFile', type = argparse.FileType('wb'),
|
parser.add_argument ("-o", "--output", dest = 'OutputFile', type = argparse.FileType ('wb'),
|
||||||
help = "Output filename for PCD value or PCD statement")
|
help = "Output filename for PCD value or PCD statement")
|
||||||
parser.add_argument("-p", "--pcd", dest = 'PcdName', type = ValidatePcdName,
|
parser.add_argument ("-p", "--pcd", dest = 'PcdName', type = ValidatePcdName,
|
||||||
help = "Name of the PCD in the form <PcdTokenSpaceGuidCName>.<PcdCName>")
|
help = "Name of the PCD in the form <PcdTokenSpaceGuidCName>.<PcdCName>")
|
||||||
parser.add_argument("-t", "--type", dest = 'PcdType', default = None, choices = ['VPD','HII'],
|
parser.add_argument ("-t", "--type", dest = 'PcdType', default = None, choices = ['VPD','HII'],
|
||||||
help = "PCD statement type (HII or VPD). Default is standard.")
|
help = "PCD statement type (HII or VPD). Default is standard.")
|
||||||
parser.add_argument("-m", "--max-size", dest = 'MaxSize', type = ValidateUnsignedInteger,
|
parser.add_argument ("-m", "--max-size", dest = 'MaxSize', type = ValidateUnsignedInteger,
|
||||||
help = "Maximum size of the PCD. Ignored with --type HII.")
|
help = "Maximum size of the PCD. Ignored with --type HII.")
|
||||||
parser.add_argument("-f", "--offset", dest = 'Offset', type = ValidateUnsignedInteger,
|
parser.add_argument ("-f", "--offset", dest = 'Offset', type = ValidateUnsignedInteger,
|
||||||
help = "VPD offset if --type is VPD. UEFI Variable offset if --type is HII. Must be 8-byte aligned.")
|
help = "VPD offset if --type is VPD. UEFI Variable offset if --type is HII. Must be 8-byte aligned.")
|
||||||
parser.add_argument("-n", "--variable-name", dest = 'VariableName',
|
parser.add_argument ("-n", "--variable-name", dest = 'VariableName',
|
||||||
help = "UEFI variable name. Only used with --type HII.")
|
help = "UEFI variable name. Only used with --type HII.")
|
||||||
parser.add_argument("-g", "--variable-guid", type = ValidateGuidName, dest = 'VariableGuid',
|
parser.add_argument ("-g", "--variable-guid", type = ValidateGuidName, dest = 'VariableGuid',
|
||||||
help = "UEFI variable GUID C name. Only used with --type HII.")
|
help = "UEFI variable GUID C name. Only used with --type HII.")
|
||||||
parser.add_argument("-x", "--xdr", dest = 'Xdr', action = "store_true",
|
parser.add_argument ("-x", "--xdr", dest = 'Xdr', action = "store_true",
|
||||||
help = "Encode PCD using the Variable-Length Opaque Data format of RFC 4506 External Data Representation Standard (XDR)")
|
help = "Encode PCD using the Variable-Length Opaque Data format of RFC 4506 External Data Representation Standard (XDR)")
|
||||||
parser.add_argument("-v", "--verbose", dest = 'Verbose', action = "store_true",
|
parser.add_argument ("-v", "--verbose", dest = 'Verbose', action = "store_true",
|
||||||
help = "Increase output messages")
|
help = "Increase output messages")
|
||||||
parser.add_argument("-q", "--quiet", dest = 'Quiet', action = "store_true",
|
parser.add_argument ("-q", "--quiet", dest = 'Quiet', action = "store_true",
|
||||||
help = "Reduce output messages")
|
help = "Reduce output messages")
|
||||||
parser.add_argument("--debug", dest = 'Debug', type = int, metavar = '[0-9]', choices = range(0,10), default = 0,
|
parser.add_argument ("--debug", dest = 'Debug', type = int, metavar = '[0-9]', choices = range (0, 10), default = 0,
|
||||||
help = "Set debug level")
|
help = "Set debug level")
|
||||||
|
|
||||||
#
|
#
|
||||||
# Parse command line arguments
|
# Parse command line arguments
|
||||||
#
|
#
|
||||||
args = parser.parse_args()
|
args = parser.parse_args ()
|
||||||
|
|
||||||
#
|
#
|
||||||
# Read all binary input files
|
# Read all binary input files
|
||||||
|
@ -113,11 +113,11 @@ if __name__ == '__main__':
|
||||||
Buffer = []
|
Buffer = []
|
||||||
for File in args.InputFile:
|
for File in args.InputFile:
|
||||||
try:
|
try:
|
||||||
Buffer.append(File.read())
|
Buffer.append (File.read ())
|
||||||
File.close()
|
File.close ()
|
||||||
except:
|
except:
|
||||||
print ('BinToPcd: error: can not read binary input file {File}'.format (File = File))
|
print ('BinToPcd: error: can not read binary input file {File}'.format (File = File))
|
||||||
sys.exit(1)
|
sys.exit (1)
|
||||||
|
|
||||||
#
|
#
|
||||||
# Convert PCD to an encoded string of hex values and determine the size of
|
# Convert PCD to an encoded string of hex values and determine the size of
|
||||||
|
@ -149,7 +149,7 @@ if __name__ == '__main__':
|
||||||
Pcd = ' {Name}|{Value}'.format (Name = args.PcdName, Value = PcdValue)
|
Pcd = ' {Name}|{Value}'.format (Name = args.PcdName, Value = PcdValue)
|
||||||
elif args.MaxSize < PcdSize:
|
elif args.MaxSize < PcdSize:
|
||||||
print ('BinToPcd: error: argument --max-size is smaller than input file.')
|
print ('BinToPcd: error: argument --max-size is smaller than input file.')
|
||||||
sys.exit(1)
|
sys.exit (1)
|
||||||
else:
|
else:
|
||||||
Pcd = ' {Name}|{Value}|VOID*|{Size}'.format (Name = args.PcdName, Value = PcdValue, Size = args.MaxSize)
|
Pcd = ' {Name}|{Value}|VOID*|{Size}'.format (Name = args.PcdName, Value = PcdValue, Size = args.MaxSize)
|
||||||
|
|
||||||
|
@ -168,7 +168,7 @@ if __name__ == '__main__':
|
||||||
args.MaxSize = PcdSize
|
args.MaxSize = PcdSize
|
||||||
if args.MaxSize < PcdSize:
|
if args.MaxSize < PcdSize:
|
||||||
print ('BinToPcd: error: argument --max-size is smaller than input file.')
|
print ('BinToPcd: error: argument --max-size is smaller than input file.')
|
||||||
sys.exit(1)
|
sys.exit (1)
|
||||||
if args.Offset is None:
|
if args.Offset is None:
|
||||||
#
|
#
|
||||||
# if --offset is not provided, then set offset field to '*' so build
|
# if --offset is not provided, then set offset field to '*' so build
|
||||||
|
@ -181,7 +181,7 @@ if __name__ == '__main__':
|
||||||
#
|
#
|
||||||
if (args.Offset % 8) != 0:
|
if (args.Offset % 8) != 0:
|
||||||
print ('BinToPcd: error: argument --offset must be 8-byte aligned.')
|
print ('BinToPcd: error: argument --offset must be 8-byte aligned.')
|
||||||
sys.exit(1)
|
sys.exit (1)
|
||||||
#
|
#
|
||||||
# Use the --offset value provided.
|
# Use the --offset value provided.
|
||||||
#
|
#
|
||||||
|
@ -193,7 +193,7 @@ if __name__ == '__main__':
|
||||||
elif args.PcdType == 'HII':
|
elif args.PcdType == 'HII':
|
||||||
if args.VariableGuid is None or args.VariableName is None:
|
if args.VariableGuid is None or args.VariableName is None:
|
||||||
print ('BinToPcd: error: arguments --variable-guid and --variable-name are required for --type HII.')
|
print ('BinToPcd: error: arguments --variable-guid and --variable-name are required for --type HII.')
|
||||||
sys.exit(1)
|
sys.exit (1)
|
||||||
if args.Offset is None:
|
if args.Offset is None:
|
||||||
#
|
#
|
||||||
# Use UEFI Variable offset of 0 if --offset is not provided
|
# Use UEFI Variable offset of 0 if --offset is not provided
|
||||||
|
@ -204,7 +204,7 @@ if __name__ == '__main__':
|
||||||
#
|
#
|
||||||
if (args.Offset % 8) != 0:
|
if (args.Offset % 8) != 0:
|
||||||
print ('BinToPcd: error: argument --offset must be 8-byte aligned.')
|
print ('BinToPcd: error: argument --offset must be 8-byte aligned.')
|
||||||
sys.exit(1)
|
sys.exit (1)
|
||||||
Pcd = ' {Name}|L"{VarName}"|{VarGuid}|{Offset}|{Value}'.format (Name = args.PcdName, VarName = args.VariableName, VarGuid = args.VariableGuid, Offset = args.Offset, Value = PcdValue)
|
Pcd = ' {Name}|L"{VarName}"|{VarGuid}|{Offset}|{Value}'.format (Name = args.PcdName, VarName = args.VariableName, VarGuid = args.VariableGuid, Offset = args.Offset, Value = PcdValue)
|
||||||
if args.Verbose:
|
if args.Verbose:
|
||||||
print ('BinToPcd: Convert binary file to PCD statement compatible with PCD sections')
|
print ('BinToPcd: Convert binary file to PCD statement compatible with PCD sections')
|
||||||
|
|
Loading…
Reference in New Issue