| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 elif os.path.exists(partial_path) and not os.path.isdir(partial_path): | 56 elif os.path.exists(partial_path) and not os.path.isdir(partial_path): |
| 57 raise Exception('The object at {} is not recognisable! It is neither ' | 57 raise Exception('The object at {} is not recognisable! It is neither ' |
| 58 'a file, nor a directory!'.format(partial_path)) | 58 'a file, nor a directory!'.format(partial_path)) |
| 59 | 59 |
| 60 if not os.path.isdir(partial_path): | 60 if not os.path.isdir(partial_path): |
| 61 os.mkdir(partial_path) | 61 os.mkdir(partial_path) |
| 62 | 62 |
| 63 if len(path_parts) == 0: | 63 if len(path_parts) == 0: |
| 64 return | 64 return |
| 65 | 65 |
| 66 resolve_dirs(os.path.join(partial_path, path_parts[0]), path_parts[1:]) | 66 ensure_dirs(os.path.join(partial_path, path_parts[0]), path_parts[1:]) |
| 67 | 67 |
| 68 | 68 |
| 69 def is_in_previous_version(path, new_contents, encoding): | 69 def is_in_previous_version(path, new_contents, encoding): |
| 70 """Test if a file we try to create already is in the output directory. | 70 """Test if a file we try to create already is in the output directory. |
| 71 | 71 |
| 72 It tests if the pre-existent file has all the expected content. | 72 It tests if the pre-existent file has all the expected content. |
| 73 It also handles the following two cases: | 73 It also handles the following two cases: |
| 74 | 74 |
| 75 1. The path is a directory - If this happens, it removes the directory from | 75 1. The path is a directory - If this happens, it removes the directory from |
| 76 the file tree. | 76 the file tree. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |
| 126 if is_in_previous_version(outfile, contents, encoding): | 126 if is_in_previous_version(outfile, contents, encoding): |
| 127 return | 127 return |
| 128 | 128 |
| 129 resolve_dirs(output_dir, path_parts[:-1]) | 129 ensure_dirs(output_dir, path_parts[:-1]) |
| 130 | 130 |
| 131 with codecs.open(outfile, 'wb', encoding=encoding) as handle: | 131 with codecs.open(outfile, 'wb', encoding=encoding) as handle: |
| 132 handle.write(contents) | 132 handle.write(contents) |
| 133 | 133 |
| 134 with create_source(repo, cached=True) as source: | 134 with create_source(repo, cached=True) as source: |
| 135 config = source.read_config() | 135 config = source.read_config() |
| 136 defaultlocale = config.get('general', 'defaultlocale') | 136 defaultlocale = config.get('general', 'defaultlocale') |
| 137 locales = list(source.list_locales()) | 137 locales = list(source.list_locales()) |
| 138 if defaultlocale not in locales: | 138 if defaultlocale not in locales: |
| 139 locales.append(defaultlocale) | 139 locales.append(defaultlocale) |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 args = parser.parse_args() | 209 args = parser.parse_args() |
| 210 generate_pages(args.source, args.output) | 210 generate_pages(args.source, args.output) |
| LEFT | RIGHT |