def upgrade_series(root, data): series, series_index = None, '1.0' for meta in XPath('./opf:metadata/opf:meta[@name="calibre:series"]')(root): remove_element(meta, data.refines) series = meta.get('content') for meta in XPath('./opf:metadata/opf:meta[@name="calibre:series_index"]')(root): remove_element(meta, data.refines) series_index = meta.get('content') if series: create_series(root, data.refines, series, series_index)