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.verbose = False
|
||||||
self.force = False
|
self.force = False
|
||||||
self.reinstall = False
|
self.reinstall = False
|
||||||
|
self.dir = ''
|
||||||
|
|
||||||
class Database:
|
class Database:
|
||||||
|
|
||||||
@ -52,7 +53,7 @@ class Database:
|
|||||||
XmlElement(fpd, "/PlatformHeader/PlatformName")
|
XmlElement(fpd, "/PlatformHeader/PlatformName")
|
||||||
|
|
||||||
for farfile in XmlList(self.dom, "/FrameworkDatabase/FarList/Filename"):
|
for farfile in XmlList(self.dom, "/FrameworkDatabase/FarList/Filename"):
|
||||||
farGuid = farfile.getAttribute("FarGuid")
|
farGuid = Guid(farfile.getAttribute("FarGuid"))
|
||||||
self.installedFars[farGuid] = XmlElementData(farfile)
|
self.installedFars[farGuid] = XmlElementData(farfile)
|
||||||
|
|
||||||
self.packageList = XmlNode(self.dom, "/FrameworkDatabase/PackageList")
|
self.packageList = XmlNode(self.dom, "/FrameworkDatabase/PackageList")
|
||||||
@ -131,7 +132,7 @@ def GetFpdGuidVersion(Dom, strip=0):
|
|||||||
gpath = ["PlatformSurfaceArea", "PlatformHeader", "GuidValue"]
|
gpath = ["PlatformSurfaceArea", "PlatformHeader", "GuidValue"]
|
||||||
vpath = ["PlatformSurfaceArea", "PlatformHeader", "Version"]
|
vpath = ["PlatformSurfaceArea", "PlatformHeader", "Version"]
|
||||||
|
|
||||||
return string.lower(XmlElement(Dom, "/".join(gpath[strip:]))), \
|
return Guid(XmlElement(Dom, "/".join(gpath[strip:]))), \
|
||||||
XmlElement(Dom, "/".join(vpath[strip:]))
|
XmlElement(Dom, "/".join(vpath[strip:]))
|
||||||
|
|
||||||
def GetSpdGuidVersion(Dom, strip=0):
|
def GetSpdGuidVersion(Dom, strip=0):
|
||||||
@ -141,7 +142,7 @@ def GetSpdGuidVersion(Dom, strip=0):
|
|||||||
gpath = ["PackageSurfaceArea", "SpdHeader", "GuidValue"]
|
gpath = ["PackageSurfaceArea", "SpdHeader", "GuidValue"]
|
||||||
vpath = ["PackageSurfaceArea", "SpdHeader", "Version"]
|
vpath = ["PackageSurfaceArea", "SpdHeader", "Version"]
|
||||||
|
|
||||||
return string.lower(XmlElement(Dom, "/".join(gpath[strip:]))), \
|
return Guid(XmlElement(Dom, "/".join(gpath[strip:]))), \
|
||||||
XmlElement(Dom, "/".join(vpath[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))
|
msa = XmlParseString(far.read(msafilePath))
|
||||||
|
|
||||||
for package in XmlList(msa, "/ModuleSurfaceArea/PackageDependencies/Package"):
|
for package in XmlList(msa, "/ModuleSurfaceArea/PackageDependencies/Package"):
|
||||||
guid = package.getAttribute("PackageGuid")
|
guid = Guid(package.getAttribute("PackageGuid"))
|
||||||
version = package.getAttribute("PackageVersion")
|
version = package.getAttribute("PackageVersion")
|
||||||
|
|
||||||
# Does anyone provide this package?
|
# Does anyone provide this package?
|
||||||
@ -215,7 +216,7 @@ def InstallFar(farfile, workspaceLocation=""):
|
|||||||
# Go through the dependencies
|
# Go through the dependencies
|
||||||
for dependency in XmlList(fpd, "/PlatformSurfaceArea/FrameworkModules/ModuleSA") + \
|
for dependency in XmlList(fpd, "/PlatformSurfaceArea/FrameworkModules/ModuleSA") + \
|
||||||
XmlList(fpd, "/PlatformSurfaceArea/FrameworkModules/ModuleSA/Libraries/Instance"):
|
XmlList(fpd, "/PlatformSurfaceArea/FrameworkModules/ModuleSA/Libraries/Instance"):
|
||||||
packagesNeeded.add((string.lower(dependency.getAttribute("PackageGuid")),
|
packagesNeeded.add((Guid(dependency.getAttribute("PackageGuid")),
|
||||||
dependency.getAttribute("PackageVersion")))
|
dependency.getAttribute("PackageVersion")))
|
||||||
|
|
||||||
# Let's see if all the packages are in the workspace
|
# Let's see if all the packages are in the workspace
|
||||||
@ -228,7 +229,7 @@ def InstallFar(farfile, workspaceLocation=""):
|
|||||||
installError = True
|
installError = True
|
||||||
|
|
||||||
# Check the fars
|
# Check the fars
|
||||||
thisFarGuid = string.lower(XmlElement(manifest, "/FrameworkArchiveManifest/FarHeader/GuidValue"))
|
thisFarGuid = Guid(XmlElement(manifest, "/FrameworkArchiveManifest/FarHeader/GuidValue"))
|
||||||
if fdb.HasFar(thisFarGuid):
|
if fdb.HasFar(thisFarGuid):
|
||||||
if not flags.reinstall:
|
if not flags.reinstall:
|
||||||
print "Error: There is a far with this guid already installed."
|
print "Error: There is a far with this guid already installed."
|
||||||
@ -301,7 +302,7 @@ if __name__ == '__main__':
|
|||||||
flags = Flags()
|
flags = Flags()
|
||||||
|
|
||||||
# Process the command line args.
|
# 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.
|
# First pass through the options list.
|
||||||
for o, a in optlist:
|
for o, a in optlist:
|
||||||
@ -314,6 +315,8 @@ if __name__ == '__main__':
|
|||||||
optlist.remove((o,a))
|
optlist.remove((o,a))
|
||||||
if o in ["-v", "--verbose"]:
|
if o in ["-v", "--verbose"]:
|
||||||
flags.verbose = True
|
flags.verbose = True
|
||||||
|
if o in ["-d", "--directory"]:
|
||||||
|
flags.dir = a
|
||||||
if o in ["-f", "--force"]:
|
if o in ["-f", "--force"]:
|
||||||
flags.force = True
|
flags.force = True
|
||||||
if o in ["--reinstall"]:
|
if o in ["--reinstall"]:
|
||||||
|
@ -25,9 +25,16 @@ class Far:
|
|||||||
far = Far()
|
far = Far()
|
||||||
"""The far object is constructed from the template file the user passed in."""
|
"""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."""
|
includes."""
|
||||||
|
|
||||||
filelist = [msaFile]
|
filelist = [msaFile]
|
||||||
@ -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 = [
|
xmlPaths = [
|
||||||
"/PackageSurfaceArea/LibraryClassDeclarations/LibraryClass/IncludeHeader",
|
"/PackageSurfaceArea/LibraryClassDeclarations/LibraryClass/IncludeHeader",
|
||||||
"/PackageSurfaceArea/IndustryStdIncludes/IndustryStdHeader/IncludeHeader",
|
"/PackageSurfaceArea/IndustryStdIncludes/IndustryStdHeader/IncludeHeader" ]
|
||||||
"/PackageSurfaceArea/PackageHeaders/IncludePkgHeader" ]
|
|
||||||
|
# These are covered by the Industry Standard Includes.
|
||||||
|
# "/PackageSurfaceArea/PackageHeaders/IncludePkgHeader"
|
||||||
|
|
||||||
for xmlPath in xmlPaths:
|
for xmlPath in xmlPaths:
|
||||||
for f in XmlList(spd, xmlPath):
|
for f in XmlList(spd, xmlPath):
|
||||||
@ -125,7 +138,10 @@ def makeFar(files, farname):
|
|||||||
contents = XmlAppendChildElement(top_element, "Contents")
|
contents = XmlAppendChildElement(top_element, "Contents")
|
||||||
XmlAppendChildElement(top_element, "UserExtensions")
|
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):
|
for infile in set(files):
|
||||||
if not os.path.exists(inWorkspace(infile)):
|
if not os.path.exists(inWorkspace(infile)):
|
||||||
print "Error: Non-existent file '%s'." % infile
|
print "Error: Non-existent file '%s'." % infile
|
||||||
@ -139,7 +155,7 @@ def makeFar(files, farname):
|
|||||||
|
|
||||||
package = XmlAppendChildElement(packList, "FarPackage")
|
package = XmlAppendChildElement(packList, "FarPackage")
|
||||||
XmlAppendChildElement(package, "FarFilename", lean(infile), {"Md5Sum": Md5(inWorkspace(infile))})
|
XmlAppendChildElement(package, "FarFilename", lean(infile), {"Md5Sum": Md5(inWorkspace(infile))})
|
||||||
zip.write(inWorkspace(infile), infile)
|
AddToZip(zip, infile)
|
||||||
XmlAppendChildElement(package, "GuidValue", spdGuid)
|
XmlAppendChildElement(package, "GuidValue", spdGuid)
|
||||||
XmlAppendChildElement(package, "Version", spdVersion)
|
XmlAppendChildElement(package, "Version", spdVersion)
|
||||||
XmlAppendChildElement(package, "DefaultPath", spdDir)
|
XmlAppendChildElement(package, "DefaultPath", spdDir)
|
||||||
@ -149,17 +165,17 @@ def makeFar(files, farname):
|
|||||||
|
|
||||||
for spdfile in filelist:
|
for spdfile in filelist:
|
||||||
XmlAppendChildElement(packContents, "FarFilename", lean(spdfile), {"Md5Sum": Md5(inWorkspace(os.path.join(spdDir, spdfile)))})
|
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":
|
elif extension == ".fpd":
|
||||||
|
|
||||||
platform = XmlAppendChildElement(platList, "FarPlatform")
|
platform = XmlAppendChildElement(platList, "FarPlatform")
|
||||||
XmlAppendChildElement(platform, "FarFilename", lean(infile), {"Md5Sum": Md5(inWorkspace(infile))})
|
XmlAppendChildElement(platform, "FarFilename", lean(infile), {"Md5Sum": Md5(inWorkspace(infile))})
|
||||||
zip.write(inWorkspace(infile), infile)
|
AddToZip(zip, infile)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
XmlAppendChildElement(contents, "FarFilename", lean(infile), {"Md5Sum": Md5(inWorkspace(infile))})
|
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.writestr("FrameworkArchiveManifest.xml", man.toxml('UTF-8'))
|
||||||
zip.close()
|
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.
|
# Second pass through the options list. These can override the first pass.
|
||||||
for o, a in optlist:
|
for o, a in optlist:
|
||||||
print o, a
|
|
||||||
if o in ["-o", "--far", "--output"]:
|
if o in ["-o", "--far", "--output"]:
|
||||||
far.FileName = a
|
far.FileName = a
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ def genguid():
|
|||||||
getpass.getuser() +
|
getpass.getuser() +
|
||||||
str(time.time()) +
|
str(time.time()) +
|
||||||
socket.gethostbyname(socket.gethostname())).hexdigest()
|
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):
|
def lean(path):
|
||||||
"""Lean the slashes forward"""
|
"""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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user