Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: cms/bin/generate_static_pages.py

Issue 5242593268989952: Issue 2340 - Don`t generate pages if less than 30% have been translated (Closed)
Patch Set: Created April 17, 2015, 5:19 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | cms/converters.py » ('j') | cms/utils.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # coding: utf-8 1 # coding: utf-8
2 2
3 # This file is part of the Adblock Plus web scripts, 3 # This file is part of the Adblock Plus web scripts,
4 # Copyright (C) 2006-2015 Eyeo GmbH 4 # Copyright (C) 2006-2015 Eyeo GmbH
5 # 5 #
6 # Adblock Plus is free software: you can redistribute it and/or modify 6 # Adblock Plus is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License version 3 as 7 # it under the terms of the GNU General Public License version 3 as
8 # published by the Free Software Foundation. 8 # published by the Free Software Foundation.
9 # 9 #
10 # Adblock Plus is distributed in the hope that it will be useful, 10 # Adblock Plus is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details. 13 # GNU General Public License for more details.
14 # 14 #
15 # You should have received a copy of the GNU General Public License 15 # You should have received a copy of the GNU General Public License
16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
17 17
18 import sys, os, re, errno, codecs 18 import sys, os, re, errno, codecs
19 from ..utils import process_page 19 from ..utils import process_page
20 from ..sources import MercurialSource 20 from ..sources import MercurialSource
21 21
22 MIN_TRANSLATED = 0.3
Sebastian Noack 2015/04/17 17:32:27 Is this actually the same threshold we currently u
Wladimir Palant 2015/04/17 18:21:15 Yes. The effect might still be different however,
23
22 def memoize(func): 24 def memoize(func):
23 memoized = {} 25 memoized = {}
24 def wrapper(*args): 26 def wrapper(*args):
25 try: 27 try:
26 return memoized[args] 28 return memoized[args]
27 except KeyError: 29 except KeyError:
28 return memoized.setdefault(args, func(*args)) 30 return memoized.setdefault(args, func(*args))
29 return wrapper 31 return wrapper
30 32
31 def generate_pages(repo, output_dir): 33 def generate_pages(repo, output_dir):
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 source.read_include = memoize(source.read_include) 65 source.read_include = memoize(source.read_include)
64 66
65 config = source.read_config() 67 config = source.read_config()
66 defaultlocale = config.get("general", "defaultlocale") 68 defaultlocale = config.get("general", "defaultlocale")
67 locales = list(source.list_locales()) 69 locales = list(source.list_locales())
68 if defaultlocale not in locales: 70 if defaultlocale not in locales:
69 locales.append(defaultlocale) 71 locales.append(defaultlocale)
70 for page, format in source.list_pages(): 72 for page, format in source.list_pages():
71 for locale in locales: 73 for locale in locales:
72 if locale == defaultlocale or source.has_locale(locale, page): 74 if locale == defaultlocale or source.has_locale(locale, page):
73 pagedata = process_page(source, locale, page, format) 75 pagedata = process_page(source, locale, page, format,
76 min_translated=MIN_TRANSLATED)
77 if pagedata:
78 # Make sure links to static files are versioned
79 pagedata = re.sub(r'(<script\s[^<>]*\bsrc="/[^"<>]+)', r"\1?%s" % so urce.version, pagedata)
80 pagedata = re.sub(r'(<link\s[^<>]*\bhref="/[^"<>]+)', r"\1?%s" % sou rce.version, pagedata)
81 pagedata = re.sub(r'(<img\s[^<>]*\bsrc="/[^"<>]+)', r"\1?%s" % sourc e.version, pagedata)
74 82
75 # Make sure links to static files are versioned 83 write_file([locale] + page.split("/"), pagedata)
76 pagedata = re.sub(r'(<script\s[^<>]*\bsrc="/[^"<>]+)', r"\1?%s" % sour ce.version, pagedata)
77 pagedata = re.sub(r'(<link\s[^<>]*\bhref="/[^"<>]+)', r"\1?%s" % sourc e.version, pagedata)
78 pagedata = re.sub(r'(<img\s[^<>]*\bsrc="/[^"<>]+)', r"\1?%s" % source. version, pagedata)
79
80 write_file([locale] + page.split("/"), pagedata)
81 84
82 for filename in source.list_localizable_files(): 85 for filename in source.list_localizable_files():
83 for locale in locales: 86 for locale in locales:
84 if source.has_localizable_file(locale, filename): 87 if source.has_localizable_file(locale, filename):
85 filedata = source.read_localizable_file(locale, filename) 88 filedata = source.read_localizable_file(locale, filename)
86 write_file([locale] + filename.split("/"), filedata, binary=True) 89 write_file([locale] + filename.split("/"), filedata, binary=True)
87 90
88 for filename in source.list_static(): 91 for filename in source.list_static():
89 write_file(filename.split("/"), source.read_static(filename), binary=True) 92 write_file(filename.split("/"), source.read_static(filename), binary=True)
90 93
91 def remove_unknown(dir): 94 def remove_unknown(dir):
92 files = os.listdir(dir) 95 files = os.listdir(dir)
93 for filename in files: 96 for filename in files:
94 path = os.path.join(dir, filename) 97 path = os.path.join(dir, filename)
95 if os.path.isfile(path) and path not in known_files: 98 if os.path.isfile(path) and path not in known_files:
96 os.remove(path) 99 os.remove(path)
97 elif os.path.isdir(path): 100 elif os.path.isdir(path):
98 remove_unknown(path) 101 remove_unknown(path)
99 if not os.listdir(path): 102 if not os.listdir(path):
100 os.rmdir(path) 103 os.rmdir(path)
101 remove_unknown(output_dir) 104 remove_unknown(output_dir)
102 105
103 if __name__ == "__main__": 106 if __name__ == "__main__":
104 if len(sys.argv) < 3: 107 if len(sys.argv) < 3:
105 print >>sys.stderr, "Usage: %s source_repository output_dir" % sys.argv[0] 108 print >>sys.stderr, "Usage: %s source_repository output_dir" % sys.argv[0]
106 sys.exit(1) 109 sys.exit(1)
107 110
108 repo, output_dir = sys.argv[1:3] 111 repo, output_dir = sys.argv[1:3]
109 generate_pages(repo, output_dir) 112 generate_pages(repo, output_dir)
OLDNEW
« no previous file with comments | « no previous file | cms/converters.py » ('j') | cms/utils.py » ('J')

Powered by Google App Engine
This is Rietveld