2727from django .core .management .base import CommandError
2828
2929from vulnerabilities .importers import IMPORTER_REGISTRY
30- from vulnerabilities .importers import importer_mapping
3130from vulnerabilities .import_runner import ImportRunner
3231
3332
@@ -54,7 +53,7 @@ def handle(self, *args, **options):
5453 return
5554
5655 if options ["all" ]:
57- self .import_data (IMPORTER_REGISTRY )
56+ self .import_data (IMPORTER_REGISTRY . values () )
5857 return
5958
6059 sources = options ["sources" ]
@@ -63,14 +62,18 @@ def handle(self, *args, **options):
6362 'Please provide at least one data source to import from or use "--all".'
6463 )
6564
66- self .import_data (valid_sources (sources ))
65+ self .import_data (validate_importers (sources ))
6766
6867 def list_sources (self ):
69- importers = [ importer . qualified_name for importer in IMPORTER_REGISTRY ]
68+ importers = list ( IMPORTER_REGISTRY )
7069 self .stdout .write ("Vulnerability data can be imported from the following sources:" )
7170 self .stdout .write ("\n " .join (importers ))
7271
7372 def import_data (self , importers ):
73+ """
74+ Run the given ``importers``. The ``importers`` are expected to be class
75+ names for the importers.
76+ """
7477 failed_importers = []
7578
7679 for importer in importers :
@@ -95,12 +98,12 @@ def import_data(self, importers):
9598 raise CommandError (f"{ len (failed_importers )} failed!: { ',' .join (failed_importers )} " )
9699
97100
98- def valid_sources (sources ):
101+ def validate_importers (sources ):
99102 importers = []
100103 unknown_sources = []
101104 for source in sources :
102105 try :
103- importers .append (importer_mapping [source ])
106+ importers .append (IMPORTER_REGISTRY [source ])
104107 except KeyError :
105108 unknown_sources .append (source )
106109 if unknown_sources :
0 commit comments