summaryrefslogtreecommitdiffstats
path: root/scripts/check-repository.py
blob: 4d3b76004c1b7ab70124c1c32cd2caf1e9816fc0 (plain)
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
#!/usr/bin/python
#
# 11.1.2001	Pekka.Savola@netcore.fi
#		
#		"If it breaks you get to keep both the pieces"
#
#		(needless to say, Red Hat doesn't support this)
#
#
# Checks RH comps, hdlist files and RPMS directory.  I use:
#
# /ftp/redhat-7.0/RedHat/base/comps
# /ftp/redhat-7.0/RedHat/base/hdlist
# /ftp/redhat-7.0/RedHat/RPMS/*
#
# So, you run this with 'check-repository.py /ftp/redhat-7.0'
#
# Checks for (everything that the installer should, really!):
#  - typos in comps file, ie. missing packages
#  - incorrect hdlist
#  - corruption of RPM headers in packages found in hdlist
#  - ...
#
# Hacked up and down from Red Hat's todo.py in anaconda package.
#
# Notes:  I have deliberately ripped off extra junk like support for
# 	  multiple architectures.  Not too difficult to remerge if you
#	  really need those.  I only have i386.


import sys
sys.path.append('/usr/lib/anaconda')

from comps import ComponentSet, HeaderList
import os
import rpm

FILENAME = 1000000

class CheckRepository:

#    def freeHeaderList(self):
#	if (self.hdList):
#	    self.hdList = None

    def getHeaderList(self):
	self.hdList = self.readHeaders()
	return self.hdList

    def getCompsList(self):
	if (not self.comps):
	    self.getHeaderList()
	    try:
		    self.comps = self.readComps(self.hdList)
            except KeyError, package:
		print 'There was a problem with', package, '(there may be further problems)'

	return self.comps

    def readComps(self, hdlist):
	cs = ComponentSet(self.path + 
                          '/RedHat/base/comps', hdlist)
	return cs

    def getFilename(self, h):
	return self.path + "/RedHat/RPMS/" + self.fnames[h]

    def readHeaders(self):
	hl = []
	path = self.path + "/RedHat/RPMS"
	for n in os.listdir(path):
            fd = os.open(path + "/" + n, 0)
            try:
                (h, isSource) = rpm.headerFromPackage(fd)
		if (h and not isSource):
		    self.fnames[h] = n
		    hl.append(h)
            except:
		pass
            os.close(fd)
		
	return HeaderList(hl)

    def __init__(self, path):
	self.path = path
	self.fnames = {}
        
	self.hdList = None
	self.comps = None

	self.getCompsList ()
	self.getHeaderList ()
        
try:
	CheckRepository(sys.argv[1])
except OSError, msg:
	print 'Directory was invalid: ', msg
except IndexError:
	print 'Usage: ', sys.argv[0], '<repository directory>'