'When importing Fedora/EL certain parts of the install tree can also be used
as yum repos containing packages that might not yet be available via updates
in yum.  This code identifies those areas. Existing repodata will be used as-is,
but repodate is created for earlier, non-yum based, installers.'

def yum_process_comps_file(self, comps_path, distro):

    if os.path.exists(os.path.join(comps_path, 'repodata')):
        keeprepodata = True
        masterdir = 'repodata'
    else:
        masterdir = 'base'
        keeprepodata = False
    self.logger.info(('looking    for    %(p1)s/%(p2)s/*comps*.xml' % {'p1': comps_path, 'p2': masterdir}))
    files = glob.glob(('%s/%s/*comps*.xml' % (comps_path, masterdir)))
    if (len(files) == 0):
        self.logger.info(('no    comps    found    here:    %s' % os.path.join(comps_path, masterdir)))
        return
    comps_file = files[0].split('/')[(-1)]
    try:
        counter = len(distro.source_repos)
        seg = comps_path.rfind('distro_mirror')
        urlseg = comps_path[((seg + len('distro_mirror')) + 1):]
        fname = os.path.join(self.settings.webdir, 'distro_mirror', 'config', ('%s-%s.repo' % (distro.name, counter)))
        repo_url = ('http://@@http_server@@/cobbler/distro_mirror/config/%s-%s.repo' % (distro.name, counter))
        repo_url2 = ('http://@@http_server@@/cobbler/distro_mirror/%s' % urlseg)
        distro.source_repos.append([repo_url, repo_url2])
        config_dir = os.path.dirname(fname)
        if (not os.path.exists(config_dir)):
            os.makedirs(config_dir)
        config_file = open(fname, 'w+')
        config_file.write(('[core-%s]\n' % counter))
        config_file.write(('name=core-%s\n' % counter))
        config_file.write(('baseurl=http://@@http_server@@/cobbler/distro_mirror/%s\n' % urlseg))
        config_file.write('enabled=1\n')
        config_file.write('gpgcheck=0\n')
        config_file.write('priority=$yum_distro_priority\n')
        config_file.close()
        if keeprepodata:
            self.logger.info(('Keeping    repodata    as-is    :%s/repodata' % comps_path))
            self.found_repos[comps_path] = 1
        elif (comps_path not in self.found_repos):
            utils.remove_yum_olddata(comps_path)
            cmd = ('createrepo    %s    --groupfile    %s    %s' % (self.settings.createrepo_flags, os.path.join(comps_path, masterdir, comps_file), comps_path))
            utils.subprocess_call(self.logger, cmd, shell=True)
            self.found_repos[comps_path] = 1
            p1 = os.path.join(comps_path, 'repodata', 'comps.xml')
            p2 = os.path.join(comps_path, 'base', 'comps.xml')
            if (os.path.exists(p1) and os.path.exists(p2)):
                shutil.copyfile(p1, p2)
    except:
        self.logger.error('error    launching    createrepo    (not    installed?),    ignoring')
        utils.log_exc(self.logger)
