Use enum in copyright update script.

This commit is contained in:
Pentarctagon 2021-07-31 12:55:31 -05:00
parent 6673524c8f
commit 35bb541f32
No known key found for this signature in database
GPG key ID: 9456BC54A21DBFA0

View file

@ -6,10 +6,16 @@
###
from datetime import date
from enum import Enum
import os
import re
import sys
class Found(Enum):
MISSING = 0
OLD = 1
NEW = 2
previous_year = str(date.today().year-1)
if len(sys.argv) == 2:
previous_year = sys.argv[1]
@ -37,20 +43,20 @@ for root, dirs, files in os.walk('src'):
for file in files:
if re.search(extensions, file):
lines = []
found = 0
found = Found.MISSING
with open(os.path.join(root, file), 'r') as f:
lines = f.readlines()
for index,line in enumerate(lines):
if re.search(old_copyright, line):
found = 1
found = Found.OLD
lines[index] = lines[index][:-5] + new_year + "\n"
break
elif re.search(new_copyright, line):
found = 2
if found == 1 and len(lines) > 0:
found = Found.NEW
if found == Found.OLD and len(lines) > 0:
with open(os.path.join(root, file), 'w') as f:
f.writelines(lines)
elif found == 2:
elif found == Found.NEW:
print("Found existing copyright notice in file: "+root+"/"+file)
else:
print("Found no copyright notice to update in file: "+root+"/"+file)