/
updateinfo.py
103 lines (86 loc) · 3.41 KB
/
updateinfo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# -*- coding: utf-8 -*-
#
# Copyright © 2013 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the License
# (GPLv2) or (at your option) any later version.
# There is NO WARRANTY for this software, express or implied, including the
# implied warranties of MERCHANTABILITY, NON-INFRINGEMENT, or FITNESS FOR A
# PARTICULAR PURPOSE.
# You should have received a copy of GPLv2 along with this software; if not,
# see http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
import logging
from pulp_rpm.common import models
_LOGGER = logging.getLogger(__name__)
METADATA_FILE_NAME = 'updateinfo'
PACKAGE_TAG = 'update'
def process_package_element(element):
"""
Process one XML block from updateinfo.xml and return a dict describing
and errata
:param element: object representing one "errate" block from the XML file
:type element: xml.etree.ElementTree.Element
:return: dictionary describing an errata
:rtype: dict
"""
package_info = {
'from': element.attrib['from'],
'status': element.attrib['status'],
'type': element.attrib['type'],
'version': element.attrib['version'],
'id': element.find('id').text,
'title': element.find('title').text,
'description': element.find('description').text,
'issued': element.find('issued').attrib['date'],
'references': map(_parse_reference, element.find('references') or []),
'pkglist': map(_parse_collection, element.find('pkglist') or []),
}
for attr_name in ('rights', 'severity', 'summary', 'solution', 'release', 'pushcount'):
child = element.find(attr_name)
if child:
package_info[attr_name] = child.text
for attr_name in ('updated',):
child = element.find(attr_name)
if child:
package_info[attr_name] = child.attrib[attr_name]
return models.Errata.from_package_info(package_info)
def _parse_reference(element):
return {
# evidence shows that the "id" attribute is sometimes missing, such as
# in a rhel6 repo.
'id': element.attrib.get('id'),
'href': element.attrib['href'],
'type': element.attrib['type'],
'title': element.text,
}
def _parse_collection(element):
ret = {
'packages': map(_parse_package, element.findall('package')),
'name': element.find('name').text,
}
# based on yum's parsing, this could be optional. See yum.update_md.UpdateNotice._parse_pkglist
if 'short' in element.attrib:
ret['short'] = element.attrib['short']
return ret
def _parse_package(element):
# looking at yum.update_md.UpdateNotice to see what attributes we can expect
sum_element = element.find('sum')
if sum_element is not None:
sum_tuple = (sum_element.attrib['type'], sum_element.text)
else:
sum_tuple = None
ret = {
'arch': element.attrib['arch'],
'name': element.attrib['name'],
'epoch': element.attrib.get('epoch', None),
'version': element.attrib['version'],
'release': element.attrib['release'],
'src': element.attrib['src'],
'filename': element.find('filename').text,
'sum': sum_tuple,
}
reboot_suggested = element.find('reboot_suggested')
if reboot_suggested:
ret['reboot_suggested'] = reboot_suggested.text
return ret