forked from beaker-project/beaker-project.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check-yum-repos.py
executable file
·87 lines (77 loc) · 3.52 KB
/
check-yum-repos.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
#!/usr/bin/python
"""
Script for checking dependencies in yum repos for Beaker
"""
import sys
import os, os.path
from ConfigParser import SafeConfigParser
import urlparse
# XXX dodgy
import imp
repoclosure = imp.load_source('repoclosure', '/usr/bin/repoclosure') # from yum-utils
def check_deps(base, local_repo, repo_urls, arches, build_deps=False):
closure_arches = ['noarch'] + arches
if build_deps:
closure_arches.append('src')
rc = repoclosure.RepoClosure(arch=closure_arches, config='/etc/yum/yum.conf')
rc.setCacheDir(True)
rc.repos.disableRepo('*')
if not urlparse.urlparse(base).scheme:
base = 'file://' + os.path.abspath(base)
if not base.endswith('/'):
base += '/' # it's supposed to be a dir
local_repo_url = urlparse.urljoin(base, local_repo)
local_repo_id = local_repo_url.replace('/', '-')
rc.add_enable_repo(local_repo_id, baseurls=[local_repo_url])
# Expand $arch in repo URLs
for repo_url in list(repo_urls):
if '$arch' in repo_url:
repo_urls.remove(repo_url)
for arch in arches:
if arch == 'i686':
arch = 'i386' # packages are i686 but it's called i386 in the URL
repo_urls.append(repo_url.replace('$arch', arch))
for repo_url in repo_urls:
rc.add_enable_repo(repo_url.replace('/', '-'), baseurls=[repo_url])
rc.readMetadata()
# Only check deps for our local repo, not the entire distro
rc.pkgonly = list(set(pkg.name for pkg in
rc.repos.getRepo(local_repo_id).getPackageSack().returnNewestByNameArch()))
broken_deps = rc.getBrokenDeps()
# XXX annoying hack: this is due to UsrMove in Fedora 17 but I'm not sure how to fix it
for pkg in broken_deps:
broken_deps[pkg] = [breakage for breakage in broken_deps[pkg]
if breakage[0] != '/bin/python']
broken_deps = dict((pkg, broken) for pkg, broken in broken_deps.iteritems() if broken)
if broken_deps:
print '%r failed dependency check using repos:' % local_repo
for repo_url in repo_urls:
print ' %s' % repo_url
for pkg, broken in broken_deps.iteritems():
print str(pkg)
for breakage in broken:
print ' ' + repr(breakage)
sys.exit(1)
def checks_from_config(base, config):
for section in config.sections():
local_repo, _, descr = section.partition('.')
print 'Checking dependencies for %s' % section
check_deps(base, local_repo,
config.get(section, 'repos').split(),
config.get(section, 'arches').split(),
config.has_option(section, 'build-deps') and config.getboolean(section, 'build-deps'))
if __name__ == '__main__':
from optparse import OptionParser
parser = OptionParser('usage: %prog [options]',
description='Checks dependencies for Beaker repos according to a config file.')
parser.add_option('-d', '--base', metavar='LOCATION',
help='look for repos under LOCATION (either directory or absolute URL) [default: %default]')
parser.add_option('-c', '--config', metavar='FILE', action='append', dest='config_filenames',
help='load configuration from FILE')
parser.set_defaults(base='yum', config_filenames=['repoclosure.conf'])
options, args = parser.parse_args()
if args:
parser.error('This program does not accept positional args')
config = SafeConfigParser()
config.read(options.config_filenames)
checks_from_config(options.base, config)