mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-02-09 06:05:00 -05:00
Add util for locating static files. Move to static.py.
This commit is contained in:
committed by
Neil Williams
parent
d2ef201989
commit
58721c2c9c
@@ -28,6 +28,24 @@ import json
|
||||
import base64
|
||||
import shutil
|
||||
|
||||
|
||||
def locate_static_file(name):
|
||||
from pylons import g
|
||||
static_dirs = set(plugin.static_dir for plugin in g.plugins)
|
||||
static_dirs.add(g.paths['static_files'])
|
||||
|
||||
for static_dir in static_dirs:
|
||||
file_path = os.path.join(static_dir, name.lstrip('/'))
|
||||
if os.path.exists(file_path):
|
||||
return file_path
|
||||
|
||||
|
||||
def static_mtime(name):
|
||||
path = locate_static_file(name)
|
||||
if path:
|
||||
return os.path.getmtime(path)
|
||||
|
||||
|
||||
def generate_static_name(name, base=None):
|
||||
"""Generate a unique filename.
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ from filters import unsafe, websafe, _force_unicode, _force_utf8
|
||||
from r2.lib.utils import vote_hash, UrlParser, timesince, is_subdomain
|
||||
|
||||
from r2.lib import hooks
|
||||
from r2.lib.static import static_mtime
|
||||
from r2.lib.media import s3_direct_url
|
||||
|
||||
import babel.numbers
|
||||
@@ -38,18 +39,6 @@ from pylons import g, c, request
|
||||
from pylons.i18n import _, ungettext
|
||||
|
||||
|
||||
def static_mtime(path):
|
||||
static_dirs = set(plugin.static_dir for plugin in g.plugins)
|
||||
static_dirs.add(g.paths['static_files'])
|
||||
|
||||
for static_dir in static_dirs:
|
||||
file_path = os.path.join(static_dir, path.lstrip('/'))
|
||||
try:
|
||||
return os.path.getmtime(file_path)
|
||||
except OSError:
|
||||
continue
|
||||
|
||||
|
||||
static_text_extensions = {
|
||||
'.js': 'js',
|
||||
'.css': 'css',
|
||||
|
||||
Reference in New Issue
Block a user