| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 1 # This file is part of the Adblock Plus web scripts, | 1 # This file is part of the Adblock Plus web scripts, |
|
Tudor Avram
2018/10/05 16:28:48
The diffs in this file come from rebasing everythi
| |
| 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. |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 117 | 117 |
| 118 def list_localizable_files(self): | 118 def list_localizable_files(self): |
| 119 default_locale = self.read_config().get('general', 'defaultlocale') | 119 default_locale = self.read_config().get('general', 'defaultlocale') |
| 120 return filter(lambda f: os.path.splitext(f)[1].lower() != '.json', | 120 return filter(lambda f: os.path.splitext(f)[1].lower() != '.json', |
| 121 self.list_files('locales/%s' % default_locale)) | 121 self.list_files('locales/%s' % default_locale)) |
| 122 | 122 |
| 123 def has_localizable_file(self, locale, filename): | 123 def has_localizable_file(self, locale, filename): |
| 124 return self.has_file(self.localizable_file_filename(locale, filename)) | 124 return self.has_file(self.localizable_file_filename(locale, filename)) |
| 125 | 125 |
| 126 def read_localizable_file(self, locale, filename): | 126 def read_localizable_file(self, locale, filename): |
| 127 return self.read_file(self.localizable_file_filename(locale, filename), binary=True)[0] | 127 return self.read_file(self.localizable_file_filename(locale, filename), True)[0] |
| 128 | 128 |
| 129 # | 129 # |
| 130 # Static file helpers | 130 # Static file helpers |
| 131 # | 131 # |
| 132 | 132 |
| 133 @staticmethod | 133 @staticmethod |
| 134 def static_filename(filename): | 134 def static_filename(filename): |
| 135 return 'static/%s' % filename | 135 return 'static/%s' % filename |
| 136 | 136 |
| 137 def list_static(self): | 137 def list_static(self): |
| 138 return self.list_files('static') | 138 return self.list_files('static') |
| 139 | 139 |
| 140 def has_static(self, filename): | 140 def has_static(self, filename): |
| 141 return self.has_file(self.static_filename(filename)) | 141 return self.has_file(self.static_filename(filename)) |
| 142 | 142 |
| 143 def read_static(self, filename): | 143 def read_static(self, filename): |
| 144 return self.read_file(self.static_filename(filename), binary=True)[0] | 144 return self.read_file(self.static_filename(filename), True)[0] |
| 145 | 145 |
| 146 # | 146 # |
| 147 # Locale helpers | 147 # Locale helpers |
| 148 # | 148 # |
| 149 | 149 |
| 150 def locale_filename(self, locale, page): | 150 def locale_filename(self, locale, page): |
| 151 config = self.read_config() | 151 config = self.read_config() |
| 152 try: | 152 try: |
| 153 page = config.get('locale_overrides', page) | 153 page = config.get('locale_overrides', page) |
| 154 except ConfigParser.Error: | 154 except ConfigParser.Error: |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 382 `additional-paths` key that contains the list of additional root folders, | 382 `additional-paths` key that contains the list of additional root folders, |
| 383 `MultiSource` will be instantiated and its bases will be the original | 383 `MultiSource` will be instantiated and its bases will be the original |
| 384 source plus an additional source for each additional root folder. | 384 source plus an additional source for each additional root folder. |
| 385 `MultiSource` looks up files in its base sources in the order they are | 385 `MultiSource` looks up files in its base sources in the order they are |
| 386 provided, so the files in the additional folders will only be used if the | 386 provided, so the files in the additional folders will only be used if the |
| 387 original source doesn't contain that file. | 387 original source doesn't contain that file. |
| 388 """ | 388 """ |
| 389 source = FileSource(path) | 389 source = FileSource(path) |
| 390 | 390 |
| 391 config = source.read_config() | 391 config = source.read_config() |
| 392 print(source.read_file('settings.ini')[0]) | |
|
Vasily Kuznetsov
2018/10/05 10:56:26
Oops.
Tudor Avram
2018/10/05 12:34:40
haha, that was from Thursday night :))
| |
| 393 try: | 392 try: |
| 394 ap = config.get('paths', 'additional-paths').strip() | 393 ap = config.get('paths', 'additional-paths').strip() |
| 395 additional_paths = filter(None, ap.split()) | 394 additional_paths = filter(None, ap.split()) |
| 396 except (ConfigParser.NoSectionError, ConfigParser.NoOptionError): | 395 except (ConfigParser.NoSectionError, ConfigParser.NoOptionError): |
| 397 additional_paths = [] | 396 additional_paths = [] |
| 398 | 397 |
| 399 if additional_paths: | 398 if additional_paths: |
| 400 additional_sources = [ | 399 additional_sources = [ |
| 401 create_source(os.path.join(path, p)) | 400 create_source(os.path.join(path, p)) |
| 402 for p in additional_paths | 401 for p in additional_paths |
| 403 ] | 402 ] |
| 404 source = MultiSource([source] + additional_sources) | 403 source = MultiSource([source] + additional_sources) |
| 405 | 404 |
| 406 if cached: | 405 if cached: |
| 407 for fname in [ | 406 for fname in [ |
| 407 'list_files', | |
| 408 'list_locales', | |
| 408 'resolve_link', | 409 'resolve_link', |
| 409 'read_config', | 410 'read_config', |
| 410 'read_template', | 411 'read_template', |
| 411 'read_locale', | 412 'read_locale', |
| 413 'read_file', | |
| 412 'read_include', | 414 'read_include', |
| 413 'exec_file', | 415 'exec_file', |
| 414 ]: | 416 ]: |
| 415 setattr(source, fname, _memoize(getattr(source, fname))) | 417 setattr(source, fname, _memoize(getattr(source, fname))) |
| 416 | 418 |
| 417 return source | 419 return source |
| LEFT | RIGHT |