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

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

Issue 6504702795579392: Issue 2530 - Selecting Korean language causes all pages to 404 (Closed)
Patch Set: Created May 15, 2015, 1:44 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 | no next file » | no next file with comments »
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,
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 source.read_locale = memoize(source.read_locale) 72 source.read_locale = memoize(source.read_locale)
73 source.read_include = memoize(source.read_include) 73 source.read_include = memoize(source.read_include)
74 74
75 config = source.read_config() 75 config = source.read_config()
76 defaultlocale = config.get("general", "defaultlocale") 76 defaultlocale = config.get("general", "defaultlocale")
77 locales = list(source.list_locales()) 77 locales = list(source.list_locales())
78 if defaultlocale not in locales: 78 if defaultlocale not in locales:
79 locales.append(defaultlocale) 79 locales.append(defaultlocale)
80 80
81 # First pass: compile the list of pages with given translation level 81 # First pass: compile the list of pages with given translation level
82 def get_locale_file(page):
83 try:
84 return config.get("locale_overrides", page)
85 except ConfigParser.Error:
86 return page
87
82 pagelist = set() 88 pagelist = set()
83 blacklist = set() 89 blacklist = set()
84 for page, format in source.list_pages(): 90 for page, format in source.list_pages():
85 for locale in locales: 91 for locale in locales:
86 if locale == defaultlocale: 92 if locale == defaultlocale:
87 pagelist.add((locale, page)) 93 pagelist.add((locale, page))
88 elif source.has_locale(locale, page): 94 elif source.has_locale(locale, page):
89 params = get_page_params(source, locale, page, format) 95 params = get_page_params(source, locale, page, format)
90 if params["translation_ratio"] >= MIN_TRANSLATED: 96 if params["translation_ratio"] >= MIN_TRANSLATED:
91 pagelist.add((locale, page)) 97 pagelist.add((locale, page))
92 else: 98 else:
93 blacklist.add((locale, page)) 99 blacklist.add((locale, get_locale_file(page)))
94 100
95 # Override existance check to avoid linking to pages we don't generate 101 # Override existance check to avoid linking to pages we don't generate
96 orig_has_locale = source.has_locale 102 orig_has_locale = source.has_locale
97 def has_locale(locale, page): 103 def has_locale(locale, page):
98 try: 104 page = get_locale_file(page)
99 page = config.get("locale_overrides", page)
100 except ConfigParser.Error:
101 pass
102 if (locale, page) in blacklist: 105 if (locale, page) in blacklist:
103 return False 106 return False
104 return orig_has_locale(locale, page) 107 return orig_has_locale(locale, page)
105 source.has_locale = has_locale 108 source.has_locale = has_locale
106 source.resolve_link.clear_cache() 109 source.resolve_link.clear_cache()
107 110
108 # Second pass: actually generate pages this time 111 # Second pass: actually generate pages this time
109 for locale, page in pagelist: 112 for locale, page in pagelist:
110 pagedata = process_page(source, locale, page) 113 pagedata = process_page(source, locale, page)
111 114
(...skipping 25 matching lines...) Expand all
137 os.rmdir(path) 140 os.rmdir(path)
138 remove_unknown(output_dir) 141 remove_unknown(output_dir)
139 142
140 if __name__ == "__main__": 143 if __name__ == "__main__":
141 if len(sys.argv) < 3: 144 if len(sys.argv) < 3:
142 print >>sys.stderr, "Usage: %s source_repository output_dir" % sys.argv[0] 145 print >>sys.stderr, "Usage: %s source_repository output_dir" % sys.argv[0]
143 sys.exit(1) 146 sys.exit(1)
144 147
145 repo, output_dir = sys.argv[1:3] 148 repo, output_dir = sys.argv[1:3]
146 generate_pages(repo, output_dir) 149 generate_pages(repo, output_dir)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld