1 from xml
.dom
import minidom
2 from zeroinstall
.injector
import namespaces
, model
5 date_format
= '\d{4}-\d{2}-\d{2}'
7 def make_release(data
, id, version
, released
, stability
, main
, arch
):
8 """Normally there's only one implementation, but we can cope with several."""
9 if released
and released
!= 'Snapshot' and not re
.match(date_format
, released
):
10 raise Exception('Invalid date format. Use YYYY-MM-DD.')
12 doc
= minidom
.parseString(data
)
14 all_impls
= doc
.documentElement
.getElementsByTagNameNS(namespaces
.XMLNS_IFACE
, 'implementation')
16 _released
= x
.getAttribute('released')
17 if released
is None or not re
.match(date_format
, _released
):
19 raise Exception('Multiple unreleased implementations!')
21 if unreleased
is None:
22 if len(all_impls
) == 0:
23 raise Exception('No implementations in interface file!')
24 if len(all_impls
) > 1:
25 raise Exception("Multiple implementations, but all are released. Aborting.")
26 unreleased
= all_impls
[0]
28 # In future, we may want to bulk change implementations...
29 for x
in [unreleased
]:
30 if id is not None: x
.setAttribute('id', id)
31 if version
is not None: x
.setAttribute('version', version
)
32 if released
is not None: x
.setAttribute('released', released
)
33 if stability
is not None: x
.setAttribute('stability', stability
)
34 if main
is not None: x
.setAttribute('main', main
)
35 if arch
is not None: x
.setAttribute('arch', arch
)