Project

Profile

Help

Issue #1088 ยป repomd.py

Example repomd.xml reader. - jortel@redhat.com, 06/13/2016 05:52 PM

 
import os
import re

from xml.etree.cElementTree import ElementTree


class Repomd(object):

FILE_NAME = 'repomd.xml'

def __init__(self):
self.files = {}

def reset(self):
self.files = {}

def get_ns(self, root):
match = re.match(r'\{.*\}', root.tag)
return match.group(0)

def read(self, path):
self.reset()
_dir = os.path.dirname(path)
tree = ElementTree()
tree.parse(path)
root = tree.getroot()
ns = self.get_ns(root)
for data in root.iter('{ns}data'.format(ns=ns)):
name = data.get('type')
location = data.find('{ns}location'.format(ns=ns))
href = location.get('href')
basename = os.path.basename(href)
self.files[name] = os.path.join(_dir, basename)


if __name__ == '__main__':
repomd = Repomd()
repomd.read('repomd.xml')
for x in repomd.files.iteritems():
print x
    (1-1/1)