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.
8 from zeroinstall
import _
10 from xml
.dom
import minidom
, XMLNS_NAMESPACE
12 from zeroinstall
.support
import basedir
14 from zeroinstall
.injector
import model
15 from zeroinstall
.injector
.namespaces
import config_site
, config_prog
, XMLNS_IFACE
16 from zeroinstall
.injector
.iface_cache
import iface_cache
18 def _atomic_save(doc
, parent
, uri
):
20 tmp_fd
, tmp_name
= tempfile
.mkstemp(dir = parent
)
22 tmp_file
= os
.fdopen(tmp_fd
, 'w')
23 doc
.writexml(tmp_file
, addindent
= " ", newl
= '\n')
25 path
= os
.path
.join(parent
, model
._pretty
_escape
(uri
))
26 os
.rename(tmp_name
, path
)
32 """Save information about a feed. Currently, this is the last_checked time and any user-set stability ratings.
34 feeds
= basedir
.save_config_path(config_site
, config_prog
, 'feeds')
36 impl
= minidom
.getDOMImplementation()
37 doc
= impl
.createDocument(XMLNS_IFACE
, 'feed-preferences', None)
38 root
= doc
.documentElement
39 root
.setAttributeNS(XMLNS_NAMESPACE
, 'xmlns', XMLNS_IFACE
)
42 root
.setAttribute('last-checked', str(feed
.last_checked
))
44 impls
= feed
.implementations
.values()
47 if impl
.user_stability
:
48 node
= doc
.createElementNS(XMLNS_IFACE
, 'implementation')
49 root
.appendChild(node
)
50 node
.setAttribute('user-stability', str(impl
.user_stability
))
51 node
.setAttribute('id', impl
.id)
53 _atomic_save(doc
, feeds
, feed
.url
)
55 def save_interface(interface
):
56 user_overrides
= basedir
.save_config_path(config_site
, config_prog
, 'interfaces')
58 impl
= minidom
.getDOMImplementation()
59 doc
= impl
.createDocument(XMLNS_IFACE
, 'interface-preferences', None)
61 root
= doc
.documentElement
62 root
.setAttributeNS(XMLNS_NAMESPACE
, 'xmlns', XMLNS_IFACE
)
63 root
.setAttribute('uri', interface
.uri
)
65 if interface
.stability_policy
:
66 root
.setAttribute('stability-policy', str(interface
.stability_policy
))
68 for feed
in interface
.extra_feeds
:
69 if feed
.user_override
:
70 elem
= doc
.createElementNS(XMLNS_IFACE
, 'feed')
71 root
.appendChild(elem
)
72 elem
.setAttribute('src', feed
.uri
)
74 elem
.setAttribute('arch', feed
.arch
)
76 _atomic_save(doc
, user_overrides
, interface
.uri
)