Index: cms/bin/generate_static_pages.py |
=================================================================== |
--- a/cms/bin/generate_static_pages.py |
+++ b/cms/bin/generate_static_pages.py |
@@ -17,33 +17,21 @@ |
import re |
import errno |
import codecs |
import ConfigParser |
import logging |
from argparse import ArgumentParser |
from cms.utils import get_page_params, process_page |
-from cms.sources import MercurialSource |
+from cms.sources import create_source |
MIN_TRANSLATED = 0.3 |
-def memoize(func): |
- memoized = {} |
- |
- def wrapper(*args): |
- try: |
- return memoized[args] |
- except KeyError: |
- return memoized.setdefault(args, func(*args)) |
- wrapper.clear_cache = memoized.clear |
- return wrapper |
- |
- |
def generate_pages(repo, output_dir, revision): |
known_files = set() |
def write_file(path_parts, contents, binary=False): |
encoding = None if binary else 'utf-8' |
outfile = os.path.join(output_dir, *path_parts) |
if outfile in known_files: |
logging.warning('File %s has multiple sources', outfile) |
@@ -59,26 +47,17 @@ |
os.makedirs(os.path.dirname(outfile)) |
except OSError as e: |
if e.errno != errno.EEXIST: |
raise |
with codecs.open(outfile, 'wb', encoding=encoding) as handle: |
handle.write(contents) |
- with MercurialSource(repo, revision) as source: |
- # Cache the result for some functions - we can assume here that the data |
- # never changes |
- source.resolve_link = memoize(source.resolve_link) |
- source.read_config = memoize(source.read_config) |
- source.read_template = memoize(source.read_template) |
- source.read_locale = memoize(source.read_locale) |
- source.read_include = memoize(source.read_include) |
- source.exec_file = memoize(source.exec_file) |
- |
+ with create_source(repo, cached=True, revision=revision) as source: |
config = source.read_config() |
defaultlocale = config.get('general', 'defaultlocale') |
locales = list(source.list_locales()) |
if defaultlocale not in locales: |
locales.append(defaultlocale) |
# First pass: compile the list of pages with given translation level |
def get_locale_file(page): |
@@ -104,17 +83,17 @@ |
orig_has_locale = source.has_locale |
def has_locale(locale, page): |
page = get_locale_file(page) |
if (locale, page) in blacklist: |
return False |
return orig_has_locale(locale, page) |
source.has_locale = has_locale |
- source.resolve_link.clear_cache() |
+ source.resolve_link.cache_clear() |
# Second pass: actually generate pages this time |
for locale, page in pagelist: |
pagedata = process_page(source, locale, page) |
# Make sure links to static files are versioned |
pagedata = re.sub(r'(<script\s[^<>]*\bsrc="/[^"<>]+)', r'\1?%s' % source.version, pagedata) |
pagedata = re.sub(r'(<link\s[^<>]*\bhref="/[^"<>]+)', r'\1?%s' % source.version, pagedata) |