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 :
@@ -896,7 +897,6 @@ def process(self, fields, about_file_path, running_inventory=False,
896897 afp = self .about_file_path
897898
898899 errors = self .hydrate (fields )
899-
900900 # We want to copy the license_files before the validation
901901 if reference_dir :
902902 copy_license_notice_files (
@@ -926,6 +926,10 @@ def load(self, location):
926926 loc = add_unc (loc )
927927 with io .open (loc , encoding = 'utf-8' ) as txt :
928928 input_text = txt .read ()
929+ # The 'Yes' and 'No' will be converted to 'True' and 'False' in the yaml.load()
930+ # Therefore, we need to wrap the original value in quote to prevent
931+ # the conversion
932+ input = wrap_boolean_value (input_text )
929933 # FIXME: this should be done in the commands, not here
930934 """
931935 The running_inventory defines if the current process is 'inventory' or not.
@@ -937,7 +941,7 @@ def load(self, location):
937941 and then join with the 'about_resource'
938942 """
939943 running_inventory = True
940- data = saneyaml .load (input_text , allow_duplicate_keys = False )
944+ data = saneyaml .load (input , allow_duplicate_keys = False )
941945 errs = self .load_dict (data , base_dir , running_inventory )
942946 errors .extend (errs )
943947 except Exception as e :
@@ -979,6 +983,7 @@ def load_dict(self, fields_dict, base_dir, running_inventory=False, reference_di
979983 # 'Field licenses is a custom field.'
980984 licenses_field = (key , value )
981985 fields .remove (licenses_field )
986+
982987 errors = self .process (
983988 fields = fields ,
984989 about_file_path = self .about_file_path ,
@@ -1009,9 +1014,9 @@ def dumps(self):
10091014 license_file = []
10101015 license_url = []
10111016 file_fields = ['about_resource' , 'notice_file' , 'changelog_file' , 'author_file' ]
1012- bool_fields = ['redistribute' , 'attribute' , 'track_changes' , 'modified' ]
1017+ bool_fields = ['redistribute' , 'attribute' , 'track_changes' , 'modified' , 'internal_use_only' ]
10131018 for field in self .all_fields ():
1014- if not field .value :
1019+ if not field .value and not field . name in bool_fields :
10151020 continue
10161021
10171022 if field .name == 'license_key' and field .value :
@@ -1028,8 +1033,10 @@ def dumps(self):
10281033 # value of 'about_resource'
10291034 elif field .name in file_fields and field .value :
10301035 data [field .name ] = list (field .value .keys ())[0 ]
1036+ elif field .name in bool_fields and not field .value == None :
1037+ data [field .name ] = field .value
10311038 else :
1032- if field .value or ( field . name in bool_fields and not field . value == None ) :
1039+ if field .value :
10331040 data [field .name ] = field .value
10341041
10351042 # Group the same license information in a list
@@ -1127,7 +1134,6 @@ def collect_inventory(location):
11271134 msg = (about_file_path + ": " + message )
11281135 errors .append (Error (severity , msg ))
11291136 abouts .append (about )
1130-
11311137 return unique (errors ), abouts
11321138
11331139
0 commit comments