'Compile a cheetah template with cobbler modifications. Modifications
include SNIPPET:: syntax replacement and inclusion of cobbler builtin
methods.'

def compile(klass, *args, **kwargs):

    def replacer(match):
        return ("$SNIPPET('%s')" % match.group(1))
    def preprocess(source, file):
        if (source is None):
            if isinstance(file, basestring):
                if os.path.exists(file):
                    f = open(file)
                    source = ('#errorCatcher    Echo\n' + f.read())
                    f.close()
                else:
                    source = ('#    Unable    to    read    %s\n' % file)
            elif hasattr(file, 'read'):
                source = file.read()
            file = None
        rx = re.compile('SNIPPET::([A-Za-z0-9_\\-\\/\\.]+)')
        results = rx.sub(replacer, source)
        return (results, file)
    preprocessors = [preprocess]
    if ('preprocessors' in kwargs):
        preprocessors.extend(kwargs['preprocessors'])
    kwargs['preprocessors'] = preprocessors
    if ('baseclass' not in kwargs):
        kwargs['baseclass'] = Template
    return Cheetah.Template.Template.compile(*args, **kwargs)
