1 from xml
.dom
import minidom
2 from zeroinstall
.injector
import namespaces
3 from zeroinstall
.zerostore
import manifest
, Stores
, NotStored
5 from logging
import info
10 yield impl
.getAttribute('id').split('=', 1)
11 for x
in xmltools
.children(impl
, 'manifest-digest'):
12 for name
, value
in x
.attributes
.itemsNS():
16 def get_version(impl
):
18 v
= impl
.getAttribute('version')
20 impl
= impl
.parentNode
22 def add_digest(impl
, alg_name
):
23 alg
= manifest
.get_algorithm(alg_name
)
25 # Scan through the existing digests
26 # - If we've already got the one we need, return
27 # - Otherwise, find a cached implementation we can use
29 for a
, value
in digests(impl
):
30 digest
= '%s=%s' % (a
, value
)
32 return False # Already signed with this algorithm
35 existing_path
= stores
.lookup(digest
)
37 existing_digest
= digest
41 if existing_path
is None:
42 print "No implementations of %s cached; can't calculate new digest" % get_version(impl
)
45 info("Verifying %s", existing_path
)
46 manifest
.verify(existing_path
, existing_digest
)
48 print "Adding new digest to version %s" % get_version(impl
)
50 new_digest
= alg
.new_digest()
51 for line
in alg
.generate_manifest(existing_path
):
52 new_digest
.update(line
+ '\n')
54 for md
in xmltools
.children(impl
, 'manifest-digest'):
57 md
= xmltools
.create_element(impl
, 'manifest-digest')
58 md
.setAttribute(alg_name
, new_digest
.hexdigest())
62 def add_digests(data
, alg
= None):
63 doc
= minidom
.parseString(data
)
69 for impl
in doc
.documentElement
.getElementsByTagNameNS(namespaces
.XMLNS_IFACE
, 'implementation'):
70 if impl
.getAttribute('id') in "./":
71 continue # Local implementation
73 if add_digest(impl
, alg
):