3 import os
, sys
, re
, getopt
, string
, glob
, xml
.dom
.minidom
, pprint
, zipfile
, tempfile
4 from XmlRoutines
import *
5 from WorkspaceRoutines
import *
7 def parseMsa(msaFile
, spdDir
):
11 msaDir
= os
.path
.dirname(msaFile
)
13 msa
= xml
.dom
.minidom
.parse(inWorkspace(msaFile
))
16 "/ModuleSurfaceArea/SourceFiles/Filename" ]
18 for xmlPath
in xmlPaths
:
19 for f
in XmlList(msa
, xmlPath
):
20 filelist
.append(str(os
.path
.join(msaDir
, XmlElementData(f
))))
24 def parseSpd(spdFile
):
29 spdDir
= os
.path
.dirname(spdFile
)
31 spd
= xml
.dom
.minidom
.parse(inWorkspace(spdFile
))
34 "/PackageSurfaceArea/LibraryClassDeclarations/LibraryClass/IncludeHeader",
35 "/PackageSurfaceArea/IndustryStdIncludes/IndustryStdHeader/IncludeHeader",
36 "/PackageSurfaceArea/<PackageHeaders/IncludePkgHeader" ]
38 for xmlPath
in xmlPaths
:
39 for f
in XmlList(spd
, xmlPath
):
40 filelist
.append(str(os
.path
.join(spdDir
, XmlElementData(f
))))
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
+= parseMsa(msaFile
, spdDir
)
49 def makeFar(filelist
, farname
):
52 """<?xml version="1.0" encoding="UTF-8"?>
53 <FrameworkArchiveManifest>
54 </FrameworkArchiveManifest>
57 domImpl
= xml
.dom
.minidom
.getDOMImplementation()
58 man
= domImpl
.createDocument(None, "FrameworkArchiveManifest", None)
59 top_element
= man
.documentElement
61 header
= man
.createElement("FarHeader")
62 top_element
.appendChild(header
)
64 packList
= man
.createElement("FarPackageList")
65 top_element
.appendChild(packList
)
67 platList
= man
.createElement("FarPlatformList")
68 top_element
.appendChild(platList
)
70 contents
= man
.createElement("Contents")
71 top_element
.appendChild(contents
)
73 zip = zipfile
.ZipFile(farname
, "w")
75 if not os
.path
.exists(inWorkspace(file)):
76 print "Skipping non-existent file '%s'." % file
77 (_
, extension
) = os
.path
.splitext(file)
78 if extension
== ".spd":
79 filelist
= parseSpd(file)
83 package
= man
.createElement("FarPackage")
84 packList
.appendChild(package
)
86 spdfilename
= man
.createElement("FarFileName")
87 package
.appendChild(spdfilename
)
89 spdfilename
.appendChild( man
.createTextNode(file) )
91 elif extension
== ".fpd":
95 for f
in set(filelist
):
96 zip.write(inWorkspace(f
), f
)
97 zip.writestr("FrameworkArchiveManifest.xml", man
.toprettyxml(" "))
101 # This acts like the main() function for the script, unless it is 'import'ed into another
103 if __name__
== '__main__':
105 # Create a pretty printer for dumping data structures in a readable form.
106 # pp = pprint.PrettyPrinter(indent=2)
108 # Process the command line args.
109 optlist
, args
= getopt
.getopt(sys
.argv
[1:], 'h', [ 'example-long-arg=', 'testing'])
111 makeFar(args
, "test.far")