Commit d65d2033 authored by Ted Themistokleous's avatar Ted Themistokleous
Browse files

Update license stamper to add current new year and update files

parent e3e58c69
......@@ -23,6 +23,7 @@
# THE SOFTWARE.
#####################################################################################
import subprocess, os
import datetime
#Debug flag
debug = False
......@@ -65,17 +66,20 @@ def hasKeySequence(inputfile, key_message):
result = False
line_cnt = 0
line_limit = 10
target_line = -1
for line in inputfile:
line_cnt = line_cnt + 1
if key_message in line:
result = True
target_line = line_cnt
break
line_cnt = line_cnt + 1
if line_cnt >= line_limit:
break
return result
return [result, target_line]
# Header and footer of the comment block
......@@ -116,6 +120,10 @@ def openAndWriteFile(filename, message, commentChar):
save_markdown_lines = []
modify_markdown = False
current_year = str(datetime.date.today().year)
needs_update = False
update_line = -1
#open save old contents and append things here
if debug is True:
print("Open", filename, end='')
......@@ -155,7 +163,18 @@ def openAndWriteFile(filename, message, commentChar):
hasOtherLic = hasKeySequence(save, "Software License")
#Check if we have a licence stamp already
if hasAmdLic or hasOtherLic is True:
if hasAmdLic[0] or hasOtherLic[0] is True:
hasOldAmdLic = hasKeySequence(
save, "2015-" + current_year +
" Advanced Micro Devices, Inc. All rights reserved.")
if hasOldAmdLic[0] is True and hasOtherLic[0] is False:
if debug is True:
print("....License Out of Date: Updating file ")
needs_update = True
update_line = hasOldAmdLic[1]
else:
if debug is True:
print("....Already Stamped: Skipping file ")
......@@ -171,6 +190,21 @@ def openAndWriteFile(filename, message, commentChar):
if debug is True:
print("...Writing header", end='')
if needs_update is True and update_line > -1:
with open(filename, rw) as contents:
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
contents.write(data)
elif needs_update is False:
with open(filename, 'w') as contents:
#append the licence to the top of the file
......
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