@@ -235,7 +235,9 @@ def scan_for_package_data(location, with_threading=True, package_only=False, **k
235235 return _scan_resource (location , scanners , with_threading = with_threading )
236236
237237
238- def save_scan_file_results (codebase_resource , scan_results , scan_errors ):
238+ def save_scan_file_results (
239+ codebase_resource , scan_results , scan_errors , update_status = True , ** kwargs
240+ ):
239241 """
240242 Save the resource scan file results in the database.
241243 Create project errors if any occurred during the scan.
@@ -246,6 +248,9 @@ def save_scan_file_results(codebase_resource, scan_results, scan_errors):
246248 codebase_resource .add_errors (scan_errors )
247249 status = flag .SCANNED_WITH_ERROR
248250
251+ if not update_status :
252+ status = None
253+
249254 codebase_resource .set_scan_results (scan_results , status )
250255
251256
@@ -266,7 +271,12 @@ def save_scan_package_results(codebase_resource, scan_results, scan_errors):
266271
267272
268273def scan_resources (
269- resource_qs , scan_func , save_func , scan_func_kwargs = None , progress_logger = None
274+ resource_qs ,
275+ scan_func ,
276+ save_func ,
277+ scan_func_kwargs = None ,
278+ save_func_kwargs = None ,
279+ progress_logger = None ,
270280):
271281 """
272282 Run the `scan_func` on the codebase resources of the provided `resource_qs`.
@@ -286,6 +296,9 @@ def scan_resources(
286296 if not scan_func_kwargs :
287297 scan_func_kwargs = {}
288298
299+ if not save_func_kwargs :
300+ save_func_kwargs = {}
301+
289302 resource_count = resource_qs .count ()
290303 logger .info (f"Scan { resource_count } codebase resources with { scan_func .__name__ } " )
291304 resource_iterator = resource_qs .iterator (chunk_size = 2000 )
@@ -300,7 +313,7 @@ def scan_resources(
300313 scan_results , scan_errors = scan_func (
301314 resource .location , with_threading , ** scan_func_kwargs
302315 )
303- save_func (resource , scan_results , scan_errors )
316+ save_func (resource , scan_results , scan_errors , ** save_func_kwargs )
304317 return
305318
306319 logger .info (f"Starting ProcessPoolExecutor with { max_workers } max_workers" )
@@ -319,10 +332,10 @@ def scan_resources(
319332 progress .log_progress ()
320333 logger .debug (f"{ scan_func .__name__ } pk={ resource .pk } " )
321334 scan_results , scan_errors = future .result ()
322- save_func (resource , scan_results , scan_errors )
335+ save_func (resource , scan_results , scan_errors , ** save_func_kwargs )
323336
324337
325- def scan_for_files (project , resource_qs = None , progress_logger = None ):
338+ def scan_for_files (project , resource_qs = None , progress_logger = None , update_status = True ):
326339 """
327340 Run a license, copyright, email, and url scan on files without a status for
328341 a `project`.
@@ -338,12 +351,39 @@ def scan_for_files(project, resource_qs=None, progress_logger=None):
338351 if license_score := project .get_env ("scancode_license_score" ):
339352 scan_func_kwargs ["min_license_score" ] = license_score
340353
354+ save_func_kwargs = {
355+ "update_status" : update_status ,
356+ }
357+
341358 scan_resources (
342359 resource_qs = resource_qs ,
343360 scan_func = scan_file ,
344361 save_func = save_scan_file_results ,
345362 scan_func_kwargs = scan_func_kwargs ,
363+ save_func_kwargs = save_func_kwargs ,
364+ progress_logger = progress_logger ,
365+ )
366+
367+
368+ def scan_package_files (
369+ project ,
370+ progress_logger = None ,
371+ update_status = False ,
372+ ):
373+ """
374+ Scan files which are part of a package, for copyright, license, email
375+ and urls.
376+
377+ If `update_status` is False, the status field of codebase resources is not
378+ updated to `scanned` (which is a side-effect of scanning files), but rather
379+ keep the old status intact.
380+ """
381+ package_files = project .codebaseresources .package_files ()
382+ scan_for_files (
383+ project = project ,
384+ resource_qs = package_files ,
346385 progress_logger = progress_logger ,
386+ update_status = update_status ,
347387 )
348388
349389
0 commit comments