Skip to content

Commit d906305

Browse files
committed
Code update/enhancement
* The `about_resource` is no longer an AboutResourceField. Instead, the `about_resource_path` is. The `about_resource` can be think of as a filename of the resource while the `about_resource_path` reference where are these resource located. For instance, the `about_resource` can be 'commons-looging.jar` and the `about_resource_path` can be: `./production/commons-logging.jar` and `./test/commons-logging.jar` Signed-off-by: Chin Yeung Li <[email protected]>
1 parent 04a7b19 commit d906305

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

src/attributecode/model.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,9 @@ def _validate(self, *args, **kwargs):
383383
self.base_dir = util.to_posix(self.base_dir)
384384

385385
name = self.name
386+
# FIXME: This is a temp fix for #286
387+
# The field in ignore_checking_list is validated in the check_file_field_exist function
388+
ignore_checking_list = [u'license_file', u'notice_file', u'changelog_file']
386389
# mapping of normalized paths to a location or None
387390
paths = OrderedDict()
388391
for path in self.value:
@@ -402,12 +405,12 @@ def _validate(self, *args, **kwargs):
402405
# set from the 'license-text-location' option, so the tool should check
403406
# at the 'license-text-location' instead of the 'base_dir'
404407
if self.base_dir or self.license_notice_text_location:
405-
if self.license_notice_text_location:
408+
if self.license_notice_text_location and name in ignore_checking_list:
406409
location = posixpath.join(self.license_notice_text_location, path)
407410
else:
408411
# The 'about_resource_path' should be a joined path with
409412
# the 'about_file_path' and the 'base_dir
410-
if not self.running_inventory and name == 'about_resource_path':
413+
if not self.running_inventory and self.about_file_path:
411414
# Get the parent directory of the 'about_file_path'
412415
afp_parent = posixpath.dirname(self.about_file_path)
413416

@@ -427,9 +430,6 @@ def _validate(self, *args, **kwargs):
427430
if not os.path.exists(location):
428431
# We don't want to show the UNC_PREFIX in the error message
429432
location = util.to_posix(location.strip(UNC_PREFIX))
430-
# FIXME: This is a temp fix for #286
431-
# The field in ignore_checking_list is validated in the check_file_field_exist function
432-
ignore_checking_list = [u'license_file', u'notice_file', u'changelog_file']
433433
if not name in ignore_checking_list:
434434
msg = (u'Field %(name)s: Path %(location)s not found'
435435
% locals())
@@ -647,9 +647,10 @@ def create_fields(self):
647647
648648
"""
649649
self.fields = OrderedDict([
650-
('about_resource', AboutResourceField(required=True)),
650+
('about_resource', ListField(required=True)),
651+
#('about_resource', AboutResourceField(required=True)),
651652
('name', SingleLineField(required=True)),
652-
('about_resource_path', PathField()),
653+
('about_resource_path', AboutResourceField()),
653654

654655
('version', SingleLineField()),
655656
('download_url', UrlField()),
@@ -758,7 +759,7 @@ def resolved_resources_paths(self):
758759
"""
759760
Return a serialized string of resolved resource paths, one per line.
760761
"""
761-
abrf = self.about_resource
762+
abrf = self.about_resource_path
762763
abrf.resolve(self.about_file_path)
763764
return u'\n'.join(abrf.resolved_paths)
764765

@@ -934,7 +935,8 @@ def process(self, fields, about_file_path, running_inventory=False, base_dir=Non
934935
errors.extend(validation_errors)
935936

936937
# do not forget to resolve about resource paths
937-
self.about_resource.resolve(self.about_file_path)
938+
# The 'about_resource' field is now a ListField and those do not need to resolve
939+
# self.about_resource.resolve(self.about_file_path)
938940
return errors
939941

940942
def load(self, location):
@@ -1038,10 +1040,12 @@ def dump(self, location, with_absent=False, with_empty=True):
10381040
about_file_path = add_unc(about_file_path)
10391041
with codecs.open(about_file_path, mode='wb', encoding='utf-8') as dumped:
10401042
dumped.write(self.dumps(with_absent, with_empty))
1041-
for about_resource_value in self.about_resource.value:
1043+
# FIXME: Why do I have to check here? Shouldn't it be checked during validation?
1044+
for about_resource_value in self.about_resource_path.value:
10421045
path = posixpath.join(dirname(util.to_posix(about_file_path)), about_resource_value)
10431046
if not posixpath.exists(path):
10441047
path = util.to_posix(path.strip(UNC_PREFIX_POSIX))
1048+
path = os.path.normpath(path)
10451049
msg = (u'The reference file : '
10461050
u'%(path)s '
10471051
u'does not exist' % locals())

0 commit comments

Comments
 (0)