[edk2-devel] [PATCH] Platform/Intel:Change the way of getting the env file content

Zhang, Shenglei posted 1 patch 4 years, 9 months ago
Failed in applying to current master (apply log)
Platform/Intel/Tools/GenBiosId/BiosId.env   |  1 -
Platform/Intel/Tools/GenBiosId/GenBiosId.py | 33 ++++++++++++---------
2 files changed, 19 insertions(+), 15 deletions(-)
[edk2-devel] [PATCH] Platform/Intel:Change the way of getting the env file content
Posted by Zhang, Shenglei 4 years, 9 months ago
From: "Fan, Zhiju" <zhijux.fan@intel.com>

The env file content can not be retrieved by using the
original method, so we change the way to read the content.
And we change the env file to original format.

This patch is going to fix the issue.

Cc: Liming Gao <liming.gao@intel.com>
Cc: Bob Feng <bob.c.feng@intel.com>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Leif Lindholm <leif.lindholm@linaro.org>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Signed-off-by: Zhiju.Fan <zhijux.fan@intel.com>
---
 Platform/Intel/Tools/GenBiosId/BiosId.env   |  1 -
 Platform/Intel/Tools/GenBiosId/GenBiosId.py | 33 ++++++++++++---------
 2 files changed, 19 insertions(+), 15 deletions(-)

diff --git a/Platform/Intel/Tools/GenBiosId/BiosId.env b/Platform/Intel/Tools/GenBiosId/BiosId.env
index dfdeeb3107..614a66ddb8 100644
--- a/Platform/Intel/Tools/GenBiosId/BiosId.env
+++ b/Platform/Intel/Tools/GenBiosId/BiosId.env
@@ -18,7 +18,6 @@
 #  SPDX-License-Identifier: BSD-2-Clause-Patent
 #
 ##
-[config]
 BOARD_ID      = KBLRVP3
 BOARD_REV     = 1
 BOARD_EXT     = 000
diff --git a/Platform/Intel/Tools/GenBiosId/GenBiosId.py b/Platform/Intel/Tools/GenBiosId/GenBiosId.py
index 7e9d115f05..31abb24d31 100644
--- a/Platform/Intel/Tools/GenBiosId/GenBiosId.py
+++ b/Platform/Intel/Tools/GenBiosId/GenBiosId.py
@@ -16,7 +16,7 @@ import struct
 import datetime
 import argparse
 import platform
-
+from collections import OrderedDict
 try:
     from configparser import ConfigParser
 except:
@@ -24,8 +24,6 @@ except:
 
 # Config message
 _BIOS_Signature = "$IBIOSI$"
