Unpack archives to tmp dir.
[zeroinstall.git] / writer.py
bloba97b6138aaebe92eeef501d582eb28188d6796f0
1 import os
2 from xml.dom import minidom, XMLNS_NAMESPACE
4 import basedir
6 from model import *
8 from namespaces import config_site, config_prog, XMLNS_IFACE
10 def add_text(parent, name, text):
11 doc = parent.ownerDocument
12 element = doc.createElementNS(XMLNS_IFACE, name)
13 parent.appendChild(element)
14 element.appendChild(doc.createTextNode(text))
16 def add_impl(parent, impl):
17 if impl.user_stability:
18 doc = parent.ownerDocument
19 node = doc.createElementNS(XMLNS_IFACE, 'implementation')
20 parent.appendChild(node)
21 node.setAttribute('user-stability', str(impl.user_stability))
22 node.setAttribute('path', impl.path)
24 def save_interface(interface):
25 path = basedir.save_config_path(config_site, config_prog, 'user_overrides')
26 path = os.path.join(path, escape(interface.uri))
27 #print "Save to", path
29 impl = minidom.getDOMImplementation()
30 doc = impl.createDocument(XMLNS_IFACE, 'interface', None)
32 root = doc.documentElement
33 root.setAttributeNS(XMLNS_NAMESPACE, 'xmlns', XMLNS_IFACE)
34 root.setAttribute('uri', interface.uri)
36 if interface.stability_policy:
37 root.setAttribute('stability-policy', str(interface.stability_policy))
39 if interface.last_checked:
40 root.setAttribute('last-checked', str(interface.last_checked))
42 impls = interface.implementations.values()
43 impls.sort()
44 for impl in impls:
45 add_impl(root, impl)
47 doc.writexml(file(path + '.new', 'w'), addindent = " ", newl = '\n')
48 os.rename(path + '.new', path)