Commit 07c37593 authored by Ted Themistokleous's avatar Ted Themistokleous
Browse files

Backup of license stamper

parent a65e2971
...@@ -26,7 +26,7 @@ import subprocess, os ...@@ -26,7 +26,7 @@ import subprocess, os
import datetime import datetime
#Debug flag #Debug flag
debug = False debug = True
__repo_dir__ = os.path.normpath( __repo_dir__ = os.path.normpath(
os.path.join(os.path.realpath(__file__), '..', '..')) os.path.join(os.path.realpath(__file__), '..', '..'))
...@@ -68,17 +68,18 @@ def hasKeySequence(inputfile, key_message): ...@@ -68,17 +68,18 @@ def hasKeySequence(inputfile, key_message):
line_limit = 10 line_limit = 10
target_line = -1 target_line = -1
for line in inputfile: for line in inputfile.split("\n"):
if key_message in line: if key_message in line:
result = True result = True
target_line = line_cnt target_line = line_cnt
break break
line_cnt = line_cnt + 1
if line_cnt >= line_limit: if line_cnt >= line_limit:
break break
line_cnt = line_cnt + 1
return [result, target_line] return [result, target_line]
...@@ -157,11 +158,14 @@ def openAndWriteFile(filename, message, commentChar): ...@@ -157,11 +158,14 @@ def openAndWriteFile(filename, message, commentChar):
#read remaining lines in the original file #read remaining lines in the original file
save = contents.read() save = contents.read()
print(save)
hasAmdLic = hasKeySequence( hasAmdLic = hasKeySequence(
save, "Advanced Micro Devices, Inc. All rights reserved") save, "Advanced Micro Devices, Inc. All rights reserved")
hasOtherLic = hasKeySequence(save, "Software License") hasOtherLic = hasKeySequence(save, "Software License")
print(save)
#Check if we have a licence stamp already #Check if we have a licence stamp already
if hasAmdLic[0] or hasOtherLic[0] is True: if hasAmdLic[0] or hasOtherLic[0] is True:
hasOldAmdLic = hasKeySequence( hasOldAmdLic = hasKeySequence(
...@@ -186,24 +190,28 @@ def openAndWriteFile(filename, message, commentChar): ...@@ -186,24 +190,28 @@ def openAndWriteFile(filename, message, commentChar):
contents.close() contents.close()
return return
if debug is True:
print("...Writing header", end='')
if needs_update is True and update_line > -1: if needs_update is True and update_line > -1:
with open(filename, rw) as contents: if debug is True:
print("...Updating header\n", end='')
data = [next(filename) for x in range(update_line + 1)]
index = data[update_line].index("-")
data[update_line] = data[
update_line][:index] + current_year + data[update_line][index +
4:]
#write remaining contents # print(save)
contents.write(data) #
# index = data[update_line + 1].find("2015-")
# if index != -1:
# save[update_line + 1] = save[
# update_line+1][:index + 5] + current_year + save[update_line+1][index + 9:]
#
# print(str(data))
#
# with open(filename, 'w') as contents:
# #write remaining contents
# contents.seek(0)
# contents.write(save)
elif needs_update is False: elif needs_update is False:
if debug is True:
print("...Writing header", end='')
with open(filename, 'w') as contents: with open(filename, 'w') as contents:
#append the licence to the top of the file #append the licence to the top of the file
...@@ -280,9 +288,9 @@ def main(): ...@@ -280,9 +288,9 @@ def main():
fileList = proc.stdout.decode().split('\n') fileList = proc.stdout.decode().split('\n')
message = message.split('\n') message = message.split('\n')
if debug is True: #if debug is True:
print("Target file list:\n" + str(fileList)) #print("Target file list:\n" + str(fileList))
print("Output Message:\n" + str(message)) #print("Output Message:\n" + str(message))
for rfile in fileList: for rfile in fileList:
file = os.path.join(__repo_dir__, rfile) file = os.path.join(__repo_dir__, rfile)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment