3232import pypac
3333
3434from scanoss .cryptography import Cryptography , create_cryptography_config_from_args
35+ from scanoss .inspection .component_summary import ComponentSummary
36+ from scanoss .inspection .license_summary import LicenseSummary
3537from scanoss .scanners .container_scanner import (
3638 DEFAULT_SYFT_COMMAND ,
3739 DEFAULT_SYFT_TIMEOUT ,
@@ -531,6 +533,7 @@ def setup_args() -> None: # noqa: PLR0912, PLR0915
531533 )
532534 p_results .set_defaults (func = results )
533535
536+ ########################################### INSPECT SUBCOMMAND ###########################################
534537 # Sub-command: inspect
535538 p_inspect = subparsers .add_parser (
536539 'inspect' , aliases = ['insp' , 'ins' ], description = f'Inspect results: { __version__ } ' , help = 'Inspect results'
@@ -539,24 +542,26 @@ def setup_args() -> None: # noqa: PLR0912, PLR0915
539542 p_inspect_sub = p_inspect .add_subparsers (
540543 title = 'Inspect Commands' , dest = 'subparsercmd' , description = 'Inspect sub-commands' , help = 'Inspect sub-commands'
541544 )
545+
546+ ####### INSPECT: Copyleft ######
542547 # Inspect Sub-command: inspect copyleft
543548 p_copyleft = p_inspect_sub .add_parser (
544549 'copyleft' , aliases = ['cp' ], description = 'Inspect for copyleft licenses' , help = 'Inspect for copyleft licenses'
545550 )
546- p_copyleft .add_argument (
547- '--include' ,
548- help = 'List of Copyleft licenses to append to the default list. Provide licenses as a comma-separated list.' ,
549- )
550- p_copyleft .add_argument (
551- '--exclude' ,
552- help = 'List of Copyleft licenses to remove from default list. Provide licenses as a comma-separated list.' ,
551+
552+ ####### INSPECT: License Summary ######
553+ # Inspect Sub-command: inspect license summary
554+ p_license_summary = p_inspect_sub .add_parser (
555+ 'license-summary' , aliases = ['lic-summary' , 'licsum' ], description = 'Get license summary' ,
556+ help = 'Get detected license summary from scan results'
553557 )
554- p_copyleft .add_argument (
555- '--explicit' ,
556- help = 'Explicit list of Copyleft licenses to consider. Provide licenses as a comma-separated list.s' ,
558+
559+ p_component_summary = p_inspect_sub .add_parser (
560+ 'component-summary' , aliases = ['comp-summary' , 'compsum' ], description = 'Get component summary' ,
561+ help = 'Get detected component summary from scan results'
557562 )
558- p_copyleft .set_defaults (func = inspect_copyleft )
559563
564+ ####### INSPECT: Undeclared components ######
560565 # Inspect Sub-command: inspect undeclared
561566 p_undeclared = p_inspect_sub .add_parser (
562567 'undeclared' ,
@@ -571,7 +576,33 @@ def setup_args() -> None: # noqa: PLR0912, PLR0915
571576 default = 'settings' ,
572577 help = 'Sbom format for status output' ,
573578 )
579+
580+ # Add common commands for inspect copyleft and license summary
581+ for p in [p_copyleft , p_license_summary ]:
582+ p .add_argument (
583+ '--include' ,
584+ help = 'List of Copyleft licenses to append to the default list. Provide licenses as a comma-separated list.' ,
585+ )
586+ p .add_argument (
587+ '--exclude' ,
588+ help = 'List of Copyleft licenses to remove from default list. Provide licenses as a comma-separated list.' ,
589+ )
590+ p .add_argument (
591+ '--explicit' ,
592+ help = 'Explicit list of Copyleft licenses to consider. Provide licenses as a comma-separated list.s' ,
593+ )
594+
595+ # Add common commands for inspect copyleft and license summary
596+ for p in [p_license_summary , p_component_summary ]:
597+ p .add_argument ('-i' , '--input' , nargs = '?' , help = 'Path to results file' )
598+ p .add_argument ('-o' , '--output' , type = str , help = 'Save summary into a file' )
599+
574600 p_undeclared .set_defaults (func = inspect_undeclared )
601+ p_copyleft .set_defaults (func = inspect_copyleft )
602+ p_license_summary .set_defaults (func = inspect_license_summary )
603+ p_component_summary .set_defaults (func = inspect_component_summary )
604+
605+ ########################################### END INSPECT SUBCOMMAND ###########################################
575606
576607 # Sub-command: folder-scan
577608 p_folder_scan = subparsers .add_parser (
@@ -825,6 +856,8 @@ def setup_args() -> None: # noqa: PLR0912, PLR0915
825856 p_results ,
826857 p_undeclared ,
827858 p_copyleft ,
859+ p_license_summary ,
860+ p_component_summary ,
828861 c_provenance ,
829862 p_folder_scan ,
830863 p_folder_hash ,
@@ -1279,7 +1312,7 @@ def convert(parser, args):
12791312 if not success :
12801313 sys .exit (1 )
12811314
1282-
1315+ ################################ INSPECT handlers ################################
12831316def inspect_copyleft (parser , args ):
12841317 """
12851318 Run the "inspect" sub-command
@@ -1356,13 +1389,73 @@ def inspect_undeclared(parser, args):
13561389 status , _ = i_undeclared .run ()
13571390 sys .exit (status )
13581391
1392+ def inspect_license_summary (parser , args ):
1393+ """
1394+ Run the "inspect" sub-command
1395+ Parameters
1396+ ----------
1397+ parser: ArgumentParser
1398+ command line parser object
1399+ args: Namespace
1400+ Parsed arguments
1401+ """
1402+ if args .input is None :
1403+ print_stderr ('Please specify an input file to inspect' )
1404+ parser .parse_args ([args .subparser , args .subparsercmd , '-h' ])
1405+ sys .exit (1 )
1406+ output : str = None
1407+ if args .output :
1408+ output = args .output
1409+ open (output , 'w' ).close ()
1410+
1411+ i_license_summary = LicenseSummary (
1412+ debug = args .debug ,
1413+ trace = args .trace ,
1414+ quiet = args .quiet ,
1415+ filepath = args .input ,
1416+ output = output ,
1417+ include = args .include ,
1418+ exclude = args .exclude ,
1419+ explicit = args .explicit ,
1420+ )
1421+ i_license_summary .run ()
1422+
1423+ def inspect_component_summary (parser , args ):
1424+ """
1425+ Run the "inspect" sub-command
1426+ Parameters
1427+ ----------
1428+ parser: ArgumentParser
1429+ command line parser object
1430+ args: Namespace
1431+ Parsed arguments
1432+ """
1433+ if args .input is None :
1434+ print_stderr ('Please specify an input file to inspect' )
1435+ parser .parse_args ([args .subparser , args .subparsercmd , '-h' ])
1436+ sys .exit (1 )
1437+ output : str = None
1438+ if args .output :
1439+ output = args .output
1440+ open (output , 'w' ).close ()
1441+
1442+ i_component_summary = ComponentSummary (
1443+ debug = args .debug ,
1444+ trace = args .trace ,
1445+ quiet = args .quiet ,
1446+ filepath = args .input ,
1447+ output = output ,
1448+ )
1449+ i_component_summary .run ()
1450+
1451+ ################################ End inspect handlers ################################
13591452
13601453def utils_certloc (* _ ):
13611454 """
13621455 Run the "utils certloc" sub-command
13631456 :param _: ignored/unused
13641457 """
1365- import certifi
1458+ import certifi # noqa: PLC0415,I001
13661459
13671460 print (f'CA Cert File: { certifi .where ()} ' )
13681461
@@ -1373,11 +1466,11 @@ def utils_cert_download(_, args): # pylint: disable=PLR0912 # noqa: PLR0912
13731466 :param _: ignore/unused
13741467 :param args: Parsed arguments
13751468 """
1376- import socket
1377- import traceback
1378- from urllib .parse import urlparse
1469+ import socket # noqa: PLC0415,I001
1470+ import traceback # noqa: PLC0415,I001
1471+ from urllib .parse import urlparse # noqa: PLC0415,I001
13791472
1380- from OpenSSL import SSL , crypto
1473+ from OpenSSL import SSL , crypto # noqa: PLC0415,I001
13811474
13821475 file = sys .stdout
13831476 if args .output :
@@ -1425,7 +1518,7 @@ def utils_pac_proxy(_, args):
14251518 :param _: ignore/unused
14261519 :param args: Parsed arguments
14271520 """
1428- from pypac .resolver import ProxyResolver
1521+ from pypac .resolver import ProxyResolver # noqa: PLC0415,I001
14291522
14301523 if not args .pac :
14311524 print_stderr ('Error: No pac file option specified.' )
@@ -1499,7 +1592,7 @@ def crypto_algorithms(parser, args):
14991592 sys .exit (1 )
15001593 except Exception as e :
15011594 if args .debug :
1502- import traceback
1595+ import traceback # noqa: PLC0415,I001
15031596
15041597 traceback .print_exc ()
15051598 print_stderr (f'ERROR: { e } ' )
@@ -1541,7 +1634,7 @@ def crypto_hints(parser, args):
15411634 sys .exit (1 )
15421635 except Exception as e :
15431636 if args .debug :
1544- import traceback
1637+ import traceback # noqa: PLC0415,I001
15451638
15461639 traceback .print_exc ()
15471640 print_stderr (f'ERROR: { e } ' )
@@ -1583,7 +1676,7 @@ def crypto_versions_in_range(parser, args):
15831676 sys .exit (1 )
15841677 except Exception as e :
15851678 if args .debug :
1586- import traceback
1679+ import traceback # noqa: PLC0415,I001
15871680
15881681 traceback .print_exc ()
15891682 print_stderr (f'ERROR: { e } ' )
0 commit comments