4646from attributecode import api
4747from attributecode import saneyaml
4848from attributecode import util
49- from attributecode .util import add_unc , UNC_PREFIX , UNC_PREFIX_POSIX , on_windows , copy_license_files
49+ from attributecode .util import add_unc , UNC_PREFIX , UNC_PREFIX_POSIX , on_windows , copy_license_notice_files
5050from license_expression import Licensing
5151
5252
@@ -363,7 +363,7 @@ def _validate(self, *args, **kwargs):
363363 """
364364 errors = super (PathField , self )._validate (* args , ** kwargs )
365365 self .base_dir = kwargs .get ('base_dir' )
366- self .license_text_location = kwargs .get ('license_text_location ' )
366+ self .license_notice_text_location = kwargs .get ('license_notice_text_location ' )
367367
368368 if self .base_dir :
369369 self .base_dir = util .to_posix (self .base_dir )
@@ -387,9 +387,9 @@ def _validate(self, *args, **kwargs):
387387 # the license files, if need to be copied, are located under the path
388388 # set from the 'license-text-location' option, so the tool should check
389389 # at the 'license-text-location' instead of the 'base_dir'
390- if self .base_dir or self .license_text_location :
391- if self .license_text_location :
392- location = posixpath .join (self .license_text_location , path )
390+ if self .base_dir or self .license_notice_text_location :
391+ if self .license_notice_text_location :
392+ location = posixpath .join (self .license_notice_text_location , path )
393393 else :
394394 location = posixpath .join (self .base_dir , path )
395395 location = util .to_native (location )
@@ -479,7 +479,7 @@ def _validate(self, *args, **kwargs):
479479 try :
480480 # TODO: we have lots the location by replacing it with a text
481481 location = add_unc (location )
482- text = codecs .open (location , encoding = 'utf-8' ).read ()
482+ text = codecs .open (location , encoding = 'utf-8' , errors = 'ignore' ).read ()
483483 self .value [path ] = text
484484 except Exception , e :
485485 # only keep the first 100 char of the exception
@@ -584,14 +584,14 @@ def __eq__(self, other):
584584 and self .value == other .value )
585585
586586
587- def validate_fields (fields , base_dir , license_text_location = None ):
587+ def validate_fields (fields , base_dir , license_notice_text_location = None ):
588588 """
589589 Validate a sequence of Field objects. Return a list of errors.
590590 Validation may update the Field objects as needed as a side effect.
591591 """
592592 errors = []
593593 for f in fields :
594- val_err = f .validate (base_dir = base_dir , license_text_location = license_text_location )
594+ val_err = f .validate (base_dir = base_dir , license_notice_text_location = license_notice_text_location )
595595 errors .extend (val_err )
596596 return errors
597597
@@ -629,7 +629,8 @@ def create_fields(self):
629629 ('home_url' , UrlField ()),
630630 ('notes' , StringField ()),
631631
632- ('license' , StringField ()),
632+ ('license' , ListField ()),
633+ ('license_expression' , StringField ()),
633634 ('license_name' , StringField ()),
634635 ('license_file' , FileTextField ()),
635636 ('license_url' , UrlField ()),
@@ -870,25 +871,25 @@ def hydrate(self, fields):
870871 errors .append (Error (INFO , msg % locals ()))
871872 return errors
872873
873- def process (self , fields , base_dir = None , license_text_location = None ):
874+ def process (self , fields , base_dir = None , license_notice_text_location = None ):
874875 """
875876 Hydrate and validate a sequence of field name/value tuples from an
876877 ABOUT file. Return a list of errors.
877878 """
878879 self .base_dir = base_dir
879- self .license_text_location = license_text_location
880+ self .license_notice_text_location = license_notice_text_location
880881 afp = self .about_file_path
881882 errors = []
882883 hydratation_errors = self .hydrate (fields )
883884 errors .extend (hydratation_errors )
884885
885886 # We want to copy the license_files before the validation
886- if license_text_location :
887- copy_license_files (fields , base_dir , license_text_location , afp )
887+ if license_notice_text_location :
888+ copy_license_notice_files (fields , base_dir , license_notice_text_location , afp )
888889
889890 # we validate all fields, not only these hydrated
890891 all_fields = self .all_fields ()
891- validation_errors = validate_fields (all_fields , self .base_dir , self .license_text_location )
892+ validation_errors = validate_fields (all_fields , self .base_dir , self .license_notice_text_location )
892893 errors .extend (validation_errors )
893894
894895 # do not forget to resolve about resource paths
@@ -937,7 +938,7 @@ def load_lines(self, lines, base_dir):
937938 self .errors = errors
938939 return errors
939940
940- def load_dict (self , fields_dict , base_dir , license_text_location = None , with_empty = True ):
941+ def load_dict (self , fields_dict , base_dir , license_notice_text_location = None , with_empty = True ):
941942 """
942943 Load the ABOUT file from a fields name/value mapping.
943944 If with_empty, create fields with no value for empty fields.
@@ -947,7 +948,7 @@ def load_dict(self, fields_dict, base_dir, license_text_location=None, with_empt
947948 fields = fields_dict .items ()
948949 if not with_empty :
949950 fields = [(n , v ) for n , v in fields_dict .items () if v ]
950- errors = self .process (fields , base_dir , license_text_location )
951+ errors = self .process (fields , base_dir , license_notice_text_location )
951952 self .errors = errors
952953 return errors
953954
@@ -1009,8 +1010,9 @@ def dump_lic(self, location, license_dict):
10091010 if not posixpath .exists (parent ):
10101011 os .makedirs (add_unc (parent ))
10111012
1012- if self .license .present and not self .license_file .present :
1013- special_char_in_expression , lic_list = parse_license_expression (self .license .value )
1013+ if self .license_expression .present and not self .license_file .present :
1014+ special_char_in_expression , lic_list = parse_license_expression (self .license_expression .value )
1015+ self .license = lic_list
10141016 if not special_char_in_expression :
10151017 for lic_key in lic_list :
10161018 try :
@@ -1347,8 +1349,8 @@ def pre_process_and_fetch_license_dict(abouts, api_url, api_key):
13471349 auth_error = Error (ERROR , u"Authorization denied. Invalid '--api_key'. License generation is skipped." )
13481350 if auth_error in errors :
13491351 break
1350- if about .license .present :
1351- special_char_in_expression , lic_list = parse_license_expression (about .license .value )
1352+ if about .license_expression .present :
1353+ special_char_in_expression , lic_list = parse_license_expression (about .license_expression .value )
13521354 if special_char_in_expression :
13531355 msg = (u"The following character(s) cannot be in the licesne_expression: " +
13541356 str (special_char_in_expression ))
0 commit comments