utils/get-developers: print error for correct line

Start counting the line numbers in 1 instead of 0, in case an error
must be printed.

Both the error about a developer entry with no file entry and the error
about a file entry with no developer entry actually belong to the
non-empty line previous the one being analysed, so in these cases print
the line number from the line before.

Also count empty and comment lines, so a developer fixing the file can
jump to the correct line (or the nearest one).

At same time standardize the messages, printing the line number
also in the case of a warning for a file that is not in the tree
anymore.

Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Signed-off-by: Ricardo Martincoski <ricardo.martincoski@gmail.com>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
2023.02.x
Ricardo Martincoski 2022-11-27 11:48:19 -03:00 committed by Thomas Petazzoni
parent 5ee1dd85a3
commit de03312db0
2 changed files with 11 additions and 11 deletions

View File

@ -48,7 +48,7 @@ class TestGetDevelopers(unittest.TestCase):
# -v generating error, called from the main dir
developers = b'text1\n'
out, err, rc = call_get_developers("./utils/get-developers", ["-v"], self.WITH_EMPTY_PATH, topdir, developers)
self.assertIn("Syntax error in DEVELOPERS file, line 0: 'text1'", err)
self.assertIn("Syntax error in DEVELOPERS file, line 1: 'text1'", err)
self.assertEqual(rc, 1)
self.assertEqual(len(out), 0)
self.assertEqual(len(err), 1)
@ -56,7 +56,7 @@ class TestGetDevelopers(unittest.TestCase):
# -v generating error, called from path
developers = b'text2\n'
out, err, rc = call_get_developers("get-developers", ["-v"], self.WITH_UTILS_IN_PATH, topdir, developers)
self.assertIn("Syntax error in DEVELOPERS file, line 0: 'text2'", err)
self.assertIn("Syntax error in DEVELOPERS file, line 1: 'text2'", err)
self.assertEqual(rc, 1)
self.assertEqual(len(out), 0)
self.assertEqual(len(err), 1)
@ -69,7 +69,7 @@ class TestGetDevelopers(unittest.TestCase):
b'N:\tAuthor2 <email>\n' \
b'F:\tutils/get-developers\n'
out, err, rc = call_get_developers("get-developers", ["-v"], self.WITH_UTILS_IN_PATH, topdir, developers)
self.assertIn("Syntax error in DEVELOPERS file, line 1", err)
self.assertIn("Syntax error in DEVELOPERS file, line 4", err)
self.assertEqual(rc, 1)
self.assertEqual(len(out), 0)
self.assertEqual(len(err), 1)
@ -83,7 +83,7 @@ class TestGetDevelopers(unittest.TestCase):
b'N:\tAuthor3 <email>\n' \
b'F:\tutils/get-developers\n'
out, err, rc = call_get_developers("get-developers", ["-v"], self.WITH_UTILS_IN_PATH, topdir, developers)
self.assertIn("Syntax error in DEVELOPERS file, line 1", err)
self.assertIn("Syntax error in DEVELOPERS file, line 4", err)
self.assertEqual(rc, 1)
self.assertEqual(len(out), 0)
self.assertEqual(len(err), 1)
@ -108,8 +108,8 @@ class TestGetDevelopers(unittest.TestCase):
b'F:\tpath/that/does/not/exists/1\n' \
b'F:\tpath/that/does/not/exists/2\n'
out, err, rc = call_get_developers("get-developers", ["-v"], self.WITH_UTILS_IN_PATH, topdir, developers)
self.assertIn("WARNING: 'path/that/does/not/exists/1' doesn't match any file", err)
self.assertIn("WARNING: 'path/that/does/not/exists/2' doesn't match any file", err)
self.assertIn("WARNING: 'path/that/does/not/exists/1' doesn't match any file, line 2", err)
self.assertIn("WARNING: 'path/that/does/not/exists/2' doesn't match any file, line 3", err)
self.assertEqual(rc, 0)
self.assertEqual(len(out), 0)
self.assertEqual(len(err), 2)
@ -119,8 +119,8 @@ class TestGetDevelopers(unittest.TestCase):
b'F:\tpath/that/does/not/exists/1\n' \
b'F:\tpath/that/does/not/exists/2\n'
out, err, rc = call_get_developers("./utils/get-developers", ["-c"], self.WITH_EMPTY_PATH, topdir, developers)
self.assertIn("WARNING: 'path/that/does/not/exists/1' doesn't match any file", err)
self.assertIn("WARNING: 'path/that/does/not/exists/2' doesn't match any file", err)
self.assertIn("WARNING: 'path/that/does/not/exists/1' doesn't match any file, line 2", err)
self.assertIn("WARNING: 'path/that/does/not/exists/2' doesn't match any file, line 3", err)
self.assertEqual(rc, 0)
self.assertGreater(len(out), 1000)
self.assertEqual(len(err), 2)

View File

@ -236,12 +236,13 @@ def parse_developers(filename=None):
files = []
name = None
for line in f:
linen += 1
line = line.strip()
if line.startswith("#"):
continue
elif line.startswith("N:"):
if name is not None or len(files) != 0:
print("Syntax error in DEVELOPERS file, line %d" % linen,
print("Syntax error in DEVELOPERS file, line %d" % (linen - 1),
file=sys.stderr)
return None
name = line[2:].strip()
@ -249,7 +250,7 @@ def parse_developers(filename=None):
fname = line[2:].strip()
dev_files = glob.glob(os.path.join(brpath, fname))
if len(dev_files) == 0:
print("WARNING: '%s' doesn't match any file" % fname,
print("WARNING: '%s' doesn't match any file, line %d" % (fname, linen),
file=sys.stderr)
for f in dev_files:
dev_file = os.path.relpath(f, brpath)
@ -267,7 +268,6 @@ def parse_developers(filename=None):
print("Syntax error in DEVELOPERS file, line %d: '%s'" % (linen, line),
file=sys.stderr)
return None
linen += 1
# handle last developer
if name is not None:
developers.append(Developer(name, files))