2020# ScanCode.io is a free software code scanning tool from nexB Inc. and others.
2121# Visit https://github.com/aboutcode-org/scancode.io for support and download.
2222
23+ from collections import defaultdict
2324from pathlib import Path
2425
2526from django .core .management import call_command
@@ -42,12 +43,16 @@ def add_arguments(self, parser):
4243 help = (
4344 "One or more pipeline to run. "
4445 "The pipelines executed based on their given order. "
45- 'Groups can be provided using the "pipeline_name:option1,option2"'
46- " syntax."
46+ 'Groups can be provided using the "pipeline_name:option1,option2" '
47+ "syntax."
4748 ),
4849 )
4950 parser .add_argument (
50- "input_location" , help = "Input location: file, directory, and URL supported."
51+ "input_location" ,
52+ help = (
53+ "Input location: file, directory, and URL supported."
54+ 'Multiple values can be provided using the "input1,input2" syntax.'
55+ ),
5156 )
5257 parser .add_argument ("--project" , required = False , help = "Project name." )
5358 parser .add_argument (
@@ -68,22 +73,38 @@ def handle(self, *args, **options):
6873 "pipeline" : pipelines ,
6974 "execute" : True ,
7075 "verbosity" : 0 ,
76+ ** self .get_input_options (input_location ),
7177 }
7278
73- if input_location .startswith (tuple (SCHEME_TO_FETCHER_MAPPING .keys ())):
74- create_project_options ["input_urls" ] = [input_location ]
75- else :
76- input_path = Path (input_location )
77- if not input_path .exists ():
78- raise CommandError (f"{ input_location } not found." )
79- if input_path .is_file ():
80- create_project_options ["input_files" ] = [input_location ]
81- else :
82- create_project_options ["copy_codebase" ] = input_location
83-
8479 # Run the database migrations in case the database is not created or outdated.
8580 call_command ("migrate" , verbosity = 0 , interactive = False )
8681 # Create a project with proper inputs and execute the pipeline(s)
8782 call_command ("create-project" , project_name , ** create_project_options )
8883 # Print the results for the specified format on stdout
8984 call_command ("output" , project = project_name , format = [output_format ], print = True )
85+
86+ @staticmethod
87+ def get_input_options (input_location ):
88+ """
89+ Parse a comma-separated list of input locations and convert them into options
90+ for the `create-project` command.
91+ """
92+ input_options = defaultdict (list )
93+
94+ for location in input_location .split ("," ):
95+ if location .startswith (tuple (SCHEME_TO_FETCHER_MAPPING .keys ())):
96+ input_options ["input_urls" ].append (location )
97+ else :
98+ input_path = Path (location )
99+ if not input_path .exists ():
100+ raise CommandError (f"{ location } not found." )
101+ if input_path .is_file ():
102+ input_options ["input_files" ].append (location )
103+ else :
104+ if input_options ["copy_codebase" ]:
105+ raise CommandError (
106+ "Only one codebase directory can be provided as input."
107+ )
108+ input_options ["copy_codebase" ] = location
109+
110+ return input_options
0 commit comments