IAP GITLAB

Skip to content
Snippets Groups Projects
Commit ff48b423 authored by ralfulrich's avatar ralfulrich
Browse files

improvements

parent 9b0227fd
No related branches found
No related tags found
No related merge requests found
...@@ -21,43 +21,50 @@ extensions = [".cc", ".h", ".test"] ...@@ -21,43 +21,50 @@ extensions = [".cc", ".h", ".test"]
def checkNote(filename): def checkNote(filename):
startNote = -1 startNote = []
endNote = -1 endNote = []
isCopyright = False
lines = []
# read input file into lines
lines = []
with open(filename, "r") as file: with open(filename, "r") as file:
for line in file.readlines(): for line in file.readlines():
lines.append(line) lines.append(line)
file.close() file.close()
searchStatus = 0 #0:before comment block, #1 in comment block, #2 found copyright
blockStart = 0
for iLine in range(len(lines)): for iLine in range(len(lines)):
line = lines[iLine] line = lines[iLine]
if "/**" in line and startNote == -1: if "/*" in line and searchStatus==0:
startNote = iLine searchStatus = 1
if "copyright" in line.lower() and startNote>=0 and endNote==-1: blockStart = iLine
isCopyright = True if "copyright" in line.lower() and searchStatus>0:
if "*/" in line and startNote>=0 and endNote==-1: searchStatus = 2
endNote = iLine if "*/" in line:
searchStatus = 0
if searchStatus>=2:
startNote.append(blockStart)
endNote.append(iLine)
iLine += 1 iLine += 1
# now check if copyright notice is already there and identical... # now check if first copyright notices is already identical...
isSame = False isSame = False
if startNote>=0 and endNote>=0 and isCopyright: if len(startNote)>0:
isSame = True isSame = True
noteLines = text.split('\n') noteLines = text.split('\n')
for iLine in range(len(noteLines)-2): for iLine in range(len(noteLines)-2):
if startNote+iLine >= len(lines): if startNote[0]+iLine >= len(lines):
isSame = False isSame = False
break break
if noteLines[iLine+1].strip(" \n") != lines[startNote+iLine].strip(" \n"): if noteLines[iLine+1].strip(" \n") != lines[startNote[0]+iLine].strip(" \n"):
isSame = False isSame = False
print "not same: " + filename + " new=\'" + noteLines[iLine+1] + "\' vs old=\'" + lines[startNote+iLine].rstrip('\n') + "\'" print "need update: " + filename + " new=\'" + noteLines[iLine+1] + "\' vs old=\'" + lines[startNote+iLine].rstrip('\n') + "\'"
break break
# check if notice is the same print filename + " > " + str(count) + " " + str(startNote) + " " + str(endNote) + " " + str(isSame)
if isSame:
# check if notice is the same, or we need to remove multiple notices...
if isSame or count>1:
return return
# add (new) copyright notice here: # add (new) copyright notice here:
...@@ -68,12 +75,16 @@ def checkNote(filename): ...@@ -68,12 +75,16 @@ def checkNote(filename):
file.write(text) file.write(text)
firstLine = 0 for iLine in range(len(lines)):
if startNote>=0 and endNote>=0 and isCopyright:
firstLine = endNote + 2 skip = False
for iBlock in range(len(startNote)):
if iLine>=startNote[iBlock] and iLine<endNote[iBlock]:
print " " + lines[iLine] + " [remove " + str(iBlock) + "]"
skip = True
for iLine in range(firstLine, len(lines)): if not skip:
file.write(lines[iLine]) file.write(lines[iLine])
file.close() file.close()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment