2
# This program is free software; you can redistribute it and/or modify
3
# it under the terms of the GNU General Public License as published by
4
# the Free Software Foundation; either version 2 of the License, or
5
# (at your option) any later version.
7
# This program is distributed in the hope that it will be useful,
8
# but WITHOUT ANY WARRANTY; without even the implied warranty of
9
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
# GNU Library General Public License for more details.
12
# You should have received a copy of the GNU General Public License
13
# along with this program; if not, write to the Free Software
14
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15
# Copyright 2006 Duke University
18
from xml.etree import cElementTree
21
iterparse = cElementTree.iterparse
22
from Errors import RepoMDError
27
if qn.find('}') == -1: return qn
28
return qn.split('}')[1]
31
"""represents anything beneath a <data> tag"""
32
def __init__(self, elem):
33
self.type = elem.attrib.get('type')
34
self.location = (None, None)
35
self.checksum = (None,None) # type,value
36
self.openchecksum = (None,None) # type,value
42
def parse(self, elem):
45
child_name = ns_cleanup(child.tag)
46
if child_name == 'location':
47
relative = child.attrib.get('href')
48
base = child.attrib.get('base')
49
self.location = (base, relative)
51
elif child_name == 'checksum':
52
csum_value = child.text
53
csum_type = child.attrib.get('type')
54
self.checksum = (csum_type,csum_value)
56
elif child_name == 'open-checksum':
57
csum_value = child.text
58
csum_type = child.attrib.get('type')
59
self.openchecksum = (csum_type, csum_value)
61
elif child_name == 'timestamp':
62
self.timestamp = child.text
63
elif child_name == 'database_version':
64
self.dbversion = child.text
67
"""represents the repomd xml file"""
69
def __init__(self, repoid, srcfile):
70
"""takes a repoid and a filename for the repomd.xml"""
75
if type(srcfile) == type('str'):
76
# srcfile is a filename string
77
infile = open(srcfile, 'rt')
79
# srcfile is a file object
82
parser = iterparse(infile)
85
for event, elem in parser:
86
elem_name = ns_cleanup(elem.tag)
88
if elem_name == "data":
89
thisdata = RepoData(elem=elem)
90
self.repoData[thisdata.type] = thisdata
91
except SyntaxError, e:
92
raise RepoMDError, "Damaged repomd.xml file"
95
"""return list of metadata file types available"""
96
return self.repoData.keys()
98
def getData(self, type):
99
if self.repoData.has_key(type):
100
return self.repoData[type]
102
raise RepoMDError, "requested datatype %s not available" % type
105
"""dump fun output"""
107
for ft in self.fileTypes():
108
thisdata = self.repoData[ft]
109
print 'datatype: %s' % thisdata.type
110
print 'location: %s %s' % thisdata.location
111
print 'timestamp: %s' % thisdata.timestamp
112
print 'checksum: %s -%s' % thisdata.checksum
113
print 'open checksum: %s - %s' % thisdata.openchecksum
114
print 'dbversion: %s' % thisdata.dbversion
120
p = RepoMD('repoid', sys.argv[1])
124
print >> sys.stderr, "newcomps.py: No such file:\'%s\'" % sys.argv[1]
127
if __name__ == '__main__':