mirror of https://github.com/acidanthera/audk.git
Adding a couple of features for far processing, including detecting duplicate files.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@2304 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
parent
e2cce12fd6
commit
822d4f3a53
|
@ -13,6 +13,7 @@ class Flags:
|
|||
self.verbose = False
|
||||
self.force = False
|
||||
self.reinstall = False
|
||||
self.dir = ''
|
||||
|
||||
class Database:
|
||||
|
||||
|
@ -52,7 +53,7 @@ class Database:
|
|||
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")
|
||||
|
@ -131,8 +132,8 @@ def GetFpdGuidVersion(Dom, strip=0):
|
|||
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):
|
||||
|
||||
|
@ -141,8 +142,8 @@ def GetSpdGuidVersion(Dom, strip=0):
|
|||
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=""):
|
||||
|
||||
|
@ -189,7 +190,7 @@ def InstallFar(farfile, workspaceLocation=""):
|
|||
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?
|
||||
|
@ -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"):
|
||||
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:
|
||||
|
@ -228,7 +229,7 @@ def InstallFar(farfile, workspaceLocation=""):
|
|||
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."
|
||||
|
@ -301,7 +302,7 @@ if __name__ == '__main__':
|
|||
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:
|
||||
|
@ -314,6 +315,8 @@ if __name__ == '__main__':
|
|||
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"]:
|
||||
|
|
|
@ -25,9 +25,16 @@ class Far:
|
|||
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):
|
||||
|
||||
""" 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]
|
||||
|
@ -39,7 +46,7 @@ def parseMsa(msaFile, spdDir):
|
|||
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))))
|
||||
|
@ -57,10 +64,16 @@ def parseSpd(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",
|
||||
"/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):
|
||||
|
@ -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."""
|
||||
|
||||
|
||||
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")
|
||||
|
||||
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
|
||||
|
@ -139,7 +155,7 @@ def makeFar(files, farname):
|
|||
|
||||
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)
|
||||
|
@ -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)))})
|
||||
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))})
|
||||
zip.write(inWorkspace(infile), infile)
|
||||
AddToZip(zip, 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()
|
||||
|
@ -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:
|
||||
print o, a
|
||||
if o in ["-o", "--far", "--output"]:
|
||||
far.FileName = a
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ def genguid():
|
|||
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"""
|
||||
|
@ -56,5 +56,6 @@ def Md5(filename):
|
|||
|
||||
return sum
|
||||
|
||||
|
||||
|
||||
def Guid(guidString):
|
||||
"""Convert the guid string into a canonical form suitable for comparison."""
|
||||
return string.lower(guidString)
|
||||
|
|
Loading…
Reference in New Issue