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
== 'today': released
= time
.strftime('%Y-%m-%d')
10 if released
and released
!= 'Snapshot' and not re
.match(date_format
, released
):
11 raise Exception('Invalid date format. Use YYYY-MM-DD.')
13 doc
= minidom
.parseString(data
)
15 all_impls
= doc
.documentElement
.getElementsByTagNameNS(namespaces
.XMLNS_IFACE
, 'implementation')
17 _released
= x
.getAttribute('released')
18 if released
is None or not re
.match(date_format
, _released
):
20 raise Exception('Multiple unreleased implementations!')
22 if unreleased
is None:
23 if len(all_impls
) == 0:
24 raise Exception('No implementations in interface file!')
25 if len(all_impls
) > 1:
26 raise Exception("Multiple implementations, but all are released. Aborting.")
27 unreleased
= all_impls
[0]
29 # In future, we may want to bulk change implementations...
30 for x
in [unreleased
]:
31 if id is not None: x
.setAttribute('id', id)
32 if version
is not None: x
.setAttribute('version', version
)
33 if released
is not None: x
.setAttribute('released', released
)
34 if stability
is not None: x
.setAttribute('stability', stability
)
35 if main
is not None: x
.setAttribute('main', main
)
36 if arch
is not None: x
.setAttribute('arch', arch
)