File tree Expand file tree Collapse file tree 3 files changed +30
-11
lines changed Expand file tree Collapse file tree 3 files changed +30
-11
lines changed Original file line number Diff line number Diff line change @@ -284,20 +284,23 @@ def validate_pipelines(pipelines_data):
284284 return pipelines_data
285285
286286
287- def extract_tag_from_input_files ( input_files ):
287+ def extract_tag_from_input_file ( file_location ):
288288 """
289- Add support for the ":tag" suffix in file location .
289+ Parse a file location with optional tag suffix .
290290
291291 For example: "/path/to/file.zip:tag"
292292 """
293- input_files_data = {}
294- for file in input_files :
295- if ":" in file :
296- key , value = file .split (":" , maxsplit = 1 )
297- input_files_data .update ({key : value })
298- else :
299- input_files_data .update ({file : "" })
300- return input_files_data
293+ if ":" in file_location :
294+ cleaned_location , tag = file_location .split (":" , maxsplit = 1 )
295+ return cleaned_location , tag
296+ return file_location , ""
297+
298+
299+ def extract_tag_from_input_files (input_files ):
300+ """Parse multiple file locations with optional tag suffixes."""
301+ return dict (
302+ extract_tag_from_input_file (file_location ) for file_location in input_files
303+ )
301304
302305
303306def validate_input_files (input_files ):
Original file line number Diff line number Diff line change 2828from django .core .management .base import CommandError
2929from django .utils .crypto import get_random_string
3030
31+ from scanpipe .management .commands import extract_tag_from_input_file
3132from scanpipe .pipes .fetch import SCHEME_TO_FETCHER_MAPPING
3233
3334
@@ -94,8 +95,10 @@ def get_input_options(input_location):
9495 for location in input_location .split ("," ):
9596 if location .startswith (tuple (SCHEME_TO_FETCHER_MAPPING .keys ())):
9697 input_options ["input_urls" ].append (location )
98+
9799 else :
98- input_path = Path (location )
100+ cleaned_location , _ = extract_tag_from_input_file (location )
101+ input_path = Path (cleaned_location )
99102 if not input_path .exists ():
100103 raise CommandError (f"{ location } not found." )
101104 if input_path .is_file ():
Original file line number Diff line number Diff line change @@ -1461,6 +1461,19 @@ def test_scanpipe_management_command_verify_project(self):
14611461 stdout = out ,
14621462 )
14631463
1464+ def test_scanpipe_management_command_extract_tag_from_input_file (self ):
1465+ extract_tag = commands .extract_tag_from_input_file
1466+ expected = ("file.ext" , "" )
1467+ self .assertEqual (expected , extract_tag ("file.ext" ))
1468+ expected = ("file.ext" , "" )
1469+ self .assertEqual (expected , extract_tag ("file.ext:" ))
1470+ expected = ("file.ext" , "tag" )
1471+ self .assertEqual (expected , extract_tag ("file.ext:tag" ))
1472+ expected = ("file.ext" , "tag1:tag2" )
1473+ self .assertEqual (expected , extract_tag ("file.ext:tag1:tag2" ))
1474+ expected = ("file.ext" , "tag1,tag2" )
1475+ self .assertEqual (expected , extract_tag ("file.ext:tag1,tag2" ))
1476+
14641477
14651478class ScanPipeManagementCommandMixinTest (TestCase ):
14661479 class CreateProjectCommand (
You can’t perform that action at this time.
0 commit comments