Fixed typo in error message
[0publish.git] / stable.py
blob26da2686a1e3885c68b06918d2d2c2fdcd2d8692
1 from xml.dom import minidom
2 from zeroinstall.injector import namespaces, model
3 from logging import warn
5 def mark_stable(data):
6 """Find the single release marked as 'testing' and make it 'stable'."""
7 doc = minidom.parseString(data)
8 testing = []
9 all_impls = doc.documentElement.getElementsByTagNameNS(namespaces.XMLNS_IFACE, 'implementation')
10 for x in all_impls:
11 if get_stability(x) == 'testing':
12 testing.append((get_version(x), x))
13 if len(testing) == 0:
14 raise Exception('No implementations are currently "testing"!')
16 testing = sorted(testing)
17 higest_version = testing[-1][0]
18 latest_testing = [impl for version, impl in testing if version == higest_version]
20 if len(latest_testing) < len(testing):
21 warn("Multiple 'testing' versions - changing %d (of %d) with version %s", len(latest_testing), len(testing), model.format_version(higest_version))
23 for impl in latest_testing:
24 impl.setAttribute('stability', 'stable')
26 return doc.toxml('utf-8')
28 def get_stability(x):
29 root = x.ownerDocument.documentElement
30 while x is not root:
31 stab = x.getAttribute('stability')
32 if stab: return stab
33 x = x.parentNode
34 return 'testing'
36 def get_version(x):
37 root = x.ownerDocument.documentElement
38 while x is not root:
39 version = x.getAttribute('version')
40 if version:
41 mod = x.getAttribute('version-modifier')
42 if mod: version += mod
43 return model.parse_version(version)
44 x = x.parentNode
45 raise Exception("No version on %s" % x)