Enhance MigrationMsa2Inf to support extract the GUID value from DEC files. It can...
authorqhuang8 <qhuang8@7335b38e-4728-0410-8992-fb3ffe349368>
Mon, 30 Mar 2009 06:40:05 +0000 (06:40 +0000)
committerqhuang8 <qhuang8@7335b38e-4728-0410-8992-fb3ffe349368>
Mon, 30 Mar 2009 06:40:05 +0000 (06:40 +0000)
git-svn-id: https://buildtools.tianocore.org/svn/buildtools/trunk/BaseTools@1539 7335b38e-4728-0410-8992-fb3ffe349368

Source/Python/MigrationMsa2Inf/MigrationMsa2Inf.py

index 3ac8a97..b25f6d4 100644 (file)
@@ -13,7 +13,7 @@
 
 """ This program converts EDK II MSA files into EDK II Extended INF format files """
 
-import os, re, sys, xml.dom.minidom
+import os, re, sys, fnmatch, xml.dom.minidom
 from optparse import OptionParser
 from AutoGenExterns import *
 from Common.XmlRoutines import  *             # XmlParseFile, XmlElement, XmlAttribute, XmlList, XmlElementData, XmlNode
@@ -744,24 +744,47 @@ def main():
             if (options.debug and options.verbose > 2):
                 print "PKG:", file
 
-            Spd = openSpd(os.path.join(workspace, file))
-            if (Spd == 'None'):
-                print "Could not parse the Package file:", file
-                sys.exit(1)
+            if fnmatch.fnmatch(file, "*.dec"):
+                print "parsing " + os.path.join(workspace, file)
+                PackageGuid = ""
+                PackageVersion = ""
+                try:
+                    Lines = open(os.path.join(workspace, file)).readlines()
+                except:
+                    print "Could not parse the Package file:", file
+                    sys.exit(1)
+                    
+                for Line in Lines:
+                    Line = Line.split("#")[0]
+                    Items = Line.split("=")
+                    if len(Items) != 2:
+                        continue
 
-            path = os.path.split(file)[0]
-            file = file.replace(".nspd", ".dec")
-            file = file.replace(".spd", ".dec")
+                    Key = Items[0].strip().upper()
+                    if Key == "PACKAGE_GUID":
+                        PackageGuid = Items[1].strip()
+                    if Key == "PACKAGE_VERSION":
+                        PackageVersion = Items[1].strip()
 
-            try:
-                PackageGuid = str(XmlElement(Spd, SpdHeader + "GuidValue"))
-            except:
-                pass
+            else:
+                Spd = openSpd(os.path.join(workspace, file))
+                if (Spd == 'None'):
+                    print "Could not parse the Package file:", file
+                    sys.exit(1)
 
-            try:
-                PackageVersion = str(XmlElement(Spd, SpdHeader + "Version"))
-            except:
-                pass
+                path = os.path.split(file)[0]
+                file = file.replace(".nspd", ".dec")
+                file = file.replace(".spd", ".dec")
+
+                try:
+                    PackageGuid = str(XmlElement(Spd, SpdHeader + "GuidValue"))
+                except:
+                    pass
+
+                try:
+                    PackageVersion = str(XmlElement(Spd, SpdHeader + "Version"))
+                except:
+                    pass
 
             file = file + "|" + PackageGuid + "|" + PackageVersion
             PkgDb.insert(0, file)
@@ -849,8 +872,6 @@ def main():
                         line = Name + "|" + os.path.join(path, Header)
                         HeaderLocations.insert(0, str(line))
 
-            Spd.unlink()
-
     PkgList = []
     PkgListIa32 = []
     PkgListX64 = []
@@ -2433,7 +2454,8 @@ def main():
         Output.append(UserExtensionSection)
         if (options.debug):
             print UserExtensionSection
-  
+
+    print "write file", outputFile
     if (options.autowrite):
         fo = open(outputFile, "w")
         for Section in Output[:]: