def prepare_wms(layers, srs, styles, bgcolor=None, transparent=True, **kwargs):

    if not os.path.exists(LAYER_CACHE_PATH):
        os.makedirs(LAYER_CACHE_PATH)  # just in case it's not there yet.

    cached_filename = cache_entry_name(
        layers, srs, styles,
        bgcolor=bgcolor,
        transparent=transparent,
        query=kwargs['query'] if 'query' in kwargs else None
    )

    layer_specs = []
    for layer in layers:
        if "#" in layer:
            layer, kwargs['sublayer'] = layer.split("#") 
        rendered_layer = m.RenderedLayer.objects.get(slug=layer)
        driver = rendered_layer.data_resource.driver_instance
        layer_spec = driver.ready_data_resource(**kwargs)
        layer_specs.append((rendered_layer, layer_spec))

    if not os.path.exists(cached_filename + ".xml"):  # not an else as previous clause may remove file.
        try:
            with open(cached_filename + ".lock", 'w') as w:
                 compile_mapfile(cached_filename, srs, styles, *layer_specs)
            os.unlink(cached_filename + ".lock")
        except sh.ErrorReturnCode_1, e:
            raise RuntimeError(str(e.stderr))
        except:
            pass

    return cached_filename
Take a WMS query and turn it into the appropriate MML file, if need be.  Or look up the cached MML file
dataset/ETHPy150Open hydroshare/hydroshare2/ga_resources/drivers/__init__.py/prepare_wms