summaryrefslogtreecommitdiffstats
path: root/debuginfofs-mirror
blob: 5433a77fa3dc2bc66e1a209f5d330d31726cff21 (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
100
101
#!/usr/bin/python
# Given Fedora arch and version, fetch all debuginfo packages from the mirrors
# Copyright 2009 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# 
# Author: Will Woods <wwoods@redhat.com>

import os
import sys
import logging
import optparse
import ConfigParser
sys.path.insert(0,'/usr/share/yum-cli')
from utils import YumUtilBase
from yum.parser import varReplace
from yum.yumRepo import YumRepository

configfile = '/etc/debuginfofs.conf'
c = ConfigParser.RawConfigParser()
try:
    c.read(configfile)
    conf = dict(c.items('general'))
except (IOError, 
        ConfigParser.MissingSectionHeaderError, 
        ConfigParser.NoSectionError):
    print "Error: no 'cachedir' in %s" % configfile
    sys.exit(1)

# FIXME get these from commandline (and validate 'em)
conf['releasever']='10'
conf['basearch']='i386'

repolist=('fedora','fedora-updates','fedora-updates-testing')

class DebuginfoFSDownloader(YumUtilBase):
    NAME = 'debuginfofs-mirror'
    VERSION = '0.1'
    USAGE = 'usage: %s' % NAME # XXX update this
    def __init__(self):
        YumUtilBase.__init__(self,
                             DebuginfoFSDownloader.NAME,
                             DebuginfoFSDownloader.VERSION,
                             DebuginfoFSDownloader.USAGE)
        self.logger = logging.getLogger("yum.verbose.cli.debuginfofs")

y = DebuginfoFSDownloader()
y.doConfigSetup()
# TODO check for RepoError
# Kinda stupid, setting up and then immediately tearing down all repos..
y.repos.disableRepo('*')
# No yum cache needed, since we're saving the packages ourselves
y.repos.setCacheDir(conf['cachedir'])
y.conf.cache = 0
y.repos.setCache(0)
# TODO: optionally allow caching?
# kind of a cheap hack
my_yumvar = y.conf.yumvar
my_yumvar.update(conf)

for repoid in repolist:
    try:
        d = dict([(k,varReplace(v,my_yumvar)) for k,v in c.items(repoid)])
    except ConfigParser.NoSectionError:
        print "No section named %s in config" % repoid
        continue
    if 'mirrorlist' in d:
        print "Adding repo %s with mirrorlist %s" % (repoid,d['mirrorlist'])
        repo = YumRepository(repoid + '-debuginfofs')
        repo.name = repo.id
        repo.mirrorlist = d['mirrorlist']
        repo.cache = 0
        repo.enable()
        y.repos.add(repo)
        y.repos.doSetup(thisrepo=repo.id)

    packages = y.pkgSack.returnPackages()
    for p in packages:
        repo = y.repos.getRepo(p.repoid)
        remote = p.returnSimple('relativepath')
        local = os.path.join(conf['cachedir'],os.path.basename(remote))
        p.localpath = local
        # TODO: Check to see if we've already got it in cache
        # TODO: Check to see if it's already unpacked
        # Download
        #path = repo.getPackage(p)
        # TODO: Unpack 
        # TODO: Remove cached package
        # TODO: Hardlink