Skip to content

Commit 0ee07a5

Browse files
committed
Fixed #321 throw file not exist errors
* Remove the temp fix for #286 * The *_file not exist error is now working Signed-off-by: Chin Yeung Li <[email protected]>
1 parent 9b4f0ca commit 0ee07a5

File tree

4 files changed

+11
-64
lines changed

4 files changed

+11
-64
lines changed

src/attributecode/cmd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ def log_errors(errors, quiet, verbose, base_dir=False):
419419
elif sever in problematic_errors:
420420
print(msg_format % locals())
421421
if base_dir:
422-
# The logger will only log error if severity >= 30
422+
# The logger will only log error for severity >= 30
423423
file_logger.log(severity, msg_format % locals())
424424

425425

src/attributecode/gen.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# -*- coding: utf8 -*-
33

44
# ============================================================================
5-
# Copyright (c) 2013-2017 nexB Inc. http://www.nexb.com/ - All rights reserved.
5+
# Copyright (c) 2013-2018 nexB Inc. http://www.nexb.com/ - All rights reserved.
66
# Licensed under the Apache License, Version 2.0 (the "License");
77
# you may not use this file except in compliance with the License.
88
# You may obtain a copy of the License at
@@ -35,7 +35,6 @@
3535
from attributecode import CRITICAL
3636
from attributecode import Error
3737
from attributecode import model
38-
from attributecode.model import check_file_field_exist
3938
from attributecode import util
4039
from attributecode.util import add_unc
4140
from attributecode.util import to_posix
@@ -304,13 +303,8 @@ def generate(location, base_dir, license_notice_text_location=None,
304303

305304
# Write the ABOUT files
306305
about.dump(dump_loc, with_empty=with_empty, with_absent=with_absent)
307-
308-
file_field_not_exist_errors = check_file_field_exist(about, dump_loc)
309-
310306
for e in not_exist_errors:
311307
errors.append(Error(ERROR, e))
312-
for e in file_field_not_exist_errors:
313-
errors.append(Error(ERROR, e))
314308
except Exception as e:
315309
# only keep the first 100 char of the exception
316310
emsg = repr(e)[:100]

src/attributecode/model.py

Lines changed: 5 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python
22
# -*- coding: utf8 -*-
33
# ============================================================================
4-
# Copyright (c) 2013-2017 nexB Inc. http://www.nexb.com/ - All rights reserved.
4+
# Copyright (c) 2013-2018 nexB Inc. http://www.nexb.com/ - All rights reserved.
55
# Licensed under the Apache License, Version 2.0 (the "License");
66
# you may not use this file except in compliance with the License.
77
# You may obtain a copy of the License at
@@ -385,9 +385,6 @@ def _validate(self, *args, **kwargs):
385385
self.base_dir = util.to_posix(self.base_dir)
386386

387387
name = self.name
388-
# FIXME: This is a temp fix for #286
389-
# The field in ignore_checking_list is validated in the check_file_field_exist function
390-
ignore_checking_list = [u'license_file', u'notice_file', u'changelog_file']
391388

392389
# mapping of normalized paths to a location or None
393390
paths = OrderedDict()
@@ -416,7 +413,7 @@ def _validate(self, *args, **kwargs):
416413
paths[path] = location
417414
continue
418415

419-
if self.license_notice_text_location and name in ignore_checking_list:
416+
if self.license_notice_text_location:
420417
location = posixpath.join(self.license_notice_text_location, path)
421418
else:
422419
# The 'about_resource_path' should be a joined path with
@@ -442,10 +439,9 @@ def _validate(self, *args, **kwargs):
442439
if not os.path.exists(location):
443440
# We don't want to show the UNC_PREFIX in the error message
444441
location = util.to_posix(location.strip(UNC_PREFIX))
445-
if not name in ignore_checking_list:
446-
msg = (u'Field %(name)s: Path %(location)s not found'
447-
% locals())
448-
errors.append(Error(CRITICAL, msg))
442+
msg = (u'Field %(name)s: Path %(location)s not found'
443+
% locals())
444+
errors.append(Error(CRITICAL, msg))
449445
location = None
450446

451447
paths[path] = location
@@ -1499,45 +1495,3 @@ def verify_license_files_in_location(about, lic_location):
14991495
return license_location_dict, errors
15001496

15011497

1502-
def check_file_field_exist(about, location):
1503-
"""
1504-
Return a list of errors for non-existence file in file fields
1505-
"""
1506-
errors = []
1507-
loc = util.to_posix(location)
1508-
parent = posixpath.dirname(loc)
1509-
1510-
about_file_path = util.to_posix(os.path.join(parent, os.path.basename(parent)))
1511-
1512-
# The model only has the following as FileTextField
1513-
license_files = about.license_file.value
1514-
notice_files = about.notice_file.value
1515-
changelog_files = about.changelog_file.value
1516-
1517-
if license_files:
1518-
for lic in license_files:
1519-
lic_path = posixpath.join(dirname(util.to_posix(about_file_path)), lic)
1520-
if not posixpath.exists(lic_path):
1521-
msg = (u'Field license_file: Path '
1522-
u'%(lic_path)s '
1523-
u'not found' % locals())
1524-
errors.append(msg)
1525-
1526-
if notice_files:
1527-
for notice in notice_files:
1528-
notice_path = posixpath.join(dirname(util.to_posix(about_file_path)), notice)
1529-
if not posixpath.exists(notice_path):
1530-
msg = (u'Field notice_file: Path '
1531-
u'%(notice_path)s '
1532-
u'not found' % locals())
1533-
errors.append(msg)
1534-
1535-
if changelog_files:
1536-
for changelog in changelog_files:
1537-
changelog_path = posixpath.join(dirname(util.to_posix(about_file_path)), changelog)
1538-
if not posixpath.exists(changelog_path):
1539-
msg = (u'Field changelog_file: Path '
1540-
u'%(changelog_path)s '
1541-
u'not found' % locals())
1542-
errors.append(msg)
1543-
return errors

tests/test_model.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# -*- coding: utf8 -*-
33

44
# ============================================================================
5-
# Copyright (c) 2014-2017 nexB Inc. http://www.nexb.com/ - All rights reserved.
5+
# Copyright (c) 2014-2018 nexB Inc. http://www.nexb.com/ - All rights reserved.
66
# Licensed under the Apache License, Version 2.0 (the "License");
77
# you may not use this file except in compliance with the License.
88
# You may obtain a copy of the License at
@@ -518,12 +518,11 @@ def test_About_file_fields_are_empty_if_present_and_path_missing(self):
518518
file_path1 = posixpath.join(posixpath.dirname(test_file), 'test.LICENSE')
519519
file_path2 = posixpath.join(posixpath.dirname(test_file), 'test.NOTICE')
520520

521-
err_msg1 = u'Field license_file: Path %s not found' % file_path1
522-
err_msg2 = u'Field notice_file: Path %s not found' % file_path2
521+
err_msg1 = Error(CRITICAL, 'Field license_file: Path %s not found' % file_path1)
522+
err_msg2 = Error(CRITICAL, 'Field notice_file: Path %s not found' % file_path2)
523523

524524
expected_errors = [err_msg1, err_msg2]
525-
errors = model.check_file_field_exist(a, test_file)
526-
assert expected_errors == errors
525+
assert expected_errors == a.errors
527526

528527
assert {'test.LICENSE': None} == a.license_file.value
529528
assert {'test.NOTICE': None} == a.notice_file.value

0 commit comments

Comments
 (0)