-_SectionKeyName = '__name__'
-_SectionName = 'config'
 
 _ConfigItem = {
     "BOARD_ID": {'Value': '', 'Length': 7},
@@ -121,20 +119,26 @@ def CheckOptions(Options):
         EdkLogger("GenBiosId", FILE_NOT_FOUND, ExtraData="Input file not found")
     return InputFile, OutputFile, OutputTextFile
 
+# Read input file and get config
+def ReadInputFile(InputFile):
+    InputDict = OrderedDict()
+    with open(InputFile) as File:
+        FileLines = File.readlines()
+    for Line in FileLines:
+        if Line.strip().startswith('#'):
+            continue
+        if '=' in Line:
+            Key, Value = Line.split('=')
+            InputDict[Key.strip()] = Value.strip()
+    return InputDict
+
 
 # Parse the input file and extract the information
-def ParserInputFile(InputFile):
-    cf = ConfigParser()
-    cf.optionxform = str
-    cf.read(InputFile)
-    if _SectionName not in cf._sections:
-        EdkLogger("GenBiosId", FORMAT_NOT_SUPPORTED, ExtraData=_ConfigSectionNotDefine)
-    for Item in cf._sections[_SectionName]:
-        if Item == _SectionKeyName:
-            continue
+def ParserInputFile(InputDict):
+    for Item in InputDict:
         if Item not in _ConfigItem:
             EdkLogger("GenBiosId", FORMAT_INVALID, ExtraData=_ConfigItemInvalid % Item)
-        _ConfigItem[Item]['Value'] = cf._sections[_SectionName][Item]
+        _ConfigItem[Item]['Value'] = InputDict[Item]
         if len(_ConfigItem[Item]['Value']) != _ConfigItem[Item]['Length']:
             EdkLogger("GenBiosId", FORMAT_INVALID, ExtraData=_ConfigLenInvalid % Item)
     for Item in _ConfigItem:
@@ -168,7 +172,8 @@ def PrintOutputFile(OutputFile, OutputTextFile, Id_Str):
 def Main():
     Options = MyOptionParser()
     InputFile, OutputFile, OutputTextFile = CheckOptions(Options)
-    Id_Str = ParserInputFile(InputFile)
+    InputDict = ReadInputFile(InputFile)
+    Id_Str = ParserInputFile(InputDict)
     PrintOutputFile(OutputFile, OutputTextFile, Id_Str)
     return 0
 
-- 
2.18.0.windows.1


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#43138): https://edk2.groups.io/g/devel/message/43138
Mute This Topic: https://groups.io/mt/32281635/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-

Re: [edk2-devel] [PATCH] Platform/Intel:Change the way of getting the env file content
Posted by Liming Gao 4 years, 9 months ago
Reviewed-by: Liming Gao <liming.gao@intel.com>

> -----Original Message-----
> From: Zhang, Shenglei
> Sent: Tuesday, July 2, 2019 9:02 AM
> To: devel@edk2.groups.io
> Cc: Fan, ZhijuX <zhijux.fan@intel.com>; Gao, Liming <liming.gao@intel.com>; Feng, Bob C <bob.c.feng@intel.com>; Ard Biesheuvel
> <ard.biesheuvel@linaro.org>; Leif Lindholm <leif.lindholm@linaro.org>; Kinney, Michael D <michael.d.kinney@intel.com>
> Subject: [PATCH] Platform/Intel:Change the way of getting the env file content
> 
> From: "Fan, Zhiju" <zhijux.fan@intel.com>
> 
> The env file content can not be retrieved by using the
> original method, so we change the way to read the content.
> And we change the env file to original format.
> 
> This patch is going to fix the issue.
> 
> Cc: Liming Gao <liming.gao@intel.com>
> Cc: Bob Feng <bob.c.feng@intel.com>
> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> Cc: Leif Lindholm <leif.lindholm@linaro.org>
> Cc: Michael D Kinney <michael.d.kinney@intel.com>
> Signed-off-by: Zhiju.Fan <zhijux.fan@intel.com>
> ---
>  Platform/Intel/Tools/GenBiosId/BiosId.env   |  1 -
>  Platform/Intel/Tools/GenBiosId/GenBiosId.py | 33 ++++++++++++---------
>  2 files changed, 19 insertions(+), 15 deletions(-)
> 
> diff --git a/Platform/Intel/Tools/GenBiosId/BiosId.env b/Platform/Intel/Tools/GenBiosId/BiosId.env
> index dfdeeb3107..614a66ddb8 100644
> --- a/Platform/Intel/Tools/GenBiosId/BiosId.env
> +++ b/Platform/Intel/Tools/GenBiosId/BiosId.env
> @@ -18,7 +18,6 @@
>  #  SPDX-License-Identifier: BSD-2-Clause-Patent
>  #
>  ##
> -[config]
>  BOARD_ID      = KBLRVP3
>  BOARD_REV     = 1
>  BOARD_EXT     = 000
> diff --git a/Platform/Intel/Tools/GenBiosId/GenBiosId.py b/Platform/Intel/Tools/GenBiosId/GenBiosId.py
> index 7e9d115f05..31abb24d31 100644
> --- a/Platform/Intel/Tools/GenBiosId/GenBiosId.py
> +++ b/Platform/Intel/Tools/GenBiosId/GenBiosId.py
> @@ -16,7 +16,7 @@ import struct
>  import datetime
>  import argparse
>  import platform
> -
> +from collections import OrderedDict
>  try:
>      from configparser import ConfigParser
>  except:
> @@ -24,8 +24,6 @@ except:
> 
>  # Config message
>  _BIOS_Signature = "$IBIOSI$"
> -_SectionKeyName = '__name__'
> -_SectionName = 'config'
> 
>  _ConfigItem = {
>      "BOARD_ID": {'Value': '', 'Length': 7},
> @@ -121,20 +119,26 @@ def CheckOptions(Options):
>          EdkLogger("GenBiosId", FILE_NOT_FOUND, ExtraData="Input file not found")
>      return InputFile, OutputFile, OutputTextFile
> 
> +# Read input file and get config
> +def ReadInputFile(InputFile):
> +    InputDict = OrderedDict()
> +    with open(InputFile) as File:
> +        FileLines = File.readlines()
> +    for Line in FileLines:
> +        if Line.strip().startswith('#'):
> +            continue
> +        if '=' in Line:
> +            Key, Value = Line.split('=')
> +            InputDict[Key.strip()] = Value.strip()
> +    return InputDict
> +
> 
>  # Parse the input file and extract the information
> -def ParserInputFile(InputFile):
> -    cf = ConfigParser()
> -    cf.optionxform = str
> -    cf.read(InputFile)
> -    if _SectionName not in cf._sections:
> -        EdkLogger("GenBiosId", FORMAT_NOT_SUPPORTED, ExtraData=_ConfigSectionNotDefine)
> -    for Item in cf._sections[_SectionName]:
> -        if Item == _SectionKeyName:
> -            continue
> +def ParserInputFile(InputDict):
> +    for Item in InputDict:
>          if Item not in _ConfigItem:
>              EdkLogger("GenBiosId", FORMAT_INVALID, ExtraData=_ConfigItemInvalid % Item)
> -        _ConfigItem[Item]['Value'] = cf._sections[_SectionName][Item]
> +        _ConfigItem[Item]['Value'] = InputDict[Item]
>          if len(_ConfigItem[Item]['Value']) != _ConfigItem[Item]['Length']:
>              EdkLogger("GenBiosId", FORMAT_INVALID, ExtraData=_ConfigLenInvalid % Item)
>      for Item in _ConfigItem:
> @@ -168,7 +172,8 @@ def PrintOutputFile(OutputFile, OutputTextFile, Id_Str):
>  def Main():
>      Options = MyOptionParser()
>      InputFile, OutputFile, OutputTextFile = CheckOptions(Options)
> -    Id_Str = ParserInputFile(InputFile)
> +    InputDict = ReadInputFile(InputFile)
> +    Id_Str = ParserInputFile(InputDict)
>      PrintOutputFile(OutputFile, OutputTextFile, Id_Str)
>      return 0
> 
> --
> 2.18.0.windows.1


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#43163): https://edk2.groups.io/g/devel/message/43163
Mute This Topic: https://groups.io/mt/32281635/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-