mirror of
https://github.com/clearlinux/autospec.git
synced 2026-11-25 23:23:59 +00:00
Always handle the common tmepfile prefix for license_skips
Modify license skips to handle the common tempfile prefix of '/tmp/*' and normalize the case where lines lead with a slash vs not. Also remove a duplicate test for globlike match. Signed-off-by: William Douglas <william.douglas@intel.com>
This commit is contained in:
committed by
William Douglas
parent
185099bba8
commit
a19cdc79b4
+3
-3
@@ -129,9 +129,9 @@ release
|
||||
respectively. This results in less manual work via automatic management.
|
||||
|
||||
license_skips
|
||||
Each line in the file should be a full path, that path is prefixed into a
|
||||
tempfile directory + the package tarfile prefix. Requires using '*' to be
|
||||
effective (e.g. /tmp/*/pkgname-*/path/to/license).
|
||||
Each line in the file should be the path to a license file. That path needs
|
||||
to account for the package tarfile prefix. Likely requires using '*' to be
|
||||
effective (e.g. ``pkgname-*/path/to/license`` where ``*`` handles the version).
|
||||
|
||||
Files paths can contain a single '*' per directory such that
|
||||
a line of ``/foo*/bar*`` is allowed but ``/foo*bar*`` is not.
|
||||
|
||||
+5
-1
@@ -151,7 +151,11 @@ def skip_license(license_path, config):
|
||||
"""Check if a given license file path should be skipped."""
|
||||
skip_name = False
|
||||
for skip in config.license_skips:
|
||||
if util.globlike_match(license_path, skip):
|
||||
# handle the common tempfile prefix and normalize for
|
||||
# skip lines without a starting '/'
|
||||
skip = skip if skip[0] != '' else skip[1:]
|
||||
skip_path = ['', 'tmp', '*'] + skip
|
||||
if util.globlike_match(license_path, skip_path):
|
||||
util.print_warning(f"Skip license detected for file at {license_path}")
|
||||
skip_name = True
|
||||
break
|
||||
|
||||
+29
-1
@@ -239,7 +239,35 @@ class TestLicense(unittest.TestCase):
|
||||
"""
|
||||
conf = config.Config("")
|
||||
conf.setup_patterns()
|
||||
conf.license_skips = [['', 'tmp', '*', 'COPYING']]
|
||||
conf.license_skips = [['COPYING']]
|
||||
with open('tests/COPYING_TEST', 'rb') as copyingf:
|
||||
content = copyingf.read()
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmpd:
|
||||
# create the copying file
|
||||
with open(os.path.join(tmpd, 'COPYING'), 'w') as newcopyingf:
|
||||
newcopyingf.write(content.decode('utf-8'))
|
||||
# create some cruft for testing
|
||||
for testf in ['testlib.c', 'testmain.c', 'testheader.h']:
|
||||
with open(os.path.join(tmpd, testf), 'w') as newtestf:
|
||||
newtestf.write('test content')
|
||||
# let's check that the proper thing is being printed as well
|
||||
out = StringIO()
|
||||
with redirect_stdout(out):
|
||||
with self.assertRaises(SystemExit) as thread:
|
||||
license.scan_for_licenses(tmpd, conf, '')
|
||||
|
||||
self.assertEqual(thread.exception.code, 1)
|
||||
self.assertIn("Cannot find any license", out.getvalue())
|
||||
self.assertEqual(license.licenses, [])
|
||||
|
||||
def test_scan_for_licenses_skip_prefix_slash(self):
|
||||
"""
|
||||
Test scan_for_licenses in temporary directory with licenses to skip
|
||||
"""
|
||||
conf = config.Config("")
|
||||
conf.setup_patterns()
|
||||
conf.license_skips = [['', 'COPYING']]
|
||||
with open('tests/COPYING_TEST', 'rb') as copyingf:
|
||||
content = copyingf.read()
|
||||
|
||||
|
||||
@@ -106,10 +106,6 @@ class TestUtil(unittest.TestCase):
|
||||
file_path = 'a/ab'
|
||||
self.assertFalse(util.globlike_match(file_path, match_name))
|
||||
|
||||
match_name = ['a', 'b*']
|
||||
file_path = 'a/ab'
|
||||
self.assertFalse(util.globlike_match(file_path, match_name))
|
||||
|
||||
match_name = ['a', '*a']
|
||||
file_path = 'a/ab'
|
||||
self.assertFalse(util.globlike_match(file_path, match_name))
|
||||
|
||||
Reference in New Issue
Block a user