LEFT | RIGHT |
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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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, static=True, revision=revision) as source: | 55 with create_source(repo, cached=True, revision=revision) 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 15 matching lines...) Expand all Loading... |
81 | 81 |
82 # Override existance check to avoid linking to pages we don't generate | 82 # Override existance check to avoid linking to pages we don't generate |
83 orig_has_locale = source.has_locale | 83 orig_has_locale = source.has_locale |
84 | 84 |
85 def has_locale(locale, page): | 85 def has_locale(locale, page): |
86 page = get_locale_file(page) | 86 page = get_locale_file(page) |
87 if (locale, page) in blacklist: | 87 if (locale, page) in blacklist: |
88 return False | 88 return False |
89 return orig_has_locale(locale, page) | 89 return orig_has_locale(locale, page) |
90 source.has_locale = has_locale | 90 source.has_locale = has_locale |
91 source.resolve_link.cache_clear() | 91 source.resolve_link.cache_clear() |
92 | 92 |
93 # Second pass: actually generate pages this time | 93 # Second pass: actually generate pages this time |
94 for locale, page in pagelist: | 94 for locale, page in pagelist: |
95 pagedata = process_page(source, locale, page) | 95 pagedata = process_page(source, locale, page) |
96 | 96 |
97 # Make sure links to static files are versioned | 97 # Make sure links to static files are versioned |
98 pagedata = re.sub(r'(<script\s[^<>]*\bsrc="/[^"<>]+)', r'\1?%s' % so
urce.version, pagedata) | 98 pagedata = re.sub(r'(<script\s[^<>]*\bsrc="/[^"<>]+)', r'\1?%s' % so
urce.version, pagedata) |
99 pagedata = re.sub(r'(<link\s[^<>]*\bhref="/[^"<>]+)', r'\1?%s' % sou
rce.version, pagedata) | 99 pagedata = re.sub(r'(<link\s[^<>]*\bhref="/[^"<>]+)', r'\1?%s' % sou
rce.version, pagedata) |
100 pagedata = re.sub(r'(<img\s[^<>]*\bsrc="/[^"<>]+)', r'\1?%s' % sourc
e.version, pagedata) | 100 pagedata = re.sub(r'(<img\s[^<>]*\bsrc="/[^"<>]+)', r'\1?%s' % sourc
e.version, pagedata) |
101 | 101 |
(...skipping 23 matching lines...) Expand all Loading... |
125 if __name__ == '__main__': | 125 if __name__ == '__main__': |
126 parser = ArgumentParser('Convert website source to static website') | 126 parser = ArgumentParser('Convert website source to static website') |
127 parser.add_argument('-r', '--rev', | 127 parser.add_argument('-r', '--rev', |
128 help=('Specify which revision to generate from. ' | 128 help=('Specify which revision to generate from. ' |
129 'See "hg help revisions" for details.'), | 129 'See "hg help revisions" for details.'), |
130 default='default') | 130 default='default') |
131 parser.add_argument('source', help="Path to website's repository") | 131 parser.add_argument('source', help="Path to website's repository") |
132 parser.add_argument('output', help='Path to desired output directory') | 132 parser.add_argument('output', help='Path to desired output directory') |
133 args = parser.parse_args() | 133 args = parser.parse_args() |
134 generate_pages(args.source, args.output, args.rev) | 134 generate_pages(args.source, args.output, args.rev) |
LEFT | RIGHT |