e853a9d4 |
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 = [] |
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 xmlPath in ["/PackageSurfaceArea/MsaFiles/Filename"]: |
43 | for f in XmlList(spd, xmlPath): |
44 | msaFile = str(os.path.join(spdDir, XmlElementData(f))) |
45 | filelist.append(msaFile) |
46 | |
47 | filelist += parseMsa(msaFile, spdDir) |
48 | |
49 | return filelist |
50 | |
51 | def makeFar(filelist, farname): |
52 | |
53 | man = \ |
54 | """<?xml version="1.0" encoding="UTF-8"?> |
55 | <FrameworkArchiveManifest> |
56 | </FrameworkArchiveManifest> |
57 | """ |
58 | zip = zipfile.ZipFile(farname, "w") |
59 | for file in args: |
60 | if not os.path.exists(inWorkspace(file)): |
61 | print "Skipping non-existent file '%s'." % file |
62 | (_, extension) = os.path.splitext(file) |
63 | if extension == ".spd": |
64 | filelist = parseSpd(file) |
65 | elif extension == ".fpd": |
66 | filelist = [file] |
67 | else: |
68 | filelist = [] |
69 | for f in set(filelist): |
70 | zip.write(inWorkspace(f), f) |
71 | zip.writestr("FrameworkArchiveManifest.xml", man) |
72 | zip.close() |
73 | return |
74 | |
75 | # This acts like the main() function for the script, unless it is 'import'ed into another |
76 | # script. |
77 | if __name__ == '__main__': |
78 | |
79 | # Create a pretty printer for dumping data structures in a readable form. |
80 | # pp = pprint.PrettyPrinter(indent=2) |
81 | |
82 | # Process the command line args. |
83 | optlist, args = getopt.getopt(sys.argv[1:], 'h', [ 'example-long-arg=', 'testing']) |
84 | |
85 | makeFar(args, "test.far") |