1 # Copyright (C) 2006, Thomas Leonard
2 # See the README file for details, or visit http://0install.net.
5 from xml
.dom
import minidom
, XMLNS_NAMESPACE
11 from namespaces
import config_site
, config_prog
, XMLNS_IFACE
13 def _add_impl(parent
, impl
):
14 if impl
.user_stability
:
15 doc
= parent
.ownerDocument
16 node
= doc
.createElementNS(XMLNS_IFACE
, 'implementation')
17 parent
.appendChild(node
)
18 node
.setAttribute('user-stability', str(impl
.user_stability
))
19 node
.setAttribute('id', impl
.id)
21 def save_interface(interface
):
22 path
= basedir
.save_config_path(config_site
, config_prog
, 'user_overrides')
23 path
= os
.path
.join(path
, escape(interface
.uri
))
24 #print "Save to", path
26 impl
= minidom
.getDOMImplementation()
27 doc
= impl
.createDocument(XMLNS_IFACE
, 'interface-preferences', None)
29 root
= doc
.documentElement
30 root
.setAttributeNS(XMLNS_NAMESPACE
, 'xmlns', XMLNS_IFACE
)
31 root
.setAttribute('uri', interface
.uri
)
33 if interface
.stability_policy
:
34 root
.setAttribute('stability-policy', str(interface
.stability_policy
))
36 if interface
.last_checked
:
37 root
.setAttribute('last-checked', str(interface
.last_checked
))
39 impls
= interface
.implementations
.values()
44 for feed
in interface
.feeds
:
45 if feed
.user_override
:
46 elem
= doc
.createElementNS(XMLNS_IFACE
, 'feed')
47 root
.appendChild(elem
)
48 elem
.setAttribute('src', feed
.uri
)
50 elem
.setAttribute('arch', feed
.arch
)
52 doc
.writexml(file(path
+ '.new', 'w'), addindent
= " ", newl
= '\n')
53 os
.rename(path
+ '.new', path
)