]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Adding a couple of features for far processing, including detecting duplicate files.
authorbbahnsen <bbahnsen@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 25 Jan 2007 01:18:46 +0000 (01:18 +0000)
committerbbahnsen <bbahnsen@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 25 Jan 2007 01:18:46 +0000 (01:18 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@2304 6f19259b-4bc3-4df7-8a09-765794883524

Tools/Python/InstallFar.py
Tools/Python/MkFar.py
Tools/Python/WorkspaceRoutines.py

index 6e28998cff1c5771d3beedcafa8a4eaccc656189..7bc03aa0ca9ecf1a15ea1bf33668f72584bce08a 100755 (executable)
@@ -13,6 +13,7 @@ class Flags:
     self.verbose = False
     self.force = False
     self.reinstall = False
     self.verbose = False
     self.force = False
     self.reinstall = False
+    self.dir = ''
 
 class Database:
 
 
 class Database:
 
@@ -52,7 +53,7 @@ class Database:
         XmlElement(fpd, "/PlatformHeader/PlatformName")
 
     for farfile in  XmlList(self.dom, "/FrameworkDatabase/FarList/Filename"):
         XmlElement(fpd, "/PlatformHeader/PlatformName")
 
     for farfile in  XmlList(self.dom, "/FrameworkDatabase/FarList/Filename"):
-      farGuid = farfile.getAttribute("FarGuid")
+      farGuid = Guid(farfile.getAttribute("FarGuid"))
       self.installedFars[farGuid] = XmlElementData(farfile)
 
     self.packageList = XmlNode(self.dom, "/FrameworkDatabase/PackageList")
       self.installedFars[farGuid] = XmlElementData(farfile)
 
     self.packageList = XmlNode(self.dom, "/FrameworkDatabase/PackageList")
@@ -131,8 +132,8 @@ def GetFpdGuidVersion(Dom, strip=0):
   gpath = ["PlatformSurfaceArea", "PlatformHeader", "GuidValue"]
   vpath = ["PlatformSurfaceArea", "PlatformHeader", "Version"]
 
   gpath = ["PlatformSurfaceArea", "PlatformHeader", "GuidValue"]
   vpath = ["PlatformSurfaceArea", "PlatformHeader", "Version"]
 
-  return string.lower(XmlElement(Dom, "/".join(gpath[strip:]))), \
-         XmlElement(Dom, "/".join(vpath[strip:]))
+  return Guid(XmlElement(Dom, "/".join(gpath[strip:]))), \
+              XmlElement(Dom, "/".join(vpath[strip:]))
 
 def GetSpdGuidVersion(Dom, strip=0):
 
 
 def GetSpdGuidVersion(Dom, strip=0):
 
@@ -141,8 +142,8 @@ def GetSpdGuidVersion(Dom, strip=0):
   gpath = ["PackageSurfaceArea", "SpdHeader", "GuidValue"]
   vpath = ["PackageSurfaceArea", "SpdHeader", "Version"]
 
   gpath = ["PackageSurfaceArea", "SpdHeader", "GuidValue"]
   vpath = ["PackageSurfaceArea", "SpdHeader", "Version"]
 
-  return string.lower(XmlElement(Dom, "/".join(gpath[strip:]))), \
-         XmlElement(Dom, "/".join(vpath[strip:]))
+  return Guid(XmlElement(Dom, "/".join(gpath[strip:]))), \
+              XmlElement(Dom, "/".join(vpath[strip:]))
 
 def InstallFar(farfile, workspaceLocation=""):
 
 
 def InstallFar(farfile, workspaceLocation=""):
 
@@ -189,7 +190,7 @@ def InstallFar(farfile, workspaceLocation=""):
       msa = XmlParseString(far.read(msafilePath))
 
       for package in XmlList(msa, "/ModuleSurfaceArea/PackageDependencies/Package"):
       msa = XmlParseString(far.read(msafilePath))
 
       for package in XmlList(msa, "/ModuleSurfaceArea/PackageDependencies/Package"):
-        guid = package.getAttribute("PackageGuid")
+        guid = Guid(package.getAttribute("PackageGuid"))
         version = package.getAttribute("PackageVersion")
 
         # Does anyone provide this package?
         version = package.getAttribute("PackageVersion")
 
         # Does anyone provide this package?
@@ -215,8 +216,8 @@ def InstallFar(farfile, workspaceLocation=""):
     # Go through the dependencies
     for dependency in XmlList(fpd, "/PlatformSurfaceArea/FrameworkModules/ModuleSA") + \
                       XmlList(fpd, "/PlatformSurfaceArea/FrameworkModules/ModuleSA/Libraries/Instance"):
     # Go through the dependencies
     for dependency in XmlList(fpd, "/PlatformSurfaceArea/FrameworkModules/ModuleSA") + \
                       XmlList(fpd, "/PlatformSurfaceArea/FrameworkModules/ModuleSA/Libraries/Instance"):
-      packagesNeeded.add((string.lower(dependency.getAttribute("PackageGuid")), 
-                                       dependency.getAttribute("PackageVersion")))
+      packagesNeeded.add((Guid(dependency.getAttribute("PackageGuid")), 
+                               dependency.getAttribute("PackageVersion")))
 
     # Let's see if all the packages are in the workspace 
     for guid, version in packagesNeeded:
 
     # Let's see if all the packages are in the workspace 
     for guid, version in packagesNeeded:
@@ -228,7 +229,7 @@ def InstallFar(farfile, workspaceLocation=""):
         installError = True
 
   # Check the fars
         installError = True
 
   # Check the fars
-  thisFarGuid = string.lower(XmlElement(manifest, "/FrameworkArchiveManifest/FarHeader/GuidValue"))
+  thisFarGuid = Guid(XmlElement(manifest, "/FrameworkArchiveManifest/FarHeader/GuidValue"))
   if fdb.HasFar(thisFarGuid):
     if not flags.reinstall:
       print "Error: There is a far with this guid already installed."
   if fdb.HasFar(thisFarGuid):
     if not flags.reinstall:
       print "Error: There is a far with this guid already installed."
@@ -301,7 +302,7 @@ if __name__ == '__main__':
   flags = Flags()
 
   # Process the command line args.
   flags = Flags()
 
   # Process the command line args.
-  optlist, args = getopt.getopt(sys.argv[1:], '?hvf', ['help', 'verbose', 'force', 'reinstall'])
+  optlist, args = getopt.getopt(sys.argv[1:], '?hvfd:', ['directory=', 'help', 'verbose', 'force', 'reinstall'])
 
   # First pass through the options list.
   for o, a in optlist:
 
   # First pass through the options list.
   for o, a in optlist:
@@ -314,6 +315,8 @@ if __name__ == '__main__':
       optlist.remove((o,a))
     if o in ["-v", "--verbose"]:
       flags.verbose = True
       optlist.remove((o,a))
     if o in ["-v", "--verbose"]:
       flags.verbose = True
+    if o in ["-d", "--directory"]:
+      flags.dir = a
     if o in ["-f", "--force"]:
       flags.force = True
     if o in ["--reinstall"]:
     if o in ["-f", "--force"]:
       flags.force = True
     if o in ["--reinstall"]:
index a12ba2105f1eada07fd8f68476790a84024496bb..2848b1de6596093c432236a13fe9eb897f3ee653 100755 (executable)
@@ -25,9 +25,16 @@ class Far:
 far = Far()
 """The far object is constructed from the template file the user passed in."""
 
 far = Far()
 """The far object is constructed from the template file the user passed in."""
 
+def AddToZip(zip, infile):
+
+  """Add a file to a zip file, provided it is not already there."""
+
+  if not infile in zip.namelist():
+    zip.write(inWorkspace(infile), infile)
+
 def parseMsa(msaFile, spdDir):
 
 def parseMsa(msaFile, spdDir):
 
-  """ XXX Parse an msa file and return a list of all the files that this msa
+  """Parse an msa file and return a list of all the files that this msa
   includes."""
 
   filelist = [msaFile]
   includes."""
 
   filelist = [msaFile]
@@ -39,7 +46,7 @@ def parseMsa(msaFile, spdDir):
   xmlPaths = [
     "/ModuleSurfaceArea/SourceFiles/Filename",
     "/ModuleSurfaceArea/NonProcessedFiles/Filename" ]
   xmlPaths = [
     "/ModuleSurfaceArea/SourceFiles/Filename",
     "/ModuleSurfaceArea/NonProcessedFiles/Filename" ]
-    
+
   for xmlPath in xmlPaths:
     for f in XmlList(msa, xmlPath):
       filelist.append(str(os.path.join(msaDir, XmlElementData(f))))
   for xmlPath in xmlPaths:
     for f in XmlList(msa, xmlPath):
       filelist.append(str(os.path.join(msaDir, XmlElementData(f))))
@@ -57,10 +64,16 @@ def parseSpd(spdFile):
 
   spd = xml.dom.minidom.parse(inWorkspace(spdFile))
 
 
   spd = xml.dom.minidom.parse(inWorkspace(spdFile))
 
+  # We are currently ignoring these hints.
+  readonly = XmlElement(spd, "/PackageSurfaceArea/PackageDefinitions/ReadOnly") != "false"
+  repackage = XmlElement(spd, "/PackageSurfaceArea/PackageDefinitions/RePackage") != "false"
+
   xmlPaths = [
     "/PackageSurfaceArea/LibraryClassDeclarations/LibraryClass/IncludeHeader",
   xmlPaths = [
     "/PackageSurfaceArea/LibraryClassDeclarations/LibraryClass/IncludeHeader",
-    "/PackageSurfaceArea/IndustryStdIncludes/IndustryStdHeader/IncludeHeader",
-    "/PackageSurfaceArea/PackageHeaders/IncludePkgHeader" ]
+    "/PackageSurfaceArea/IndustryStdIncludes/IndustryStdHeader/IncludeHeader" ]
+
+    # These are covered by the Industry Standard Includes.
+    # "/PackageSurfaceArea/PackageHeaders/IncludePkgHeader"
 
   for xmlPath in xmlPaths:
     for f in XmlList(spd, xmlPath):
 
   for xmlPath in xmlPaths:
     for f in XmlList(spd, xmlPath):
@@ -87,7 +100,7 @@ def makeFarHeader(doc):
 
   """Create a dom tree for the Far Header. It will use information from the
   template file passed on the command line, if present."""
 
   """Create a dom tree for the Far Header. It will use information from the
   template file passed on the command line, if present."""
-  
   header = XmlAppendChildElement(doc.documentElement, "FarHeader")
 
   XmlAppendChildElement(header, "FarName", far.FarName)
   header = XmlAppendChildElement(doc.documentElement, "FarHeader")
 
   XmlAppendChildElement(header, "FarName", far.FarName)
@@ -125,7 +138,10 @@ def makeFar(files, farname):
   contents = XmlAppendChildElement(top_element, "Contents")
   XmlAppendChildElement(top_element, "UserExtensions")
 
   contents = XmlAppendChildElement(top_element, "Contents")
   XmlAppendChildElement(top_element, "UserExtensions")
 
-  zip = zipfile.ZipFile(farname, "w")
+  try:
+    zip = zipfile.ZipFile(farname, "w", zipfile.ZIP_DEFLATED)
+  except:
+    zip = zipfile.ZipFile(farname, "w", zipfile.ZIP_STORED)
   for infile in set(files):
     if not os.path.exists(inWorkspace(infile)):
       print "Error: Non-existent file '%s'." % infile
   for infile in set(files):
     if not os.path.exists(inWorkspace(infile)):
       print "Error: Non-existent file '%s'." % infile
@@ -139,7 +155,7 @@ def makeFar(files, farname):
 
       package = XmlAppendChildElement(packList, "FarPackage")
       XmlAppendChildElement(package, "FarFilename", lean(infile), {"Md5Sum": Md5(inWorkspace(infile))})
 
       package = XmlAppendChildElement(packList, "FarPackage")
       XmlAppendChildElement(package, "FarFilename", lean(infile), {"Md5Sum": Md5(inWorkspace(infile))})
-      zip.write(inWorkspace(infile), infile)
+      AddToZip(zip, infile)
       XmlAppendChildElement(package, "GuidValue", spdGuid)
       XmlAppendChildElement(package, "Version", spdVersion)
       XmlAppendChildElement(package, "DefaultPath", spdDir)
       XmlAppendChildElement(package, "GuidValue", spdGuid)
       XmlAppendChildElement(package, "Version", spdVersion)
       XmlAppendChildElement(package, "DefaultPath", spdDir)
@@ -149,17 +165,17 @@ def makeFar(files, farname):
 
       for spdfile in filelist:
         XmlAppendChildElement(packContents, "FarFilename", lean(spdfile), {"Md5Sum": Md5(inWorkspace(os.path.join(spdDir, spdfile)))})
 
       for spdfile in filelist:
         XmlAppendChildElement(packContents, "FarFilename", lean(spdfile), {"Md5Sum": Md5(inWorkspace(os.path.join(spdDir, spdfile)))})
-        zip.write(inWorkspace(os.path.join(spdDir, spdfile)), os.path.join(spdDir,spdfile))
+        AddToZip(zip, os.path.join(spdDir,spdfile))
 
     elif extension == ".fpd":
 
       platform = XmlAppendChildElement(platList, "FarPlatform")
       XmlAppendChildElement(platform, "FarFilename", lean(infile), {"Md5Sum": Md5(inWorkspace(infile))})
 
     elif extension == ".fpd":
 
       platform = XmlAppendChildElement(platList, "FarPlatform")
       XmlAppendChildElement(platform, "FarFilename", lean(infile), {"Md5Sum": Md5(inWorkspace(infile))})
-      zip.write(inWorkspace(infile), infile)
+      AddToZip(zip, infile)
 
     else:
       XmlAppendChildElement(contents, "FarFilename", lean(infile), {"Md5Sum": Md5(inWorkspace(infile))})
 
     else:
       XmlAppendChildElement(contents, "FarFilename", lean(infile), {"Md5Sum": Md5(inWorkspace(infile))})
-      zip.write(inWorkspace(infile), infile)
+      AddToZip(zip, infile)
 
   zip.writestr("FrameworkArchiveManifest.xml", man.toxml('UTF-8'))
   zip.close()
 
   zip.writestr("FrameworkArchiveManifest.xml", man.toxml('UTF-8'))
   zip.close()
@@ -202,7 +218,6 @@ is a text file that allows more contol over the contents of the far.
 
   # Second pass through the options list. These can override the first pass.
   for o, a in optlist:
 
   # Second pass through the options list. These can override the first pass.
   for o, a in optlist:
-    print o, a
     if o in ["-o", "--far", "--output"]:
       far.FileName = a
 
     if o in ["-o", "--far", "--output"]:
       far.FileName = a
 
index f1f8be2b3ca6aa2fababe0dda3efea01bfca1b9c..c75cd57c524c753ee0cc29cce11199ddec1c412d 100755 (executable)
@@ -27,7 +27,7 @@ def genguid():
         getpass.getuser() + 
         str(time.time()) + 
         socket.gethostbyname(socket.gethostname())).hexdigest()
         getpass.getuser() + 
         str(time.time()) + 
         socket.gethostbyname(socket.gethostname())).hexdigest()
-  return "%s-%s-%s-%s-%s" % (g[0:8], g[8:12], g[12:16], g[16:20], g[20:])
+  return Guid("%s-%s-%s-%s-%s" % (g[0:8], g[8:12], g[12:16], g[16:20], g[20:]))
 
 def lean(path):
   """Lean the slashes forward"""
 
 def lean(path):
   """Lean the slashes forward"""
@@ -56,5 +56,6 @@ def Md5(filename):
 
   return sum
 
 
   return sum
 
-
-
+def Guid(guidString):
+  """Convert the guid string into a canonical form suitable for comparison."""
+  return string.lower(guidString)