| 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 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 350 | 350 |
| 351 def wrapper(*args): | 351 def wrapper(*args): |
| 352 try: | 352 try: |
| 353 return memoized[args] | 353 return memoized[args] |
| 354 except KeyError: | 354 except KeyError: |
| 355 return memoized.setdefault(args, func(*args)) | 355 return memoized.setdefault(args, func(*args)) |
| 356 wrapper.cache_clear = memoized.clear | 356 wrapper.cache_clear = memoized.clear |
| 357 return wrapper | 357 return wrapper |
| 358 | 358 |
| 359 | 359 |
| 360 def create_source(path, static=False, revision=None): | 360 def create_source(path, cached=False, revision=None): |
|
Sebastian Noack
2017/09/29 19:11:30
Does it still make sense to call that argument "st
Vasily Kuznetsov
2017/10/02 11:11:56
Yeah, you're right, now it would be more clear if
| |
| 361 """Create a source from path and optional revision. | 361 """Create a source from path and optional revision. |
| 362 | 362 |
| 363 `static` flag indicates that the website source under `path` can be assumed | 363 `cached` flag activates caching. This can be used to optimize performance |
| 364 to not change after the source was created and any changes can be safely | 364 if no changes are expected on the filesystem after the source was created. |
| 365 ignored. | 365 This is usually the case with static generation (as opposed to dynamic |
| 366 - If `static` is `True`, no interim changes are expected and caching will | 366 preview). |
| 367 be used to optimize performance. | |
| 368 - If `static` is `False`, changes on the filesystem are expected and will | |
| 369 be reflected in the outputs of the calls. This mode can be used for live | |
| 370 preview. | |
| 371 | 367 |
| 372 If `revision` option is provided, the `path` is assumed to be pointing to a | 368 If `revision` option is provided, the `path` is assumed to be pointing to a |
| 373 Mercurial repository. In this case the source will return the content of | 369 Mercurial repository. In this case the source will return the content of |
| 374 selected revision (using `MercurialSource`) instead of the content of the | 370 selected revision (using `MercurialSource`) instead of the content of the |
| 375 directory. Note that any local changes will be ignored in this case. | 371 directory. Note that any local changes will be ignored in this case. |
| 376 | 372 |
| 377 If `settings.ini` in the source contains `[paths]` section with an | 373 If `settings.ini` in the source contains `[paths]` section with an |
| 378 `additional-paths` key that contains the list of additional root folders, | 374 `additional-paths` key that contains the list of additional root folders, |
| 379 `MultiSource` will be instantiated and its bases will be the original | 375 `MultiSource` will be instantiated and its bases will be the original |
| 380 source plus an additional source for each additional root folder. | 376 source plus an additional source for each additional root folder. |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 394 except (ConfigParser.NoSectionError, ConfigParser.NoOptionError): | 390 except (ConfigParser.NoSectionError, ConfigParser.NoOptionError): |
| 395 additional_paths = [] | 391 additional_paths = [] |
| 396 | 392 |
| 397 if additional_paths: | 393 if additional_paths: |
| 398 additional_sources = [ | 394 additional_sources = [ |
| 399 create_source(os.path.join(path, p)) | 395 create_source(os.path.join(path, p)) |
| 400 for p in additional_paths | 396 for p in additional_paths |
| 401 ] | 397 ] |
| 402 source = MultiSource([source] + additional_sources) | 398 source = MultiSource([source] + additional_sources) |
| 403 | 399 |
| 404 if static: | 400 if cached: |
| 405 for fname in [ | 401 for fname in [ |
| 406 'resolve_link', | 402 'resolve_link', |
| 407 'read_config', | 403 'read_config', |
| 408 'read_template', | 404 'read_template', |
| 409 'read_locale', | 405 'read_locale', |
| 410 'read_include', | 406 'read_include', |
| 411 'exec_file', | 407 'exec_file', |
| 412 ]: | 408 ]: |
| 413 setattr(source, fname, _memoize(getattr(source, fname))) | 409 setattr(source, fname, _memoize(getattr(source, fname))) |
| 414 | 410 |
| 415 return source | 411 return source |
| LEFT | RIGHT |