4 from xml.dom.minidom import Document
6 def createFtags(doc, path, isrootpath=True):
8 create f-tags for packagemaker's contents.xml files recursively replacing
9 owner with "root" and group with "wheel" in each entry
12 statinfo = os.lstat(path)
13 isdir = stat.S_ISDIR(statinfo[0])
15 ftag = doc.createElement("f")
16 ftag.setAttribute("n",os.path.split(path)[1])
17 ftag.setAttribute("p","%d" % statinfo[0])
18 ftag.setAttribute("o","root")
19 ftag.setAttribute("g","wheel")
21 # we additionally have to create <mod>owner</mod> and <mod>group</mod>
23 ftag.appendChild(doc.createElement("mod").appendChild(doc.createTextNode("owner")))
24 ftag.appendChild(doc.createElement("mod").appendChild(doc.createTextNode("group")))
27 # needs to be the full path
28 ftag.setAttribute("pt",os.path.abspath(path))
29 # no idea what those attributes mean:
30 ftag.setAttribute("m","false")
31 ftag.setAttribute("t","file")
34 for item in os.listdir(path):
35 ftag.appendChild(createFtags(doc, os.path.join(path,item), False))
39 def generateContentsDocument(path):
41 create new minidom document and generate contents by recursively traver-
46 root = doc.createElement("pkg-contents")
47 root.setAttribute("spec","1.12")
48 root.appendChild(createFtags(doc, path))
53 if __name__ == "__main__":
55 doc = generateContentsDocument(sys.argv[1])
56 print doc.toprettyxml(indent=" "),