@@ -632,22 +632,30 @@ def copy_license_notice_files(fields, base_dir, license_notice_text_location, af
632632 print ('Cannot copy file at %(from_lic_path)r.' % locals ())
633633
634634
635- # FIXME: add docstring
636- def inventory_filter (abouts , filter_dict ):
637- updated_abouts = []
638- for key in filter_dict :
639- for about in abouts :
640- try :
641- # Check if the about object has the filtered attribute and if the
642- # attributed value is the same as the defined in the filter
643- for value in filter_dict [key ]:
644- if vars (about )[key ].value == value :
645- if not about in updated_abouts :
646- updated_abouts .append (about )
647- except :
648- # The current about object does not have the defined attribute
649- continue
650- return updated_abouts
635+ # FIXME: this is NOT a util but something to move with inventories or a method
636+ # from About objects
637+ def inventory_filter (abouts , filters ):
638+ """
639+ Return a list of filtered About objects from an `abouts` list of About
640+ object using the `filters` mapping of:
641+ {field_name: [acceptable_values, ....]}
642+
643+ ... such that only the About object that have a field_name with a value that
644+ matches one of the acceptable values is returned. Other About object are
645+ filtered out.
646+ """
647+ matching_abouts = []
648+ for about in abouts :
649+ for field_name , acceptable_values in filters .items ():
650+ # Check if the about object has the filtered attribute and if the
651+ # attributed value is the same as the defined in the filter
652+ actual_value = getattr (about , field_name , None )
653+ if actual_value in acceptable_values and not about in matching_abouts :
654+ matching_abouts .append (about )
655+ # FIXME: if it matches once it matches always which is probably not right
656+ break
657+
658+ return matching_abouts
651659
652660
653661# FIXME: rename function: this is mapping field names. Also this is returning a list...
@@ -686,6 +694,7 @@ def update_about_dictionary_keys(about_dictionary_list, mapping_output):
686694 return updated_dict_list
687695
688696
697+ # FIXME: we should use a license object instead
689698def ungroup_licenses (licenses ):
690699 """
691700 Ungroup multiple licenses information
0 commit comments