This file is indexed.

/usr/lib/python2.7/dist-packages/createrepo/merge.py is in createrepo 0.10.3-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/python -tt
# 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 Library 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# Copyright 2008  Red Hat, Inc - written by seth vidal skvidal at fedoraproject.org

# merge repos from arbitrary repo urls

import os
import shutil
import yum
import yum.Errors
from yum.misc import unique, getCacheDir
import yum.update_md
import rpmUtils.arch
import operator
from utils import MDError
import createrepo
import tempfile

# take repo paths from cli
# produce new repo metadata from merging the two together.

#TODO:
# excludes?


class RepoMergeBase:
    def __init__(self, repolist=[], yumbase=None, mdconf=None, mdbase_class=None ):
        self.repolist = repolist
        self.outputdir = '%s/merged_repo' % os.getcwd()
        self.exclude_tuples = []
        self.sort_func = self._sort_func # callback function to magically sort pkgs
        if not mdconf:
            self.mdconf = createrepo.MetaDataConfig()
        else:
            self.mdconf = mdconf
        if not mdbase_class:
            self.mdbase_class = createrepo.MetaDataGenerator
        else:
            self.mdbase_class = mdbase_class
        if not yumbase:
            self.yumbase = yum.YumBase()
        else:
            self.yumbase = yumbase
        self.yumbase.conf.cachedir = getCacheDir()
        self.yumbase.conf.cache = 0
        # default to all arches
        self.archlist = unique(rpmUtils.arch.arches.keys() + rpmUtils.arch.arches.values())
        self.groups = True
        self.updateinfo = True

    def _sort_func(self, repos):
        """Default sort func for repomerge. Takes a list of repository objects
           any package which is not to be included in the merged repo should be
           delPackage()'d"""
        # sort the repos by _merge_rank
        # - lowest number is the highest rank (1st place, 2ndplace, etc)
        repos.sort(key=operator.attrgetter('_merge_rank'))

        for repo in repos:
            for pkg in repo.sack:
                others = self.yumbase.pkgSack.searchNevra(pkg.name, pkg.epoch, pkg.version, pkg.release, pkg.arch)
                if len(others) > 1:
                    for thatpkg in others:
                        if pkg.repoid == thatpkg.repoid: continue
                        if pkg.repo._merge_rank < thatpkg.repo._merge_rank:
                            thatpkg.repo.sack.delPackage(thatpkg)

    def merge_repos(self):
        self.yumbase.repos.disableRepo('*')
        # add our repos and give them a merge rank in the order they appear in
        # in the repolist
        count = 0
        for r in self.repolist:
            if ':' not in r:
                r = os.path.abspath(r)
                r = 'file://' + r # just fix the file repos, this is silly.
            count +=1
            rid = 'repo%s' % count
            n = self.yumbase.add_enable_repo(rid, baseurls=[r],
                                             metadata_expire=0,
                                             timestamp_check=False)
            n._merge_rank = count

        #setup our sacks
        try:
            self.yumbase._getSacks(archlist=self.archlist)
        except yum.Errors.RepoError, e:
            raise MDError, "Could not setup merge repo pkgsack: %s" % e

        myrepos = self.yumbase.repos.listEnabled()

        self.sort_func(myrepos)


    def write_metadata(self, outputdir=None):
        mytempdir = tempfile.mkdtemp()
        if self.groups:
            try:
                comps_fn = mytempdir + '/groups.xml'
                compsfile = open(comps_fn, 'w')
                compsfile.write(self.yumbase.comps.xml())
                compsfile.close()
            except yum.Errors.GroupsError, e:
                # groups not being available shouldn't be a fatal error
                pass
            else:
                self.mdconf.groupfile=comps_fn

        if self.updateinfo:
            ui_fn = mytempdir + '/updateinfo.xml'
            uifile = open(ui_fn, 'w')
            umd = yum.update_md.UpdateMetadata()
            for repo in self.yumbase.repos.listEnabled():
                try: # attempt to grab the updateinfo.xml.gz from the repodata
                    umd.add(repo)
                except yum.Errors.RepoMDError:
                    continue
            umd.xml(fileobj=uifile)
            uifile.close()
            self.mdconf.additional_metadata['updateinfo'] = ui_fn


        self.mdconf.pkglist = self.yumbase.pkgSack
        self.mdconf.directory = self.outputdir
        if outputdir:
            self.mdconf.directory = outputdir
        # clean out what was there
        if os.path.exists(self.mdconf.directory + '/repodata'):
            shutil.rmtree(self.mdconf.directory + '/repodata')

        if not os.path.exists(self.mdconf.directory):
            os.makedirs(self.mdconf.directory)

        mdgen = self.mdbase_class(config_obj=self.mdconf)
        mdgen.doPkgMetadata()
        mdgen.doRepoMetadata()
        mdgen.doFinalMove()