| 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, |
| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 63 | 63 |
| 64 parts = page.split('/') | 64 parts = page.split('/') |
| 65 if parts[-1] == default_page: | 65 if parts[-1] == default_page: |
| 66 page = '/'.join(parts[:-1]) | 66 page = '/'.join(parts[:-1]) |
| 67 if locale: | 67 if locale: |
| 68 path = '/{}/{}'.format(locale, page) | 68 path = '/{}/{}'.format(locale, page) |
| 69 return locale, urlparse.urlunparse(parsed[0:2] + (path,) + parsed[3: ]) | 69 return locale, urlparse.urlunparse(parsed[0:2] + (path,) + parsed[3: ]) |
| 70 return locale, '/' + page | 70 return locale, '/' + page |
| 71 | 71 |
| 72 def read_config(self): | 72 def read_config(self): |
| 73 try: | 73 configdata = self.read_file('settings.ini')[0] |
| 74 configdata = self.read_file('settings.ini')[0] | 74 config = ConfigParser.SafeConfigParser() |
| 75 config = ConfigParser.SafeConfigParser() | 75 config.readfp(StringIO(configdata)) |
| 76 config.readfp(StringIO(configdata)) | 76 return config |
| 77 return config | |
| 78 except IOError: | |
| 79 return ConfigParser.SafeConfigParser() | |
|
Vasily Kuznetsov
2019/01/04 18:46:03
This will do the trick, however, I'm worried that
rhowell
2019/01/08 00:19:25
Yeah, this seems clearer. Done.
| |
| 80 | 77 |
| 81 def exec_file(self, filename): | 78 def exec_file(self, filename): |
| 82 source, filename = self.read_file(filename) | 79 source, filename = self.read_file(filename) |
| 83 code = compile(source, filename, 'exec') | 80 code = compile(source, filename, 'exec') |
| 84 namespace = {} | 81 namespace = {} |
| 85 exec code in namespace | 82 exec code in namespace |
| 86 return namespace | 83 return namespace |
| 87 | 84 |
| 88 # | 85 # |
| 89 # Page helpers | 86 # Page helpers |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 373 If `settings.ini` in the source contains `[paths]` section with an | 370 If `settings.ini` in the source contains `[paths]` section with an |
| 374 `additional-paths` key that contains the list of additional root folders, | 371 `additional-paths` key that contains the list of additional root folders, |
| 375 `MultiSource` will be instantiated and its bases will be the original | 372 `MultiSource` will be instantiated and its bases will be the original |
| 376 source plus an additional source for each additional root folder. | 373 source plus an additional source for each additional root folder. |
| 377 `MultiSource` looks up files in its base sources in the order they are | 374 `MultiSource` looks up files in its base sources in the order they are |
| 378 provided, so the files in the additional folders will only be used if the | 375 provided, so the files in the additional folders will only be used if the |
| 379 original source doesn't contain that file. | 376 original source doesn't contain that file. |
| 380 """ | 377 """ |
| 381 source = FileSource(path) | 378 source = FileSource(path) |
| 382 | 379 |
| 383 config = source.read_config() | |
| 384 try: | 380 try: |
| 381 config = source.read_config() | |
| 385 ap = config.get('paths', 'additional-paths').strip() | 382 ap = config.get('paths', 'additional-paths').strip() |
| 386 additional_paths = filter(None, ap.split()) | 383 additional_paths = filter(None, ap.split()) |
| 387 except (ConfigParser.NoSectionError, ConfigParser.NoOptionError): | 384 except (ConfigParser.NoSectionError, ConfigParser.NoOptionError, IOError): |
| 388 additional_paths = [] | 385 additional_paths = [] |
| 389 | 386 |
| 390 if additional_paths: | 387 if additional_paths: |
| 391 additional_sources = [ | 388 additional_sources = [ |
| 392 create_source(os.path.join(path, p)) | 389 create_source(os.path.join(path, p)) |
| 393 for p in additional_paths | 390 for p in additional_paths |
| 394 ] | 391 ] |
| 395 source = MultiSource([source] + additional_sources) | 392 source = MultiSource([source] + additional_sources) |
| 396 | 393 |
| 397 if cached: | 394 if cached: |
| 398 for fname in [ | 395 for fname in [ |
| 399 'list_files', | 396 'list_files', |
| 400 'list_locales', | 397 'list_locales', |
| 401 'resolve_link', | 398 'resolve_link', |
| 402 'read_config', | 399 'read_config', |
| 403 'read_template', | 400 'read_template', |
| 404 'read_locale', | 401 'read_locale', |
| 405 'read_file', | 402 'read_file', |
| 406 'read_include', | 403 'read_include', |
| 407 'exec_file', | 404 'exec_file', |
| 408 ]: | 405 ]: |
| 409 setattr(source, fname, utils.memoize(getattr(source, fname))) | 406 setattr(source, fname, utils.memoize(getattr(source, fname))) |
| 410 | 407 |
| 411 return source | 408 return source |
| LEFT | RIGHT |