Skip to content

Instantly share code, notes, and snippets.

Created March 8, 2017 21:14
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Usage: python <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
# 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)
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
errata = Errata.objects.get(errata_id=imported.errata_id)
print 'Merged {} into existing errata'.format(errata.errata_id)
except Errata.DoesNotExist:
errata = imported
print 'Creating new errata {}'.format(errata.errata_id)
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