diff options
author | bbahnsen <bbahnsen@6f19259b-4bc3-4df7-8a09-765794883524> | 2006-12-16 06:39:33 +0000 |
---|---|---|
committer | bbahnsen <bbahnsen@6f19259b-4bc3-4df7-8a09-765794883524> | 2006-12-16 06:39:33 +0000 |
commit | e853a9d4831ae95363ce5fdcce71cbb23aff2269 (patch) | |
tree | a21188fcb0911fe246c22d3cf487ce3f709fa914 /Tools/Python | |
parent | ddb3d91caf129581e6686cd5127ca3517faca16e (diff) | |
download | edk2-platforms-e853a9d4831ae95363ce5fdcce71cbb23aff2269.tar.xz |
Add a far maker
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@2103 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'Tools/Python')
-rwxr-xr-x | Tools/Python/MkFar.py | 85 | ||||
-rwxr-xr-x | Tools/Python/WorkspaceRoutines.py | 21 | ||||
-rwxr-xr-x | Tools/Python/XmlRoutines.py | 5 |
3 files changed, 111 insertions, 0 deletions
diff --git a/Tools/Python/MkFar.py b/Tools/Python/MkFar.py new file mode 100755 index 0000000000..1dba1fc4aa --- /dev/null +++ b/Tools/Python/MkFar.py @@ -0,0 +1,85 @@ +#!/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): + + filelist = [] + + 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): + + filelist = [spdFile] + msaFileList = [] + + spdDir = os.path.dirname(spdFile) + + spd = xml.dom.minidom.parse(inWorkspace(spdFile)) + + xmlPaths = [ + "/PackageSurfaceArea/LibraryClassDeclarations/LibraryClass/IncludeHeader", + "/PackageSurfaceArea/IndustryStdIncludes/IndustryStdHeader/IncludeHeader", + "/PackageSurfaceArea/<PackageHeaders/IncludePkgHeader" ] + + for xmlPath in xmlPaths: + for f in XmlList(spd, xmlPath): + filelist.append(str(os.path.join(spdDir, XmlElementData(f)))) + + for xmlPath in ["/PackageSurfaceArea/MsaFiles/Filename"]: + for f in XmlList(spd, xmlPath): + msaFile = str(os.path.join(spdDir, XmlElementData(f))) + filelist.append(msaFile) + + filelist += parseMsa(msaFile, spdDir) + + return filelist + +def makeFar(filelist, farname): + + man = \ +"""<?xml version="1.0" encoding="UTF-8"?> +<FrameworkArchiveManifest> +</FrameworkArchiveManifest> +""" + zip = zipfile.ZipFile(farname, "w") + for file in args: + if not os.path.exists(inWorkspace(file)): + print "Skipping non-existent file '%s'." % file + (_, extension) = os.path.splitext(file) + if extension == ".spd": + filelist = parseSpd(file) + elif extension == ".fpd": + filelist = [file] + else: + filelist = [] + for f in set(filelist): + zip.write(inWorkspace(f), f) + zip.writestr("FrameworkArchiveManifest.xml", man) + zip.close() + return + +# This acts like the main() function for the script, unless it is 'import'ed into another +# script. +if __name__ == '__main__': + + # Create a pretty printer for dumping data structures in a readable form. + # pp = pprint.PrettyPrinter(indent=2) + + # Process the command line args. + optlist, args = getopt.getopt(sys.argv[1:], 'h', [ 'example-long-arg=', 'testing']) + + makeFar(args, "test.far") diff --git a/Tools/Python/WorkspaceRoutines.py b/Tools/Python/WorkspaceRoutines.py new file mode 100755 index 0000000000..c919065fc3 --- /dev/null +++ b/Tools/Python/WorkspaceRoutines.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python + +import os, sys, re, getopt, string, glob, xml.dom.minidom, pprint, md5, socket, getpass, time, random + +def inWorkspace(rel_path=""): + """Treat the given path as relative to the workspace.""" + + # Make sure the user has set the workspace variable: + try: + return os.path.join(os.environ["WORKSPACE"], rel_path ) + except: + print "Oops! You must set the WORKSPACE environment variable to run this script." + sys.exit() + +def genguid(): + g = md5.md5( + str(random.random()) + + 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:]) diff --git a/Tools/Python/XmlRoutines.py b/Tools/Python/XmlRoutines.py index 20671ea407..6968f14aef 100755 --- a/Tools/Python/XmlRoutines.py +++ b/Tools/Python/XmlRoutines.py @@ -42,6 +42,11 @@ def XmlAttribute (Dom, String): except: return '' +def XmlTopTag(Dom): + """Return the name of the Root or top tag in the XML tree.""" + return Dom.firstChild.nodeName + + # This acts like the main() function for the script, unless it is 'import'ed into another # script. if __name__ == '__main__': |