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='default'): | 360 def create_source(path, cached=False, revision=None): |
Wladimir Palant
2017/09/29 08:50:44
The default revision should be 'master', not 'defa
Vasily Kuznetsov
2017/09/29 10:49:09
Changed to `None`, following your next comment. Do
| |
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 (source directory is also assumed to be a | 367 |
368 Mercurial repository, and `revision` parameter can be used to select a | 368 If `revision` option is provided, the `path` is assumed to be pointing to a |
369 source revision from which the files will be read). | 369 Mercurial repository. In this case the source will return the content of |
370 - If `static` is `False`, changes on the filesystem are expected and will | 370 selected revision (using `MercurialSource`) instead of the content of the |
371 be reflected in the outputs of the calls. This mode can be used for live | 371 directory. Note that any local changes will be ignored in this case. |
372 preview. | |
373 | 372 |
374 If `settings.ini` in the source contains `[paths]` section with an | 373 If `settings.ini` in the source contains `[paths]` section with an |
375 `additional-paths` key that contains the list of additional root folders, | 374 `additional-paths` key that contains the list of additional root folders, |
376 `MultiSource` will be instantiated and its bases will be the original | 375 `MultiSource` will be instantiated and its bases will be the original |
377 source plus an additional source for each additional root folder. | 376 source plus an additional source for each additional root folder. |
378 `MultiSource` looks up files in its base sources in the order they are | 377 `MultiSource` looks up files in its base sources in the order they are |
379 provided, so the files in the additional folders will only be used if the | 378 provided, so the files in the additional folders will only be used if the |
380 original source doesn't contain that file. | 379 original source doesn't contain that file. |
381 """ | 380 """ |
382 if static: | 381 if revision is not None: |
Wladimir Palant
2017/09/29 08:50:44
Should this flag really determine which type of so
Vasily Kuznetsov
2017/09/29 10:49:10
Yeah, you're right. `static` parameter should cont
| |
383 source = MercurialSource(path, revision) | 382 source = MercurialSource(path, revision) |
384 else: | 383 else: |
385 source = FileSource(path) | 384 source = FileSource(path) |
386 | 385 |
387 config = source.read_config() | 386 config = source.read_config() |
388 try: | 387 try: |
389 ap = config.get('paths', 'additional-paths').strip() | 388 ap = config.get('paths', 'additional-paths').strip() |
390 additional_paths = filter(None, ap.split()) | 389 additional_paths = filter(None, ap.split()) |
391 except ConfigParser.NoSectionError: | 390 except (ConfigParser.NoSectionError, ConfigParser.NoOptionError): |
Wladimir Palant
2017/09/29 08:50:44
What about NoOptionError?
Vasily Kuznetsov
2017/09/29 10:49:09
Thank you. Done.
| |
392 additional_paths = [] | 391 additional_paths = [] |
393 | 392 |
394 if additional_paths: | 393 if additional_paths: |
395 additional_sources = [ | 394 additional_sources = [ |
396 create_source(os.path.join(path, p)) | 395 create_source(os.path.join(path, p)) |
Sebastian Noack
2017/09/28 20:48:21
This seems to be equivalent to FileSource(os.path.
Wladimir Palant
2017/09/29 08:50:44
Not quite equivalent. The directory we link to mig
Vasily Kuznetsov
2017/09/29 10:49:09
Yes, nested dependencies are the reason why I made
Sebastian Noack
2017/09/29 15:55:07
I agree with Wladimir. His suggestion seems to be
| |
397 for p in additional_paths | 396 for p in additional_paths |
398 ] | 397 ] |
399 source = MultiSource([source] + additional_sources) | 398 source = MultiSource([source] + additional_sources) |
400 | 399 |
401 if static: | 400 if cached: |
402 for fname in [ | 401 for fname in [ |
403 'resolve_link', | 402 'resolve_link', |
404 'read_config', | 403 'read_config', |
405 'read_template', | 404 'read_template', |
406 'read_locale', | 405 'read_locale', |
407 'read_include', | 406 'read_include', |
408 'exec_file', | 407 'exec_file', |
409 ]: | 408 ]: |
410 setattr(source, fname, _memoize(getattr(source, fname))) | 409 setattr(source, fname, _memoize(getattr(source, fname))) |
411 | 410 |
412 return source | 411 return source |
LEFT | RIGHT |