2020-06-12 23:38:29 +02:00
|
|
|
#!/usr/bin/env python3
|
util/: Replace GPLv2 boiler plate with SPDX header
Used commands:
perl -i -p0e 's|\/\*[\s*]*.*is free software[:;][\s*]*you[\s*]*can[\s*]*redistribute[\s*]*it[\s*]*and\/or[\s*]*modify[\s*]*it[\s*]*under[\s*]*the[\s*]*terms[\s*]*of[\s*]*the[\s*]*GNU[\s*]*General[\s*]*Public[\s*]*License[\s*]*as[\s*]*published[\s*]*by[\s*]*the[\s*]*Free[\s*]*Software[\s*]*Foundation[;,][\s*]*version[\s*]*2[\s*]*of[\s*]*the[\s*]*License.[\s*]*This[\s*]*program[\s*]*is[\s*]*distributed[\s*]*in[\s*]*the[\s*]*hope[\s*]*that[\s*]*it[\s*]*will[\s*]*be[\s*]*useful,[\s*]*but[\s*]*WITHOUT[\s*]*ANY[\s*]*WARRANTY;[\s*]*without[\s*]*even[\s*]*the[\s*]*implied[\s*]*warranty[\s*]*of[\s*]*MERCHANTABILITY[\s*]*or[\s*]*FITNESS[\s*]*FOR[\s*]*A[\s*]*PARTICULAR[\s*]*PURPOSE.[\s*]*See[\s*]*the[\s*]*GNU[\s*]*General[\s*]*Public[\s*]*License[\s*]*for[\s*]*more[\s*]*details.[\s*]*\*\/|/* SPDX-License-Identifier: GPL-2.0-only */|' $(cat filelist)
perl -i -p0e 's|This[\s*]*program[\s*]*is[\s*]*free[\s*]*software[:;][\s*]*you[\s*]*can[\s*]*redistribute[\s*]*it[\s*]*and/or[\s*]*modify[\s*]*it[\s*]*under[\s*]*the[\s*]*terms[\s*]*of[\s*]*the[\s*]*GNU[\s*]*General[\s*]*Public[\s*]*License[\s*]*as[\s*]*published[\s*]*by[\s*]*the[\s*]*Free[\s*]*Software[\s*]*Foundation[;,][\s*]*either[\s*]*version[\s*]*2[\s*]*of[\s*]*the[\s*]*License,[\s*]*or[\s*]*.at[\s*]*your[\s*]*option.*[\s*]*any[\s*]*later[\s*]*version.[\s*]*This[\s*]*program[\s*]*is[\s*]*distributed[\s*]*in[\s*]*the[\s*]*hope[\s*]*that[\s*]*it[\s*]*will[\s*]*be[\s*]*useful,[\s*]*but[\s*]*WITHOUT[\s*]*ANY[\s*]*WARRANTY;[\s*]*without[\s*]*even[\s*]*the[\s*]*implied[\s*]*warranty[\s*]*of[\s*]*MERCHANTABILITY[\s*]*or[\s*]*FITNESS[\s*]*FOR[\s*]*A[\s*]*PARTICULAR[\s*]*PURPOSE.[\s*]*See[\s*]*the[\s*]*GNU[\s*]*General[\s*]*Public[\s*]*License[\s*]*for[\s*]*more[\s*]*details.[\s*]*\*\/|/* SPDX-License-Identifier: GPL-2.0-or-later */|' $(cat filelist)
perl -i -p0e 's|\/\*[\s*]*.*This[\s*#]*program[\s*#]*is[\s*#]*free[\s*#]*software[;:,][\s*#]*you[\s*#]*can[\s*#]*redistribute[\s*#]*it[\s*#]*and/or[\s*#]*modify[\s*#]*it[\s*#]*under[\s*#]*the[\s*#]*terms[\s*#]*of[\s*#]*the[\s*#]*GNU[\s*#]*General[\s*#]*Public[\s*#]*License[\s*#]*as[\s*#]*published[\s*#]*by[\s*#]*the[\s*#]*Free[\s*#]*Software[\s*#]*Foundation[;:,][\s*#]*either[\s*#]*version[\s*#]*3[\s*#]*of[\s*#]*the[\s*#]*License[;:,][\s*#]*or[\s*#]*.at[\s*#]*your[\s*#]*option.*[\s*#]*any[\s*#]*later[\s*#]*version.[\s*#]*This[\s*#]*program[\s*#]*is[\s*#]*distributed[\s*#]*in[\s*#]*the[\s*#]*hope[\s*#]*that[\s*#]*it[\s*#]*will[\s*#]*be[\s*#]*useful[;:,][\s*#]*but[\s*#]*WITHOUT[\s*#]*ANY[\s*#]*WARRANTY[;:,][\s*#]*without[\s*#]*even[\s*#]*the[\s*#]*implied[\s*#]*warranty[\s*#]*of[\s*#]*MERCHANTABILITY[\s*#]*or[\s*#]*FITNESS[\s*#]*FOR[\s*#]*A[\s*#]*PARTICULAR[\s*#]*PURPOSE.[\s*#]*See[\s*#]*the[\s*#]*GNU[\s*#]*General[\s*#]*Public[\s*#]*License[\s*#]*for[\s*#]*more[\s*#]*details.[\s*]*\*\/|/* SPDX-License-Identifier: GPL-3.0-or-later */|' $(cat filelist)
perl -i -p0e 's|(\#\#*)[\w]*.*is free software[:;][\#\s]*you[\#\s]*can[\#\s]*redistribute[\#\s]*it[\#\s]*and\/or[\#\s]*modify[\#\s]*it[\s\#]*under[\s \#]*the[\s\#]*terms[\s\#]*of[\s\#]*the[\s\#]*GNU[\s\#]*General[\s\#]*Public[\s\#]*License[\s\#]*as[\s\#]*published[\s\#]*by[\s\#]*the[\s\#]*Free[\s\#]*Software[\s\#]*Foundation[;,][\s\#]*version[\s\#]*2[\s\#]*of[\s\#]*the[\s\#]*License.*[\s\#]*This[\s\#]*program[\s\#]*is[\s\#]*distributed[\s\#]*in[\s\#]*the[\s\#]*hope[\s\#]*that[\s\#]*it[\s\#]*will[\#\s]*be[\#\s]*useful,[\#\s]*but[\#\s]*WITHOUT[\#\s]*ANY[\#\s]*WARRANTY;[\#\s]*without[\#\s]*even[\#\s]*the[\#\s]*implied[\#\s]*warranty[\#\s]*of[\#\s]*MERCHANTABILITY[\#\s]*or[\#\s]*FITNESS[\#\s]*FOR[\#\s]*A[\#\s]*PARTICULAR[\#\s]*PURPOSE.[\#\s]*See[\#\s]*the[\#\s]*GNU[\#\s]*General[\#\s]*Public[\#\s]*License[\#\s]*for[\#\s]*more[\#\s]*details.\s(#* *\n)*|\1 SPDX-License-Identifier: GPL-2.0-only\n\n|' $(cat filelist)
perl -i -p0e 's|(\#\#*)[\w*]*.*is free software[:;][\s*]*you[\s*]*can[\s*]*redistribute[\s*]*it[\s*]*and\/or[\s*]*modify[\s*]*it[\s*]*under[\s*]*the[\s*]*terms[\s*]*of[\s*]*the[\s*]*GNU[\s*]*General[\s*]*Public[\s*]*License[\s*]*as[\s*]*published[\s*]*by[\s*]*the[\s*]*Free[\s*]*Software[\s*]*Foundation[;,][\s*]*version[\s*]*2[\s*]*of[\s*]*the[\s*]*License.[\s*]*This[\s*]*program[\s*]*is[\s*]*distributed[\s*]*in[\s*]*the[\s*]*hope[\s*]*that[\s*]*it[\s*]*will[\s*]*be[\s*]*useful,[\s*]*but[\s*]*WITHOUT[\s*]*ANY[\s*]*WARRANTY;[\s*]*without[\s*]*even[\s*]*the[\s*]*implied[\s*]*warranty[\s*]*of[\s*]*MERCHANTABILITY[\s*]*or[\s*]*FITNESS[\s*]*FOR[\s*]*A[\s*]*PARTICULAR[\s*]*PURPOSE.[\s*]*See[\s*]*the[\s*]*GNU[\s*]*General[\s*]*Public[\s*]*License[\s*]*for[\s*]*more[\s*]*details.\s(#* *\n)*|\1 SPDX-License-Identifier: GPL-2.0-only\n\n|' $(cat filelist)
Change-Id: I1008a63b804f355a916221ac994701d7584f60ff
Signed-off-by: Patrick Georgi <pgeorgi@google.com>
Signed-off-by: Elyes HAOUAS <ehaouas@noos.fr>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/41177
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
2020-05-08 20:48:04 +02:00
|
|
|
# SPDX-License-Identifier: GPL-2.0-only
|
2018-01-25 14:32:25 +01:00
|
|
|
|
|
|
|
"""
|
|
|
|
This utilty generate json output to post comment in gerrit.
|
|
|
|
|
|
|
|
INPUT: output of checkpatch.pl.
|
|
|
|
OUTPUT: json format output that can be used to post comment in gerrit
|
|
|
|
"""
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import json
|
2022-03-23 00:59:27 +01:00
|
|
|
import re
|
2018-01-25 14:32:25 +01:00
|
|
|
|
|
|
|
data = {}
|
|
|
|
data['comments'] = []
|
|
|
|
list_temp = {}
|
|
|
|
|
|
|
|
def update_struct( file_path, msg_output, line_number):
|
|
|
|
if file_path not in list_temp:
|
|
|
|
list_temp[file_path] = []
|
|
|
|
list_temp[file_path].append({
|
2021-03-15 21:07:05 +01:00
|
|
|
"robot_id" : "checkpatch",
|
|
|
|
"robot_run_id" : sys.argv[3],
|
|
|
|
"url" : sys.argv[4],
|
2018-01-25 14:32:25 +01:00
|
|
|
"line" : line_number,
|
2023-07-10 10:07:17 +02:00
|
|
|
"message" : "`" + msg_output + "`",
|
|
|
|
})
|
2018-01-25 14:32:25 +01:00
|
|
|
|
|
|
|
def parse_file(input_file):
|
|
|
|
fp = open (input_file, "r")
|
|
|
|
for line in fp:
|
2018-06-20 11:23:57 +02:00
|
|
|
if line.startswith("ERROR:"):
|
2018-01-25 14:32:25 +01:00
|
|
|
msg_output = line.split("ERROR:")[1].strip()
|
2018-06-20 11:23:57 +02:00
|
|
|
elif line.startswith("WARNING:"):
|
2018-01-25 14:32:25 +01:00
|
|
|
msg_output = line.split("WARNING:")[1].strip()
|
2018-06-20 11:23:57 +02:00
|
|
|
elif ": FILE:" in line:
|
2018-01-25 14:32:25 +01:00
|
|
|
temp = line.split("FILE:")
|
|
|
|
file_path = temp[1].split(":")[0]
|
|
|
|
line_number = temp[1].split(":")[1]
|
|
|
|
update_struct( file_path.strip(), msg_output, str(line_number) )
|
2022-03-23 00:59:27 +01:00
|
|
|
elif re.search("^\d+:\Z",line) != "None" and line.startswith("#"):
|
|
|
|
file_path="/COMMIT_MSG"
|
|
|
|
line = line.replace('#', '')
|
|
|
|
line_number = int(line.split(":")[0]) + 2
|
|
|
|
update_struct( file_path.strip(), msg_output, str(line_number) )
|
2018-01-25 14:32:25 +01:00
|
|
|
else:
|
|
|
|
continue
|
|
|
|
fp.close()
|
|
|
|
|
|
|
|
def main():
|
2021-03-15 21:07:05 +01:00
|
|
|
if (len(sys.argv) < 5) or (sys.argv[1] == "-h"):
|
2020-06-12 23:38:29 +02:00
|
|
|
print("HELP:")
|
2021-03-15 21:07:05 +01:00
|
|
|
print(sys.argv[0] + " <input file> <output file in json> <job-id> <job-url>")
|
2018-01-25 14:32:25 +01:00
|
|
|
sys.exit()
|
|
|
|
|
2020-06-12 23:38:29 +02:00
|
|
|
print(sys.argv[1])
|
2018-01-25 14:32:25 +01:00
|
|
|
parse_file(sys.argv[1])
|
2021-03-15 21:07:05 +01:00
|
|
|
data['robot_comments'] = list_temp
|
2020-06-12 23:38:29 +02:00
|
|
|
print(json.dumps(data))
|
2018-01-25 14:32:25 +01:00
|
|
|
out_file = open( sys.argv[2] , "w")
|
|
|
|
json.dump(data, out_file, sort_keys=True, indent=4)
|
|
|
|
out_file.close()
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|