Source

garter / garter / lesscss.py

Full commit
import os, subprocess

def lesscss(app):
    if app.debug:
        @app.before_request
        def _render_less_css():
            static_dir = app.root_path + app.static_path
            
            less_paths = []
            for path, subdirs, filenames in os.walk(static_dir):
                less_paths.extend([
                    os.path.join(path, f)
                    for f in filenames if os.path.splitext(f)[1] == '.less'
                ])
            
            for less_path in less_paths:
                css_path = os.path.splitext(less_path)[0] + '.css'
                css_mtime, less_mtime = os.path.getmtime(css_path), os.path.getmtime(less_path)
                if less_mtime >= css_mtime:
                    print 'UPDATING %s' % less_path
                    subprocess.call(['lessc', less_path, css_path], shell=False)