@@ -252,7 +252,9 @@ def scan_for_package_data(location, with_threading=True, package_only=False, **k
252
252
return _scan_resource (location , scanners , with_threading = with_threading )
253
253
254
254
255
- def save_scan_file_results (codebase_resource , scan_results , scan_errors ):
255
+ def save_scan_file_results (
256
+ codebase_resource , scan_results , scan_errors , update_status = True , ** kwargs
257
+ ):
256
258
"""
257
259
Save the resource scan file results in the database.
258
260
Create project errors if any occurred during the scan.
@@ -263,6 +265,9 @@ def save_scan_file_results(codebase_resource, scan_results, scan_errors):
263
265
codebase_resource .add_errors (scan_errors )
264
266
status = flag .SCANNED_WITH_ERROR
265
267
268
+ if not update_status :
269
+ status = None
270
+
266
271
codebase_resource .set_scan_results (scan_results , status )
267
272
268
273
@@ -283,7 +288,12 @@ def save_scan_package_results(codebase_resource, scan_results, scan_errors):
283
288
284
289
285
290
def scan_resources (
286
- resource_qs , scan_func , save_func , scan_func_kwargs = None , progress_logger = None
291
+ resource_qs ,
292
+ scan_func ,
293
+ save_func ,
294
+ scan_func_kwargs = None ,
295
+ save_func_kwargs = None ,
296
+ progress_logger = None ,
287
297
):
288
298
"""
289
299
Run the `scan_func` on the codebase resources of the provided `resource_qs`.
@@ -303,6 +313,9 @@ def scan_resources(
303
313
if not scan_func_kwargs :
304
314
scan_func_kwargs = {}
305
315
316
+ if not save_func_kwargs :
317
+ save_func_kwargs = {}
318
+
306
319
resource_count = resource_qs .count ()
307
320
logger .info (f"Scan { resource_count } codebase resources with { scan_func .__name__ } " )
308
321
resource_iterator = resource_qs .iterator (chunk_size = 2000 )
@@ -317,7 +330,7 @@ def scan_resources(
317
330
scan_results , scan_errors = scan_func (
318
331
resource .location , with_threading , ** scan_func_kwargs
319
332
)
320
- save_func (resource , scan_results , scan_errors )
333
+ save_func (resource , scan_results , scan_errors , ** save_func_kwargs )
321
334
return
322
335
323
336
logger .info (f"Starting ProcessPoolExecutor with { max_workers } max_workers" )
@@ -344,10 +357,10 @@ def scan_resources(
344
357
"CPU core for successful execution."
345
358
)
346
359
raise broken_pool_error from InsufficientResourcesError (message )
347
- save_func (resource , scan_results , scan_errors )
360
+ save_func (resource , scan_results , scan_errors , ** save_func_kwargs )
348
361
349
362
350
- def scan_for_files (project , resource_qs = None , progress_logger = None ):
363
+ def scan_for_files (project , resource_qs = None , progress_logger = None , update_status = True ):
351
364
"""
352
365
Run a license, copyright, email, and url scan on files without a status for
353
366
a `project`.
@@ -363,12 +376,39 @@ def scan_for_files(project, resource_qs=None, progress_logger=None):
363
376
if license_score := project .get_env ("scancode_license_score" ):
364
377
scan_func_kwargs ["min_license_score" ] = license_score
365
378
379
+ save_func_kwargs = {
380
+ "update_status" : update_status ,
381
+ }
382
+
366
383
scan_resources (
367
384
resource_qs = resource_qs ,
368
385
scan_func = scan_file ,
369
386
save_func = save_scan_file_results ,
370
387
scan_func_kwargs = scan_func_kwargs ,
388
+ save_func_kwargs = save_func_kwargs ,
389
+ progress_logger = progress_logger ,
390
+ )
391
+
392
+
393
+ def scan_package_files (
394
+ project ,
395
+ progress_logger = None ,
396
+ update_status = False ,
397
+ ):
398
+ """
399
+ Scan files which are part of a package, for copyright, license, email
400
+ and urls.
401
+
402
+ If `update_status` is False, the status field of codebase resources is not
403
+ updated to `scanned` (which is a side-effect of scanning files), but rather
404
+ keep the old status intact.
405
+ """
406
+ package_files = project .codebaseresources .package_files ()
407
+ scan_for_files (
408
+ project = project ,
409
+ resource_qs = package_files ,
371
410
progress_logger = progress_logger ,
411
+ update_status = update_status ,
372
412
)
373
413
374
414
0 commit comments