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

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

Issue 29827639: Issue 6728 - Remove dead hg revision argument (Closed)
Patch Set: Created July 11, 2018, 5:12 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/sources.py » ('j') | no next file with comments »
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
11 # GNU General Public License for more details. 11 # GNU General Public License for more details.
12 # 12 #
13 # You should have received a copy of the GNU General Public License 13 # You should have received a copy of the GNU General Public License
14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
15 15
16 import os 16 import os
17 import re 17 import re
18 import errno 18 import errno
19 import codecs 19 import codecs
20 import ConfigParser 20 import ConfigParser
21 import logging 21 import logging
22 from argparse import ArgumentParser 22 from argparse import ArgumentParser
23 23
24 from cms.utils import get_page_params, process_page 24 from cms.utils import get_page_params, process_page
25 from cms.sources import create_source 25 from cms.sources import create_source
26 26
27 MIN_TRANSLATED = 0.3 27 MIN_TRANSLATED = 0.3
28 28
29 29
30 def generate_pages(repo, output_dir, revision): 30 def generate_pages(repo, output_dir):
31 known_files = set() 31 known_files = set()
32 32
33 def write_file(path_parts, contents, binary=False): 33 def write_file(path_parts, contents, binary=False):
34 encoding = None if binary else 'utf-8' 34 encoding = None if binary else 'utf-8'
35 outfile = os.path.join(output_dir, *path_parts) 35 outfile = os.path.join(output_dir, *path_parts)
36 if outfile in known_files: 36 if outfile in known_files:
37 logging.warning('File %s has multiple sources', outfile) 37 logging.warning('File %s has multiple sources', outfile)
38 return 38 return
39 known_files.add(outfile) 39 known_files.add(outfile)
40 40
41 if os.path.exists(outfile): 41 if os.path.exists(outfile):
42 with codecs.open(outfile, 'rb', encoding=encoding) as handle: 42 with codecs.open(outfile, 'rb', encoding=encoding) as handle:
43 if handle.read() == contents: 43 if handle.read() == contents:
44 return 44 return
45 45
46 try: 46 try:
47 os.makedirs(os.path.dirname(outfile)) 47 os.makedirs(os.path.dirname(outfile))
48 except OSError as e: 48 except OSError as e:
49 if e.errno != errno.EEXIST: 49 if e.errno != errno.EEXIST:
50 raise 50 raise
51 51
52 with codecs.open(outfile, 'wb', encoding=encoding) as handle: 52 with codecs.open(outfile, 'wb', encoding=encoding) as handle:
53 handle.write(contents) 53 handle.write(contents)
54 54
55 with create_source(repo, cached=True, revision=revision) as source: 55 with create_source(repo, cached=True) as source:
56 config = source.read_config() 56 config = source.read_config()
57 defaultlocale = config.get('general', 'defaultlocale') 57 defaultlocale = config.get('general', 'defaultlocale')
58 locales = list(source.list_locales()) 58 locales = list(source.list_locales())
59 if defaultlocale not in locales: 59 if defaultlocale not in locales:
60 locales.append(defaultlocale) 60 locales.append(defaultlocale)
61 61
62 # First pass: compile the list of pages with given translation level 62 # First pass: compile the list of pages with given translation level
63 def get_locale_file(page): 63 def get_locale_file(page):
64 try: 64 try:
65 return config.get('locale_overrides', page) 65 return config.get('locale_overrides', page)
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 os.remove(path) 118 os.remove(path)
119 elif os.path.isdir(path): 119 elif os.path.isdir(path):
120 remove_unknown(path) 120 remove_unknown(path)
121 if not os.listdir(path): 121 if not os.listdir(path):
122 os.rmdir(path) 122 os.rmdir(path)
123 remove_unknown(output_dir) 123 remove_unknown(output_dir)
124 124
125 125
126 if __name__ == '__main__': 126 if __name__ == '__main__':
127 parser = ArgumentParser('Convert website source to static website') 127 parser = ArgumentParser('Convert website source to static website')
128 parser.add_argument('-r', '--rev',
129 help='Specify which revision to generate from. '
130 'See "hg help revisions" for details.',
131 default='default')
132 parser.add_argument('source', help="Path to website's repository") 128 parser.add_argument('source', help="Path to website's repository")
133 parser.add_argument('output', help='Path to desired output directory') 129 parser.add_argument('output', help='Path to desired output directory')
134 args = parser.parse_args() 130 args = parser.parse_args()
135 generate_pages(args.source, args.output, args.rev) 131 generate_pages(args.source, args.output)
OLDNEW
« no previous file with comments | « no previous file | cms/sources.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld