Ejemplo n.º 1
0
def compile_assets(website):
    client = Client(website.www_root, website.project_root)
    client._website = website
    for spt in find_files(website.www_root + '/assets/', '*.spt'):
        filepath = spt[:-4]  # /path/to/www/assets/foo.css
        urlpath = spt[spt.rfind('/assets/'):-4]  # /assets/foo.css
        if urlpath == '/assets/_well-known/acme-challenge/%token':
            # This *should* be dynamic.
            continue
        try:
            # Remove any existing compiled asset, so we can access the dynamic
            # one instead (Aspen prefers foo.css over foo.css.spt).
            os.unlink(filepath)
        except:
            pass
        headers = {}
        if website.base_url:
            url = urlparse.urlparse(website.base_url)
            headers[b'HTTP_X_FORWARDED_PROTO'] = str(url.scheme)
            headers[b'HTTP_HOST'] = str(url.netloc)
        content = client.GET(urlpath, **headers).body
        tmpfd, tmpfpath = mkstemp(dir='.')
        os.write(tmpfd, content)
        os.close(tmpfd)
        os.rename(tmpfpath, filepath)
    atexit.register(lambda: clean_assets(website.www_root))
Ejemplo n.º 2
0
def compile_assets(website):
    client = Client(website.www_root, website.project_root)
    client._website = website
    for spt in find_files(website.www_root + '/assets/', '*.spt'):
        filepath = spt[:-4]  # /path/to/www/assets/foo.css
        urlpath = spt[spt.rfind('/assets/'):-4]  # /assets/foo.css
        try:
            # Remove any existing compiled asset, so we can access the dynamic
            # one instead (Aspen prefers foo.css over foo.css.spt).
            os.unlink(filepath)
        except:
            pass
        content = client.GET(urlpath).body
        tmpfd, tmpfpath = mkstemp(dir='.')
        os.write(tmpfd, content)
        os.close(tmpfd)
        os.rename(tmpfpath, filepath)