3434import os
3535# FIXME: why posixpath???
3636import posixpath
37+ import re
3738
3839import yaml
39- import re
4040
4141from attributecode .util import python2
4242
@@ -420,7 +420,7 @@ def _validate(self, *args, **kwargs):
420420 self .about_file_path = kwargs .get ('about_file_path' )
421421 self .running_inventory = kwargs .get ('running_inventory' )
422422 self .base_dir = kwargs .get ('base_dir' )
423- self .license_notice_text_location = kwargs .get ('license_notice_text_location ' )
423+ self .reference_dir = kwargs .get ('reference_dir ' )
424424
425425 if self .base_dir :
426426 self .base_dir = util .to_posix (self .base_dir )
@@ -447,16 +447,16 @@ def _validate(self, *args, **kwargs):
447447 # the license files, if need to be copied, are located under the path
448448 # set from the 'license-text-location' option, so the tool should check
449449 # at the 'license-text-location' instead of the 'base_dir'
450- if not (self .base_dir or self .license_notice_text_location ):
450+ if not (self .base_dir or self .reference_dir ):
451451 msg = (u'Field %(name)s: Unable to verify path: %(path)s:'
452452 u' No base directory provided' % locals ())
453453 errors .append (Error (ERROR , msg ))
454454 location = None
455455 paths [path ] = location
456456 continue
457457
458- if self .license_notice_text_location :
459- location = posixpath .join (self .license_notice_text_location , path )
458+ if self .reference_dir :
459+ location = posixpath .join (self .reference_dir , path )
460460 else :
461461 # The 'about_resource' should be a joined path with
462462 # the 'about_file_path' and the 'base_dir
@@ -669,7 +669,7 @@ def __eq__(self, other):
669669
670670
671671def validate_fields (fields , about_file_path , running_inventory , base_dir ,
672- license_notice_text_location = None ):
672+ reference_dir = None ):
673673 """
674674 Validate a sequence of Field objects. Return a list of errors.
675675 Validation may update the Field objects as needed as a side effect.
@@ -680,7 +680,7 @@ def validate_fields(fields, about_file_path, running_inventory, base_dir,
680680 base_dir = base_dir ,
681681 about_file_path = about_file_path ,
682682 running_inventory = running_inventory ,
683- license_notice_text_location = license_notice_text_location ,
683+ reference_dir = reference_dir ,
684684 )
685685 errors .extend (val_err )
686686 return errors
@@ -972,28 +972,29 @@ def hydrate(self, fields, mapping_file=None):
972972 return errors
973973
974974 def process (self , fields , about_file_path , running_inventory = False ,
975- base_dir = None , license_notice_text_location = None ,
975+ base_dir = None , reference_dir = None ,
976976 mapping_file = None ):
977977 """
978- Hydrate and validate a sequence of field name/value tuples from an
979- ABOUT file . Return a list of errors.
978+ Validate and set as attributes on this About object a sequence of
979+ `fields` name/value tuples . Return a list of errors.
980980 """
981981 self .base_dir = base_dir
982- self .license_notice_text_location = license_notice_text_location
982+ self .reference_dir = reference_dir
983983 afp = self .about_file_path
984984 errors = []
985985 hydratation_errors = self .hydrate (fields , mapping_file = mapping_file )
986986 errors .extend (hydratation_errors )
987987
988988 # We want to copy the license_files before the validation
989- if license_notice_text_location :
989+ if reference_dir :
990990 copy_license_notice_files (
991- fields , base_dir , license_notice_text_location , afp )
991+ fields , base_dir , reference_dir , afp )
992+
992993 # we validate all fields, not only these hydrated
993994 all_fields = self .all_fields ()
994995 validation_errors = validate_fields (
995996 all_fields , about_file_path , running_inventory ,
996- self .base_dir , self .license_notice_text_location )
997+ self .base_dir , self .reference_dir )
997998 errors .extend (validation_errors )
998999
9991000 # do not forget to resolve about resource paths The
@@ -1043,12 +1044,10 @@ def load(self, location, mapping_file=None):
10431044 # FIXME: an About object should not know about mappings
10441045 def load_dict (self , fields_dict , base_dir , running_inventory = False ,
10451046 mapping_file = None ,
1046- license_notice_text_location = None , with_empty = True ):
1047+ reference_dir = None , with_empty = True ):
10471048 """
1048- Load the ABOUT file from a fields name/value mapping.
1049- If with_empty, create fields with no value for empty fields.
1050- Return a list of
1051- errors.
1049+ Load this About object file from a `fields_dict` name/value mapping.
1050+ Return a list of errors.
10521051 """
10531052 fields = list (fields_dict .items ())
10541053 about_file_path = self .about_file_path
@@ -1076,7 +1075,7 @@ def load_dict(self, fields_dict, base_dir, running_inventory=False,
10761075 about_file_path = about_file_path ,
10771076 running_inventory = running_inventory ,
10781077 base_dir = base_dir ,
1079- license_notice_text_location = license_notice_text_location ,
1078+ reference_dir = reference_dir ,
10801079 mapping_file = mapping_file )
10811080 self .errors = errors
10821081 return errors
@@ -1193,7 +1192,7 @@ def dump_lic(self, location, license_dict):
11931192# valid field name
11941193field_name = r'(?P<name>[a-z][0-9a-z_]*)'
11951194
1196- valid_field_name = re .compile (field_name , re .UNICODE | re .IGNORECASE ).match
1195+ valid_field_name = re .compile (field_name , re .UNICODE | re .IGNORECASE ).match # NOQA
11971196
11981197# line in the form of "name: value"
11991198field_declaration = re .compile (
@@ -1202,7 +1201,7 @@ def dump_lic(self, location, license_dict):
12021201 r'\s*:\s*'
12031202 r'(?P<value>.*)'
12041203 r'\s*$'
1205- , re .UNICODE | re .IGNORECASE
1204+ , re .UNICODE | re .IGNORECASE # NOQA
12061205 ).match
12071206
12081207
@@ -1212,7 +1211,7 @@ def dump_lic(self, location, license_dict):
12121211 r' '
12131212 r'(?P<value>.*)'
12141213 r'\s*$'
1215- , re .UNICODE | re .IGNORECASE
1214+ , re .UNICODE | re .IGNORECASE # NOQA
12161215 ).match
12171216
12181217
0 commit comments