Use portable_rename to support Windows
[0publish.git] / mimetypes.py
blob48ad47efe1e13bc80b528b697ca9ba00ec05e4cb
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') or href.endswith('.tar.gz'):
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('utf-8')
29 else:
30 return data