3131from attributecode .licenses import COMMON_LICENSES
3232from attributecode .model import parse_license_expression
3333from attributecode .util import add_unc
34- from attributecode .util import get_about_file_path
3534
3635
3736# FIXME: the template dir should be outside the code tree
@@ -167,93 +166,26 @@ def generate_from_file(abouts, template_loc=DEFAULT_TEMPLATE_FILE, variables=Non
167166
168167
169168def generate_and_save (abouts , output_location , template_loc = None , variables = None ,
170- mapping_file = None , inventory_location = None ):
169+ mapping_file = None ):
171170 """
172171 Generate an attribution text from an `abouts` list of About objects, a
173172 `template_loc` template file location and a `variables` optional
174173 mapping of extra variables. Save the generated attribution text in the
175174 `output_location` file.
176175 Return a list of Error objects if any.
177176
178- FIXME: these three argument are too complex:
179-
180177 Optionally use the `mapping_file` mapping config if provided.
181- Optionally filter `abouts` object based on the inventory JSON or CSV at `inventory_location`.
182178 """
183179 updated_abouts = []
184- lstrip_afp = []
185- afp_list = []
186- not_match_path = []
187180 errors = []
188181
189- if not inventory_location :
190- updated_abouts = abouts
191-
192- # FIXME: this is too complex
193- # Do the following if a filter list (inventory_location) is provided
194- else :
195- if not os .path .exists (inventory_location ):
196- # FIXME: this message does not make sense
197- msg = (u'"INVENTORY_LOCATION" does not exist. Generation halted.' )
198- errors .append (Error (ERROR , msg ))
199- return errors
200-
201- if inventory_location .endswith ('.csv' ) or inventory_location .endswith ('.json' ):
202- # FIXME: we should use the same inventory loading that we use everywhere
203-
204- try :
205- # Return a list which contains only the about file path
206- about_list = get_about_file_path (inventory_location , mapping_file = mapping_file )
207- # FIXME: why catching all exceptions?
208- except Exception :
209- # 'about_file_path' key/column doesn't exist
210-
211- msg = u"The required key: 'about_file_path' does not exist. Generation halted."
212- errors .append (Error (ERROR , msg ))
213- return errors
214- else :
215- # FIXME: this message does not make sense
216- msg = u'Only .csv and .json are supported for the "INVENTORY_LOCATION". Generation halted.'
217- errors .append (Error (ERROR , msg ))
218- return errors
219-
220- for afp in about_list :
221- lstrip_afp .append (afp .lstrip ('/' ))
222-
223- # return a list of paths that point all to .ABOUT files
224- about_files_list = as_about_paths (lstrip_afp )
225-
226- # Collect all the about_file_path
227- for about in abouts :
228- afp_list .append (about .about_file_path )
229-
230- # Get the not matching list if any
231- for fp in about_files_list :
232- if not fp in afp_list :
233- not_match_path .append (fp )
234-
235- if not_match_path :
236- if len (not_match_path ) == len (about_files_list ):
237- msg = "None of the paths in the provided 'inventory_location' match with the 'LOCATION'."
238- errors .append (Error (ERROR , msg ))
239- return errors
240- else :
241- for path in not_match_path :
242- msg = 'Path: ' + path + ' cannot be found.'
243- errors .append (Error (ERROR , msg ))
244-
245- for about in abouts :
246- for fp in about_files_list :
247- if about .about_file_path == fp :
248- updated_abouts .append (about )
249-
250182 # Parse license_expression and save to the license list
251183 for about in updated_abouts :
252184 if not about .license_expression .value :
253185 continue
254186 special_char_in_expression , lic_list = parse_license_expression (about .license_expression .value )
255187 if special_char_in_expression :
256- msg = (u"The following character(s) cannot be in the licesne_expression : " +
188+ msg = (u"The following character(s) cannot be in the license_expression : " +
257189 str (special_char_in_expression ))
258190 errors .append (Error (ERROR , msg ))
259191 else :
@@ -274,24 +206,3 @@ def generate_and_save(abouts, output_location, template_loc=None, variables=None
274206 of .write (rendered )
275207
276208 return errors
277-
278-
279- # FIXME: this function purpose needs to be explained.
280- def as_about_paths (paths ):
281- """
282- Return a list of paths to .ABOUT files from a list of `paths`
283- strings.
284- """
285- from posixpath import basename
286- from posixpath import dirname
287-
288- about_paths = []
289- for path in paths :
290- if path .endswith ('.ABOUT' ):
291- about_paths .append (path )
292- else :
293- # FIXME: this is not the way to check that a path is a directory, too weak
294- if path .endswith ('/' ):
295- path += basename (dirname (path ))
296- about_paths .append (path + '.ABOUT' )
297- return about_paths
0 commit comments