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

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

Issue 29933596: Issue 5333 - Allow cms to generate relative pages (Closed) Base URL: https://hg.adblockplus.org/cms/
Patch Set: Address comments on PS2, rearrange test files (again) Created Nov. 7, 2018, 4:14 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/converters.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # This file is part of the Adblock Plus web scripts, 1 # This file is part of the Adblock Plus web scripts,
2 # Copyright (C) 2006-present eyeo GmbH 2 # Copyright (C) 2006-present eyeo GmbH
3 # 3 #
4 # Adblock Plus is free software: you can redistribute it and/or modify 4 # Adblock Plus is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License version 3 as 5 # it under the terms of the GNU General Public License version 3 as
6 # published by the Free Software Foundation. 6 # published by the Free Software Foundation.
7 # 7 #
8 # Adblock Plus is distributed in the hope that it will be useful, 8 # Adblock Plus is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 return True 105 return True
106 elif os.path.isdir(path): 106 elif os.path.isdir(path):
107 shutil.rmtree(path) 107 shutil.rmtree(path)
108 elif os.path.exists(path): 108 elif os.path.exists(path):
109 raise Exception('The object at {} is not recognisable! It is ' 109 raise Exception('The object at {} is not recognisable! It is '
110 'neither a file, nor a directory!'.format(path)) 110 'neither a file, nor a directory!'.format(path))
111 111
112 return False 112 return False
113 113
114 114
115 def generate_pages(repo, output_dir): 115 def generate_pages(repo, output_dir, relative=False):
116 known_files = set() 116 known_files = set()
117 117
118 def write_file(path_parts, contents, binary=False): 118 def write_file(path_parts, contents, binary=False):
119 encoding = None if binary else 'utf-8' 119 encoding = None if binary else 'utf-8'
120 outfile = os.path.join(output_dir, *path_parts) 120 outfile = os.path.join(output_dir, *path_parts)
121 if outfile in known_files: 121 if outfile in known_files:
122 logging.warning('File %s has multiple sources', outfile) 122 logging.warning('File %s has multiple sources', outfile)
123 return 123 return
124 known_files.add(outfile) 124 known_files.add(outfile)
125 125
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 def has_locale(locale, page): 164 def has_locale(locale, page):
165 page = get_locale_file(page) 165 page = get_locale_file(page)
166 if (locale, page) in blacklist: 166 if (locale, page) in blacklist:
167 return False 167 return False
168 return orig_has_locale(locale, page) 168 return orig_has_locale(locale, page)
169 source.has_locale = has_locale 169 source.has_locale = has_locale
170 source.resolve_link.cache_clear() 170 source.resolve_link.cache_clear()
171 171
172 # Second pass: actually generate pages this time 172 # Second pass: actually generate pages this time
173 for locale, page in pagelist: 173 for locale, page in pagelist:
174 pagedata = process_page(source, locale, page) 174 pagedata = process_page(source, locale, page, relative=relative)
175 175
176 # Make sure links to static files are versioned 176 # Make sure links to static files are versioned
177 pagedata = re.sub(r'(<script\s[^<>]*\bsrc="/[^"<>]+)', r'\1?%s' % so urce.version, pagedata) 177 pagedata = re.sub(r'(<script\s[^<>]*\bsrc="/[^"<>]+)', r'\1?%s' % so urce.version, pagedata)
178 pagedata = re.sub(r'(<link\s[^<>]*\bhref="/[^"<>]+)', r'\1?%s' % sou rce.version, pagedata) 178 pagedata = re.sub(r'(<link\s[^<>]*\bhref="/[^"<>]+)', r'\1?%s' % sou rce.version, pagedata)
179 pagedata = re.sub(r'(<img\s[^<>]*\bsrc="/[^"<>]+)', r'\1?%s' % sourc e.version, pagedata) 179 pagedata = re.sub(r'(<img\s[^<>]*\bsrc="/[^"<>]+)', r'\1?%s' % sourc e.version, pagedata)
180 180
181 write_file([locale] + page.split('/'), pagedata) 181 write_file([locale] + page.split('/'), pagedata)
182 182
183 for filename in source.list_localizable_files(): 183 for filename in source.list_localizable_files():
184 for locale in locales: 184 for locale in locales:
(...skipping 14 matching lines...) Expand all
199 remove_unknown(path) 199 remove_unknown(path)
200 if not os.listdir(path): 200 if not os.listdir(path):
201 os.rmdir(path) 201 os.rmdir(path)
202 remove_unknown(output_dir) 202 remove_unknown(output_dir)
203 203
204 204
205 if __name__ == '__main__': 205 if __name__ == '__main__':
206 parser = ArgumentParser('Convert website source to static website') 206 parser = ArgumentParser('Convert website source to static website')
207 parser.add_argument('source', help="Path to website's repository") 207 parser.add_argument('source', help="Path to website's repository")
208 parser.add_argument('output', help='Path to desired output directory') 208 parser.add_argument('output', help='Path to desired output directory')
209 parser.add_argument('--relative', help='Generate relative links',
210 action='store_true')
209 args = parser.parse_args() 211 args = parser.parse_args()
210 generate_pages(args.source, args.output) 212 generate_pages(args.source, args.output, args.relative)
OLDNEW
« no previous file with comments | « no previous file | cms/converters.py » ('j') | cms/converters.py » ('J')

Powered by Google App Engine
This is Rietveld