2 Save per-interface and per-feed configuration information.
5 # Copyright (C) 2009, Thomas Leonard
6 # See the README file for details, or visit http://0install.net.
9 from xml
.dom
import minidom
, XMLNS_NAMESPACE
11 from zeroinstall
.support
import basedir
13 from zeroinstall
.injector
import model
14 from zeroinstall
.injector
.namespaces
import config_site
, config_prog
, XMLNS_IFACE
16 def _atomic_save(doc
, parent
, uri
):
18 tmp_fd
, tmp_name
= tempfile
.mkstemp(dir = parent
)
20 tmp_file
= os
.fdopen(tmp_fd
, 'w')
21 doc
.writexml(tmp_file
, addindent
= " ", newl
= '\n')
23 path
= os
.path
.join(parent
, model
._pretty
_escape
(uri
))
24 os
.rename(tmp_name
, path
)
30 """Save information about a feed. Currently, this is the last_checked time and any user-set stability ratings.
32 feeds
= basedir
.save_config_path(config_site
, config_prog
, 'feeds')
34 impl
= minidom
.getDOMImplementation()
35 doc
= impl
.createDocument(XMLNS_IFACE
, 'feed-preferences', None)
36 root
= doc
.documentElement
37 root
.setAttributeNS(XMLNS_NAMESPACE
, 'xmlns', XMLNS_IFACE
)
40 root
.setAttribute('last-checked', str(feed
.last_checked
))
42 impls
= feed
.implementations
.values()
45 if impl
.user_stability
:
46 node
= doc
.createElementNS(XMLNS_IFACE
, 'implementation')
47 root
.appendChild(node
)
48 node
.setAttribute('user-stability', str(impl
.user_stability
))
49 node
.setAttribute('id', impl
.id)
51 _atomic_save(doc
, feeds
, feed
.url
)
53 def save_interface(interface
):
54 user_overrides
= basedir
.save_config_path(config_site
, config_prog
, 'interfaces')
56 impl
= minidom
.getDOMImplementation()
57 doc
= impl
.createDocument(XMLNS_IFACE
, 'interface-preferences', None)
59 root
= doc
.documentElement
60 root
.setAttributeNS(XMLNS_NAMESPACE
, 'xmlns', XMLNS_IFACE
)
61 root
.setAttribute('uri', interface
.uri
)
63 if interface
.stability_policy
:
64 root
.setAttribute('stability-policy', str(interface
.stability_policy
))
66 for feed
in interface
.extra_feeds
:
67 if feed
.user_override
:
68 elem
= doc
.createElementNS(XMLNS_IFACE
, 'feed')
69 root
.appendChild(elem
)
70 elem
.setAttribute('src', feed
.uri
)
72 elem
.setAttribute('arch', feed
.arch
)
74 _atomic_save(doc
, user_overrides
, interface
.uri
)