Release 0.18
[0publish.git] / mimetypes.py
blobb953b85973e8d1ba72173791bd7a8c719f3b5831
1 from xml.dom import minidom
2 from zeroinstall.injector import namespaces
3 from zeroinstall.zerostore import manifest, Stores, NotStored
4 import xmltools
5 from logging import info
7 stores = Stores()
9 def add_types(data):
10 doc = minidom.parseString(data)
12 changed = False
13 for archive in doc.documentElement.getElementsByTagNameNS(namespaces.XMLNS_IFACE, 'archive'):
14 href = archive.getAttribute('href')
15 type = archive.getAttribute('type')
17 if not type:
18 if href.endswith('.tar.bz2'):
19 type = "application/x-bzip-compressed-tar"
20 elif href.endswith('.tgz'):
21 type = "application/x-compressed-tar"
22 else:
23 raise Exception("Can't guess type for " + href)
24 archive.setAttribute('type', type)
25 changed = True
27 if changed:
28 return doc.toxml()
29 else:
30 return data