6161from attributecode import saneyaml
6262from attributecode import util
6363from attributecode .util import add_unc
64+ from attributecode .util import boolean_fields
6465from attributecode .util import copy_license_notice_files
6566from attributecode .util import csv
6667from attributecode .util import filter_errors
6768from attributecode .util import is_valid_name
6869from attributecode .util import on_windows
70+ from attributecode .util import wrap_boolean_value
6971from attributecode .util import UNC_PREFIX
7072from attributecode .util import ungroup_licenses
7173from attributecode .util import unique
@@ -119,7 +121,7 @@ def validate(self, *args, **kwargs):
119121 # present fields should have content ...
120122 # The boolean value can be True, False and None
121123 # The value True or False is the content of boolean fields
122- if not self .has_content :
124+ if not name in boolean_fields and not self .has_content :
123125 # ... especially if required
124126 if self .required :
125127 msg = u'Field %(name)s is required and empty'
@@ -585,8 +587,7 @@ def _validate(self, *args, **kwargs):
585587 self .value = None
586588 elif flag is None :
587589 name = self .name
588- msg = (u'Field %(name)s: field is empty. '
589- u'Defaulting flag to no.' % locals ())
590+ msg = (u'Field %(name)s: field is present but empty. ' % locals ())
590591 errors .append (Error (INFO , msg ))
591592 self .value = None
592593 else :
@@ -794,8 +795,21 @@ def __eq__(self, other):
794795 def all_fields (self ):
795796 """
796797 Return the list of all Field objects.
798+ If with_absent, include absent (not present) fields.
799+ If with_empty, include empty fields.
797800 """
798- return list (self .fields .values ()) + list (self .custom_fields .values ())
801+ all_fields = []
802+
803+ for field in list (self .fields .values ()) + list (self .custom_fields .values ()):
804+ if field .required :
805+ all_fields .append (field )
806+ else :
807+ if field .present :
808+ if field .value :
809+ all_fields .append (field )
810+ elif field .name in boolean_fields and not field .value == None :
811+ all_fields .append (field )
812+ return all_fields
799813
800814 def as_dict (self ):
801815 """
@@ -926,6 +940,10 @@ def load(self, location):
926940 loc = add_unc (loc )
927941 with io .open (loc , encoding = 'utf-8' ) as txt :
928942 input_text = txt .read ()
943+ # The 'Yes' and 'No' will be converted to 'True' and 'False' in the yaml.load()
944+ # Therefore, we need to wrap the original value in quote to prevent
945+ # the conversion
946+ input = wrap_boolean_value (input_text )
929947 # FIXME: this should be done in the commands, not here
930948 """
931949 The running_inventory defines if the current process is 'inventory' or not.
@@ -937,7 +955,7 @@ def load(self, location):
937955 and then join with the 'about_resource'
938956 """
939957 running_inventory = True
940- data = saneyaml .load (input_text , allow_duplicate_keys = False )
958+ data = saneyaml .load (input , allow_duplicate_keys = False )
941959 errs = self .load_dict (data , base_dir , running_inventory )
942960 errors .extend (errs )
943961 except Exception as e :
@@ -1127,7 +1145,6 @@ def collect_inventory(location):
11271145 msg = (about_file_path + ": " + message )
11281146 errors .append (Error (severity , msg ))
11291147 abouts .append (about )
1130-
11311148 return unique (errors ), abouts
11321149
11331150
0 commit comments