def upgrade(pyramid_env): from assembl.models import Extract, TextFragmentIdentifier, Content, Post db = Extract.db() reg = re.compile(r"^//div\[@id='message-([0-9]+)'\](.*)") with transaction.manager: db.query(TextFragmentIdentifier).filter_by(extract=None).delete() for tfi in db.query(TextFragmentIdentifier).join( Extract, Content, Post).all(): xpo = tfi.xpath_start print xpo match = reg.match(xpo) if match: id, remainder = match.groups() uri = Post.uri_generic(id) xp = "//div[@id='message-%s']%s" % ( uri, remainder) print xp tfi.xpath_start = tfi.xpath_end = xp