99
1010import os
1111import pickle
12+
1213from shutil import rmtree
1314
1415from commoncode .fileutils import create_dir
@@ -185,10 +186,7 @@ def load_or_build(
185186 additional_license_plugins = plugin_directories ,
186187 )
187188
188- # save the cache as pickle new tree checksum
189- with open (cache_file , 'wb' ) as fn :
190- pickle .dump (license_cache , fn , protocol = PICKLE_PROTOCOL )
191-
189+ license_cache .dump (cache_file )
192190 return license_cache
193191
194192 except lockfile .LockTimeout :
@@ -201,6 +199,13 @@ def has_additional_licenses(self):
201199 if cache .additional_license_directory or cache .additional_license_plugins :
202200 return True
203201
202+ def dump (self , cache_file ):
203+ """
204+ Dump this license cache on disk at ``cache_file``.
205+ """
206+ with open (cache_file , 'wb' ) as fn :
207+ pickle .dump (self , fn , protocol = PICKLE_PROTOCOL )
208+
204209
205210def build_index (
206211 licenses_db = None ,
@@ -235,9 +240,12 @@ def build_index(
235240 if not licenses_db :
236241 # combine the licenses in these additional directories with the licenses in the original DB
237242 additional_license_dirs = get_license_dirs (additional_dirs = additional_directories )
238- combined_license_directories = [licenses_data_dir ] + additional_license_dirs
239243 # generate a single combined license db with all licenses
240- licenses_db = load_licenses_from_multiple_dirs (license_dirs = combined_license_directories )
244+ licenses_db = load_licenses_from_multiple_dirs (
245+ builtin_license_data_dir = licenses_data_dir ,
246+ additional_license_data_dirs = additional_license_dirs ,
247+ with_deprecated = False ,
248+ )
241249
242250 # if we have additional directories, extract the rules from them
243251 additional_rule_dirs = get_rule_dirs (additional_dirs = additional_directories )
@@ -393,7 +401,7 @@ def get_cache(
393401 Return a LicenseCache either rebuilt, cached or loaded from disk.
394402
395403 If ``index_all_languages`` is True, include texts in all languages when
396- building the license index. Otherwise, only include the English license \
404+ building the license index. Otherwise, only include the English license
397405 texts and rules (the default)
398406 """
399407 return populate_cache (
@@ -531,7 +539,7 @@ def validate_spdx_license_keys(license_expression, licensing):
531539 if not type (key ) == str :
532540 msg = f"Invalid license key: { key } of type { type (key )} , license key should be a string"
533541 messages .append (msg )
534-
542+
535543 lic = license_db .get (key , None )
536544 if not lic :
537545 licenses = load_licenses (with_deprecated = True )
0 commit comments