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
17 def _atomic_save(doc
, parent
, uri
):
19 tmp_fd
, tmp_name
= tempfile
.mkstemp(dir = parent
)
21 tmp_file
= os
.fdopen(tmp_fd
, 'w')
22 doc
.writexml(tmp_file
, addindent
= " ", newl
= '\n')
24 path
= os
.path
.join(parent
, model
._pretty
_escape
(uri
))
25 os
.rename(tmp_name
, path
)
31 """Save information about a feed. Currently, this is the last_checked time and any user-set stability ratings.
33 feeds
= basedir
.save_config_path(config_site
, config_prog
, 'feeds')
35 impl
= minidom
.getDOMImplementation()
36 doc
= impl
.createDocument(XMLNS_IFACE
, 'feed-preferences', None)
37 root
= doc
.documentElement
38 root
.setAttributeNS(XMLNS_NAMESPACE
, 'xmlns', XMLNS_IFACE
)
41 root
.setAttribute('last-checked', str(feed
.last_checked
))
43 impls
= feed
.implementations
.values()
46 if impl
.user_stability
:
47 node
= doc
.createElementNS(XMLNS_IFACE
, 'implementation')
48 root
.appendChild(node
)
49 node
.setAttribute('user-stability', str(impl
.user_stability
))
50 node
.setAttribute('id', impl
.id)
52 _atomic_save(doc
, feeds
, feed
.url
)
54 def save_interface(interface
):
55 user_overrides
= basedir
.save_config_path(config_site
, config_prog
, 'interfaces')
57 impl
= minidom
.getDOMImplementation()
58 doc
= impl
.createDocument(XMLNS_IFACE
, 'interface-preferences', None)
60 root
= doc
.documentElement
61 root
.setAttributeNS(XMLNS_NAMESPACE
, 'xmlns', XMLNS_IFACE
)
62 root
.setAttribute('uri', interface
.uri
)
64 if interface
.stability_policy
:
65 root
.setAttribute('stability-policy', str(interface
.stability_policy
))
67 for feed
in interface
.extra_feeds
:
68 if feed
.user_override
:
69 elem
= doc
.createElementNS(XMLNS_IFACE
, 'feed')
70 root
.appendChild(elem
)
71 elem
.setAttribute('src', feed
.uri
)
73 elem
.setAttribute('arch', feed
.arch
)
75 _atomic_save(doc
, user_overrides
, interface
.uri
)