IAP GITLAB

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

fixed script

parent 85558652
No related branches found
No related tags found
No related merge requests found
...@@ -16,7 +16,7 @@ text = """ ...@@ -16,7 +16,7 @@ text = """
* This software is distributed under the terms of the GNU General Public * This software is distributed under the terms of the GNU General Public
* Licence version 3 (GPL Version 3). See file LICENSE for a full version of * Licence version 3 (GPL Version 3). See file LICENSE for a full version of
* the license. * the license.
*/ */\n
""" """
Debug = 0 # 0: nothing, 1: checking, 2: filesystem Debug = 0 # 0: nothing, 1: checking, 2: filesystem
...@@ -29,10 +29,13 @@ extensions = [".cc", ".h", ".test"] ...@@ -29,10 +29,13 @@ extensions = [".cc", ".h", ".test"]
justCheck = True # T: only checking, F: also changing files justCheck = True # T: only checking, F: also changing files
foundMissing = False foundMissing = False
forYear="YEAR" # replace this with year via command line
############################################### ###############################################
# #
def checkNote(filename): def checkNote(filename):
global foundMissing, justCheck global foundMissing, justCheck, forYear
if Debug>0: if Debug>0:
print ("***********************************************") print ("***********************************************")
...@@ -92,8 +95,10 @@ def checkNote(filename): ...@@ -92,8 +95,10 @@ def checkNote(filename):
if isSame and len(startNote)<=1: if isSame and len(startNote)<=1:
return return
print ("No copyright note in file: " + filename) if (len(startNote)==0):
print ("No copyright note in file: " + filename)
# either we found a file with no copyright, or with wrong copyright notice here
if justCheck: if justCheck:
foundMissing = True foundMissing = True
return return
...@@ -104,8 +109,9 @@ def checkNote(filename): ...@@ -104,8 +109,9 @@ def checkNote(filename):
with open(filename, "w") as file: with open(filename, "w") as file:
file.write(text) textReplace = re.sub(r"Copyright YEAR ", "Copyright " + forYear + " ", text)
file.write(textReplace)
skip = False skip = False
for iLine in range(len(lines)): for iLine in range(len(lines)):
...@@ -130,7 +136,9 @@ def checkNote(filename): ...@@ -130,7 +136,9 @@ def checkNote(filename):
############################################### ###############################################
# #
#def next_file(x, dir_name, files): # check files: loops over list of files,
# excludes if wished, process otherwise
#
def next_file(dir_name, files): def next_file(dir_name, files):
for check in excludeDirs : for check in excludeDirs :
if check in dir_name: if check in dir_name:
...@@ -161,22 +169,24 @@ def next_file(dir_name, files): ...@@ -161,22 +169,24 @@ def next_file(dir_name, files):
############################################### ###############################################
# the main program # the main program
def main(argv): def main(argv):
global justCheck, foundMissing, Debug global justCheck, foundMissing, Debug, forYear
justCheck = True justCheck = True
Debug = 0 Debug = 0
try: try:
opts, args = getopt.getopt(argv, "cIhd:", ["check", "implement", "debug="]) opts, args = getopt.getopt(argv, "cAhd:", ["check", "add=", "debug="])
except getopt.GetoptError: except getopt.GetoptError:
print 'do-copyright.py [--check] [--implement] [--debug=0]' print 'do-copyright.py [--check] [--add=YEAR] [--debug=0]'
sys.exit(2) sys.exit(2)
for opt, arg in opts: for opt, arg in opts:
if opt == '-h': if opt == '-h':
print 'do-copyright.py [--check] [--implement] [--debug=0]' print 'do-copyright.py [--check] [--add=YEAR] [--debug=0]'
sys.exit() sys.exit()
elif opt in ("-c", "--check"): elif opt in ("-c", "--check"):
justCheck = True justCheck = True
elif opt in ("-I", "--implement"): elif opt in ("-A", "--add"):
justCheck = False justCheck = False
forYear = str(arg)
print 'Adding \'Copyright ' + forYear + '\' notice, where needed. '
elif opt in ("-d", "--debug"): elif opt in ("-d", "--debug"):
Debug = int(arg) Debug = int(arg)
......
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