+ def fix_part(self, child, master, typ_, audience_, commit_args):
+ print "checking child %s" % child.slug
+ fc = child[0]
+ txt = fc.materialize()
+ changed = False
+ try:
+ t = etree.fromstring(txt)
+ except etree.XMLSyntaxError, e:
+ print "cannot read xml in part: %s" % child.slug
+ print unicode(e)
+ return
+ typ = t.xpath("//dc:type", namespaces=dc_namespaces)
+ if not typ:
+ print "no type in DC, inserting under format"
+ fmt = t.xpath("//dc:format", namespaces=dc_namespaces)
+ container = fmt.getparent()
+ typ = etree.SubElement(container, etree.QName('dc', 'type'))
+ container.insert(typ, container.index(fmt)+1)
+ changed = True
+ else:
+ typ = typ[0]
+ if typ.text != typ_:
+ print "type is '%s', setting to '%s'" % (typ.text, typ_)
+ changed = True
+ typ.text = typ_
+ audience = t.xpath("//dc:audience", namespaces=dc_namespaces)[0]
+ if audience.text != audience_:
+ print "audience is '%s', setting to '%s'" % (audience.text, audience_)
+ changed = True
+ audience.text = audience_
+ if changed:
+ print "will commit."
+ fc.commit(etree.tostring(t, encoding=unicode), **commit_args)
+
+