Represent cachable/pickable LicenseIndex and index-related objects.
| 37 | |
| 38 | |
| 39 | class LicenseCache: |
| 40 | """ |
| 41 | Represent cachable/pickable LicenseIndex and index-related objects. |
| 42 | """ |
| 43 | |
| 44 | def __init__( |
| 45 | self, |
| 46 | db=None, |
| 47 | index=None, |
| 48 | licensing=None, |
| 49 | spdx_symbols=None, |
| 50 | unknown_spdx_symbol=None, |
| 51 | additional_license_directory=None, |
| 52 | additional_license_plugins=None, |
| 53 | ): |
| 54 | # mapping of License objects by key |
| 55 | self.db = db |
| 56 | # LicenseIndex object |
| 57 | self.index = index |
| 58 | # Licensing object |
| 59 | self.licensing = licensing |
| 60 | # mapping of LicenseSymbol objects by SPDX key |
| 61 | self.spdx_symbols = spdx_symbols |
| 62 | # LicenseSymbol object |
| 63 | self.unknown_spdx_symbol = unknown_spdx_symbol |
| 64 | # Additional licenses from directory and plugins |
| 65 | self.additional_license_directory = additional_license_directory |
| 66 | self.additional_license_plugins = additional_license_plugins |
| 67 | |
| 68 | @staticmethod |
| 69 | def load_or_build( |
| 70 | only_builtin=False, |
| 71 | licensedcode_cache_dir=licensedcode_cache_dir, |
| 72 | scancode_cache_dir=scancode_cache_dir, |
| 73 | force=False, |
| 74 | index_all_languages=False, |
| 75 | # used for testing only |
| 76 | timeout=LICENSE_INDEX_LOCK_TIMEOUT, |
| 77 | licenses_data_dir=None, |
| 78 | rules_data_dir=None, |
| 79 | additional_directory=None, |
| 80 | ): |
| 81 | """ |
| 82 | Load or build and save and return a LicenseCache object. |
| 83 | |
| 84 | We either load a cached LicenseIndex or build and cache the index. |
| 85 | On the side, we load cached or build license db, SPDX symbols and other |
| 86 | license-related data structures. |
| 87 | |
| 88 | - If the cache exists, it is returned unless corrupted. |
| 89 | - If ``force`` is True, or if the cache does not exist a new index is built |
| 90 | and cached. |
| 91 | - If ``index_all_languages`` is True, include texts in all languages when |
| 92 | building the license index. Otherwise, only include the English license |
| 93 | texts and rules (the default) |
| 94 | - ``additional_directory`` is an optional additional directory |
| 95 | that contain additional licenses and rules in a /licenses and a /rules |
| 96 | directories using the same format that we use for licenses and rules. |