'Creates Yum config files for use by reposync
Two uses:
(A) output=True, Create local files that can be used with yum on provisioned clients to make use of this mirror.
(B) output=False, Create a temporary file for yum to feed into yum for mirroring'

def create_local_file(self, dest_path, repo, output=True):

    if output:
        fname = os.path.join(dest_path, 'config.repo')
    else:
        fname = os.path.join(dest_path, ('%s.repo' % repo.name))
    self.logger.debug(('creating:    %s' % fname))
    if (not os.path.exists(dest_path)):
        utils.mkdir(dest_path)
    config_file = open(fname, 'w+')
    config_file.write(('[%s]\n' % repo.name))
    config_file.write(('name=%s\n' % repo.name))
    optenabled = False
    optgpgcheck = False
    if output:
        if repo.mirror_locally:
            line = ('baseurl=http://${http_server}/cobbler/repo_mirror/%s\n' % repo.name)
        else:
            mstr = repo.mirror
            if mstr.startswith('/'):
                mstr = ('file://%s' % mstr)
            line = ('baseurl=%s\n' % mstr)
        config_file.write(line)
        for x in repo.yumopts:
            config_file.write(('%s=%s\n' % (x, repo.yumopts[x])))
            if (x == 'enabled'):
                optenabled = True
            if (x == 'gpgcheck'):
                optgpgcheck = True
    else:
        mstr = repo.mirror
        if mstr.startswith('/'):
            mstr = ('file://%s' % mstr)
        line = ('baseurl=%s\n' % mstr)
        if (self.settings.http_port not in (80, '80')):
            http_server = ('%s:%s' % (self.settings.server, self.settings.http_port))
        else:
            http_server = self.settings.server
        line = line.replace('@@server@@', http_server)
        config_file.write(line)
        config_proxy = None
        if (repo.proxy == '<<inherit>>'):
            config_proxy = self.settings.proxy_url_ext
        elif ((repo.proxy != '') and (repo.proxy != '<<None>>')):
            config_proxy = repo.proxy
        if (config_proxy is not None):
            config_file.write(('proxy=%s\n' % config_proxy))
        if ('exclude' in repo.yumopts.keys()):
            self.logger.debug(('excluding:    %s' % repo.yumopts['exclude']))
            config_file.write(('exclude=%s\n' % repo.yumopts['exclude']))
    if (not optenabled):
        config_file.write('enabled=1\n')
    config_file.write(('priority=%s\n' % repo.priority))
    if (not optgpgcheck):
        config_file.write('gpgcheck=0\n')
        for x in repo.yumopts:
            config_file.write(('%s=%s\n' % (x, repo.yumopts[x])))
            if (x == 'enabled'):
                optenabled = True
            if (x == 'gpgcheck'):
                optgpgcheck = True
    config_file.close()
    return fname
