Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
"""
Usage: python import-updateinfo.py <repo_id> <updateinfo xml>
This will parse an updateinfo xml file and add it to pulp as though the updateinfo file was found
in a feed repository. This script comes with no guarantees, and should behave the same as if the
updateinfo XML was parsed, and an appropriate 'pulp-admin rpm repo uploads erratum' command was
created for each package referenced by a given errata. This should not be used in a production
setting, use at your own risk.
This script is only for use with python 2.7, and will break with 2.6 or earlier and python 3.
"""
import sys
import time
from xml.etree.ElementTree import ElementTree
from mongoengine.errors import NotUniqueError
from pulp.server.controllers import repository as repo_controller
from pulp.server.db.connection import initialize
from pulp.server.db.model import Repository
from pulp_rpm.plugins.db.models import Errata
from pulp_rpm.plugins.importers.yum.repomd.updateinfo import process_package_element
initialize()
# jank
repo_id, updateinfo_xml = sys.argv[1:]
repo = Repository.objects.get(repo_id=repo_id)
et = ElementTree(file=updateinfo_xml)
for update in et.findall('/update'):
imported = process_package_element(update)
# clean up CESA_XXXX__YYYY to be CESA:XXXX-YYYY
imported.errata_id = imported.errata_id.replace('_', ':', 1)
imported.errata_id = imported.errata_id.replace('__', '-')
imported._last_updated = time.time()
for pkglist in imported.pkglist:
pkglist['_pulp_repo_id'] = repo_id
try:
errata = Errata.objects.get(errata_id=imported.errata_id)
errata.merge_errata(imported)
print 'Merged {} into existing errata'.format(errata.errata_id)
except Errata.DoesNotExist:
errata = imported
print 'Creating new errata {}'.format(errata.errata_id)
errata.save()
repo_controller.associate_single_unit(repo, errata)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment