2006-12-16 07:39:33 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
import os, sys, re, getopt, string, glob, xml.dom.minidom, pprint, zipfile, tempfile
|
|
|
|
from XmlRoutines import *
|
|
|
|
from WorkspaceRoutines import *
|
|
|
|
|
|
|
|
def parseMsa(msaFile, spdDir):
|
|
|
|
|
2006-12-16 08:50:00 +01:00
|
|
|
filelist = [msaFile]
|
2006-12-16 07:39:33 +01:00
|
|
|
|
|
|
|
msaDir = os.path.dirname(msaFile)
|
|
|
|
|
|
|
|
msa = xml.dom.minidom.parse(inWorkspace(msaFile))
|
|
|
|
|
|
|
|
xmlPaths = [
|
|
|
|
"/ModuleSurfaceArea/SourceFiles/Filename" ]
|
|
|
|
|
|
|
|
for xmlPath in xmlPaths:
|
|
|
|
for f in XmlList(msa, xmlPath):
|
|
|
|
filelist.append(str(os.path.join(msaDir, XmlElementData(f))))
|
|
|
|
|
|
|
|
return filelist
|
|
|
|
|
|
|
|
def parseSpd(spdFile):
|
|
|
|
|
2006-12-16 21:51:59 +01:00
|
|
|
filelist = []
|
2006-12-16 07:39:33 +01:00
|
|
|
|
|
|
|
spdDir = os.path.dirname(spdFile)
|
|
|
|
|
|
|
|
spd = xml.dom.minidom.parse(inWorkspace(spdFile))
|
|
|
|
|
|
|
|
xmlPaths = [
|
|
|
|
"/PackageSurfaceArea/LibraryClassDeclarations/LibraryClass/IncludeHeader",
|
|
|
|
"/PackageSurfaceArea/IndustryStdIncludes/IndustryStdHeader/IncludeHeader",
|
2006-12-16 21:51:59 +01:00
|
|
|
"/PackageSurfaceArea/PackageHeaders/IncludePkgHeader" ]
|
2006-12-16 07:39:33 +01:00
|
|
|
|
|
|
|
for xmlPath in xmlPaths:
|
|
|
|
for f in XmlList(spd, xmlPath):
|
|
|
|
filelist.append(str(os.path.join(spdDir, XmlElementData(f))))
|
|
|
|
|
2006-12-16 09:28:47 +01:00
|
|
|
for f in XmlList(spd, "/PackageSurfaceArea/MsaFiles/Filename"):
|
|
|
|
msaFile = str(os.path.join(spdDir, XmlElementData(f)))
|
|
|
|
filelist += parseMsa(msaFile, spdDir)
|
2006-12-16 07:39:33 +01:00
|
|
|
|
|
|
|
return filelist
|
|
|
|
|
|
|
|
def makeFar(filelist, farname):
|
|
|
|
|
2006-12-16 08:50:00 +01:00
|
|
|
domImpl = xml.dom.minidom.getDOMImplementation()
|
|
|
|
man = domImpl.createDocument(None, "FrameworkArchiveManifest", None)
|
|
|
|
top_element = man.documentElement
|
|
|
|
|
|
|
|
header = man.createElement("FarHeader")
|
|
|
|
top_element.appendChild(header)
|
2006-12-16 09:28:47 +01:00
|
|
|
|
2006-12-16 08:50:00 +01:00
|
|
|
packList = man.createElement("FarPackageList")
|
|
|
|
top_element.appendChild(packList)
|
2006-12-16 09:28:47 +01:00
|
|
|
|
2006-12-16 08:50:00 +01:00
|
|
|
platList = man.createElement("FarPlatformList")
|
|
|
|
top_element.appendChild(platList)
|
2006-12-16 09:28:47 +01:00
|
|
|
|
2006-12-16 08:50:00 +01:00
|
|
|
contents = man.createElement("Contents")
|
|
|
|
top_element.appendChild(contents)
|
2006-12-16 09:28:47 +01:00
|
|
|
|
2006-12-16 07:39:33 +01:00
|
|
|
zip = zipfile.ZipFile(farname, "w")
|
2006-12-16 09:28:47 +01:00
|
|
|
for infile in filelist:
|
|
|
|
if not os.path.exists(inWorkspace(infile)):
|
|
|
|
print "Skipping non-existent file '%s'." % infile
|
|
|
|
(_, extension) = os.path.splitext(infile)
|
2006-12-16 07:39:33 +01:00
|
|
|
if extension == ".spd":
|
2006-12-16 09:28:47 +01:00
|
|
|
filelist = parseSpd(infile)
|
2006-12-16 08:50:00 +01:00
|
|
|
|
2006-12-16 09:28:47 +01:00
|
|
|
package = man.createElement("FarPackage")
|
|
|
|
packList.appendChild(package)
|
2006-12-16 08:50:00 +01:00
|
|
|
|
2006-12-16 09:28:47 +01:00
|
|
|
spdfilename = man.createElement("FarFilename")
|
|
|
|
package.appendChild(spdfilename)
|
2006-12-16 08:50:00 +01:00
|
|
|
|
2006-12-16 09:28:47 +01:00
|
|
|
spdfilename.appendChild( man.createTextNode(infile) )
|
2006-12-16 21:51:59 +01:00
|
|
|
zip.write(inWorkspace(infile), infile)
|
2006-12-16 09:28:47 +01:00
|
|
|
|
|
|
|
for spdfile in filelist:
|
|
|
|
content = man.createElement("FarFilename")
|
|
|
|
content.appendChild( man.createTextNode(spdfile))
|
|
|
|
contents.appendChild(content)
|
2006-12-16 21:51:59 +01:00
|
|
|
zip.write(inWorkspace(spdfile), spdfile)
|
2006-12-16 08:50:00 +01:00
|
|
|
|
2006-12-16 07:39:33 +01:00
|
|
|
elif extension == ".fpd":
|
2006-12-16 09:28:47 +01:00
|
|
|
|
|
|
|
platform = man.createElement("FarPlatform")
|
|
|
|
platList.appendChild(platform)
|
|
|
|
|
|
|
|
fpdfilename = man.createElement("FarFilename")
|
|
|
|
platform.appendChild(fpdfilename)
|
|
|
|
|
|
|
|
fpdfilename.appendChild( man.createTextNode(infile) )
|
2006-12-16 21:51:59 +01:00
|
|
|
zip.write(inWorkspace(infile), infile)
|
2006-12-16 09:28:47 +01:00
|
|
|
|
2006-12-16 07:39:33 +01:00
|
|
|
else:
|
2006-12-16 21:51:59 +01:00
|
|
|
print "Skipping file '%s' since is is not a .spd or .fpd." % infile
|
2006-12-16 09:28:47 +01:00
|
|
|
|
2006-12-16 20:15:09 +01:00
|
|
|
zip.writestr("FrameworkArchiveManifest.xml", man.toprettyxml(2*" "))
|
2006-12-16 07:39:33 +01:00
|
|
|
zip.close()
|
|
|
|
return
|
|
|
|
|
2006-12-16 20:15:09 +01:00
|
|
|
# This acts like the main() function for the script, unless it is 'import'ed
|
|
|
|
# into another script.
|
2006-12-16 07:39:33 +01:00
|
|
|
if __name__ == '__main__':
|
|
|
|
|
|
|
|
# Create a pretty printer for dumping data structures in a readable form.
|
|
|
|
# pp = pprint.PrettyPrinter(indent=2)
|
|
|
|
|
2006-12-16 20:15:09 +01:00
|
|
|
# Default name for far file.
|
|
|
|
farName = "output.far"
|
|
|
|
|
2006-12-16 07:39:33 +01:00
|
|
|
# Process the command line args.
|
2006-12-16 20:15:09 +01:00
|
|
|
optlist, args = getopt.getopt(sys.argv[1:], 'hf:', [ 'far=', 'help'])
|
|
|
|
|
|
|
|
for o, a in optlist:
|
|
|
|
if o in ["-h", "--help"]:
|
|
|
|
print """
|
|
|
|
Pass a list of .spd and .fpd files to be placed into a far for distribution.
|
|
|
|
You may give the name of the far with a -f or --far option. For example:
|
|
|
|
|
|
|
|
%s --far library.far MdePkg/MdePkg.spd
|
|
|
|
|
|
|
|
The file paths of .spd and .fpd are relative to the WORKSPACE envirnonment
|
|
|
|
which must be set to a valid workspace root directory.
|
|
|
|
""" % os.path.basename(sys.argv[0])
|
|
|
|
|
|
|
|
sys.exit()
|
|
|
|
if o in ["-f", "--far"]:
|
|
|
|
farName = a
|
2006-12-16 07:39:33 +01:00
|
|
|
|
2006-12-16 20:15:09 +01:00
|
|
|
makeFar(args, farName)
|