]>
Commit | Line | Data |
---|---|---|
1 | #!/usr/bin/env python | |
2 | ||
3 | import os, sys, re, getopt, string, glob, xml.dom.minidom, pprint, zipfile, tempfile | |
4 | from XmlRoutines import * | |
5 | from WorkspaceRoutines import * | |
6 | ||
7 | def parseMsa(msaFile, spdDir): | |
8 | ||
9 | filelist = [msaFile] | |
10 | ||
11 | msaDir = os.path.dirname(msaFile) | |
12 | ||
13 | msa = xml.dom.minidom.parse(inWorkspace(msaFile)) | |
14 | ||
15 | xmlPaths = [ | |
16 | "/ModuleSurfaceArea/SourceFiles/Filename" ] | |
17 | ||
18 | for xmlPath in xmlPaths: | |
19 | for f in XmlList(msa, xmlPath): | |
20 | filelist.append(str(os.path.join(msaDir, XmlElementData(f)))) | |
21 | ||
22 | return filelist | |
23 | ||
24 | def parseSpd(spdFile): | |
25 | ||
26 | filelist = [spdFile] | |
27 | msaFileList = [] | |
28 | ||
29 | spdDir = os.path.dirname(spdFile) | |
30 | ||
31 | spd = xml.dom.minidom.parse(inWorkspace(spdFile)) | |
32 | ||
33 | xmlPaths = [ | |
34 | "/PackageSurfaceArea/LibraryClassDeclarations/LibraryClass/IncludeHeader", | |
35 | "/PackageSurfaceArea/IndustryStdIncludes/IndustryStdHeader/IncludeHeader", | |
36 | "/PackageSurfaceArea/<PackageHeaders/IncludePkgHeader" ] | |
37 | ||
38 | for xmlPath in xmlPaths: | |
39 | for f in XmlList(spd, xmlPath): | |
40 | filelist.append(str(os.path.join(spdDir, XmlElementData(f)))) | |
41 | ||
42 | for f in XmlList(spd, "/PackageSurfaceArea/MsaFiles/Filename"): | |
43 | msaFile = str(os.path.join(spdDir, XmlElementData(f))) | |
44 | filelist += parseMsa(msaFile, spdDir) | |
45 | ||
46 | return filelist | |
47 | ||
48 | def makeFar(filelist, farname): | |
49 | ||
50 | domImpl = xml.dom.minidom.getDOMImplementation() | |
51 | man = domImpl.createDocument(None, "FrameworkArchiveManifest", None) | |
52 | top_element = man.documentElement | |
53 | ||
54 | header = man.createElement("FarHeader") | |
55 | top_element.appendChild(header) | |
56 | ||
57 | packList = man.createElement("FarPackageList") | |
58 | top_element.appendChild(packList) | |
59 | ||
60 | platList = man.createElement("FarPlatformList") | |
61 | top_element.appendChild(platList) | |
62 | ||
63 | contents = man.createElement("Contents") | |
64 | top_element.appendChild(contents) | |
65 | ||
66 | zip = zipfile.ZipFile(farname, "w") | |
67 | for infile in filelist: | |
68 | if not os.path.exists(inWorkspace(infile)): | |
69 | print "Skipping non-existent file '%s'." % infile | |
70 | (_, extension) = os.path.splitext(infile) | |
71 | if extension == ".spd": | |
72 | filelist = parseSpd(infile) | |
73 | ||
74 | package = man.createElement("FarPackage") | |
75 | packList.appendChild(package) | |
76 | ||
77 | spdfilename = man.createElement("FarFilename") | |
78 | package.appendChild(spdfilename) | |
79 | ||
80 | spdfilename.appendChild( man.createTextNode(infile) ) | |
81 | ||
82 | for spdfile in filelist: | |
83 | content = man.createElement("FarFilename") | |
84 | content.appendChild( man.createTextNode(spdfile)) | |
85 | contents.appendChild(content) | |
86 | ||
87 | elif extension == ".fpd": | |
88 | filelist = [infile] | |
89 | ||
90 | platform = man.createElement("FarPlatform") | |
91 | platList.appendChild(platform) | |
92 | ||
93 | fpdfilename = man.createElement("FarFilename") | |
94 | platform.appendChild(fpdfilename) | |
95 | ||
96 | fpdfilename.appendChild( man.createTextNode(infile) ) | |
97 | ||
98 | else: | |
99 | filelist = [] | |
100 | content = man.createElement("FarFilename") | |
101 | content.appendChild( man.createTextNode(infile)) | |
102 | contents.appendChild(content) | |
103 | ||
104 | for f in set(filelist): | |
105 | zip.write(inWorkspace(f), f) | |
106 | zip.writestr("FrameworkArchiveManifest.xml", man.toprettyxml(" ")) | |
107 | zip.close() | |
108 | return | |
109 | ||
110 | # This acts like the main() function for the script, unless it is 'import'ed into another | |
111 | # script. | |
112 | if __name__ == '__main__': | |
113 | ||
114 | # Create a pretty printer for dumping data structures in a readable form. | |
115 | # pp = pprint.PrettyPrinter(indent=2) | |
116 | ||
117 | # Process the command line args. | |
118 | optlist, args = getopt.getopt(sys.argv[1:], 'h', [ 'example-long-arg=', 'testing']) | |
119 | ||
120 | makeFar(args, "test.far") |