Skip to content

Commit

Permalink
Merge pull request #105 from fanjinfei/working3
Browse files Browse the repository at this point in the history
use temp dir for jinja2 cache
  • Loading branch information
wardi committed Aug 17, 2017
2 parents f3a8ead + a1b59f4 commit 03415ff
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
12 changes: 10 additions & 2 deletions ckan/config/environment.py
@@ -1,6 +1,10 @@
# -*- coding: utf-8 -*-
"""Pylons environment configuration"""
import os
import tempfile
import atexit
import shutil
from functools import partial
import logging
import warnings
from urlparse import urlparse
Expand Down Expand Up @@ -367,8 +371,12 @@ def template_loaded(template):
template_paths, auto_reload=True, callback=template_loaded)

# Create Jinja2 environment
cache_dir = config.get('jinja2_cache_dir', '/tmp/jinja_cache')
if not os.path.exists(cache_dir):
cache_dir = config.get('jinja2_cache_dir', None)
if not cache_dir:
cache_dir = tempfile.mkdtemp()
config['jinja2_cache_dir'] = cache_dir
atexit.register(partial(shutil.rmtree, cache_dir))
elif not os.path.exists(cache_dir):
os.makedirs(cache_dir)
env = jinja_extensions.Environment(
loader=jinja_extensions.CkanFileSystemLoader(template_paths),
Expand Down
1 change: 1 addition & 0 deletions test-core.ini
Expand Up @@ -6,6 +6,7 @@
use = egg:Paste#http
host = 0.0.0.0
port = 5000
jinja2_cache_dir = /tmp/test_ckanjinja2

[app:main]
use = egg:ckan
Expand Down

0 comments on commit 03415ff

Please sign in to comment.