From d68f6218de82a05df7d82cae6d61a59579b71bc4 Mon Sep 17 00:00:00 2001
From: gifrerenom <lluis.gifre@cttc.es>
Date: Tue, 16 Apr 2024 10:37:14 +0000
Subject: [PATCH] Scripts - update_license_headers.py:

- Added missing skip patterns
- Added multiple old copyright lines
- Added logic to keep new-line chars
- Not finished
---
 scripts/update_license_headers.py | 33 ++++++++++++++++++++++++-------
 1 file changed, 26 insertions(+), 7 deletions(-)

diff --git a/scripts/update_license_headers.py b/scripts/update_license_headers.py
index da839ba0a..562352faa 100644
--- a/scripts/update_license_headers.py
+++ b/scripts/update_license_headers.py
@@ -28,12 +28,18 @@ FILE_PATH_NO_HEADER  = 'out-no-header.txt'
 FILE_PATH_UPDATED    = 'out-updated.txt'
 
 RE_OLD_COPYRIGHTS = [
-    re.compile(r'Copyright\ 2021\-2023\ H2020\ TeraFlow\ \(https\:\/\/www\.teraflow\-h2020\.eu\/\)'),
-    re.compile(r'Copyright\ 2022\-2023\ ETSI\ TeraFlowSDN\ \-\ TFS\ OSG\ \(https\:\/\/tfs\.etsi\.org\/\)'),
+    r'Copyright\ 2021\-2023\ H2020\ TeraFlow\ \(https\:\/\/www\.teraflow\-h2020\.eu\/\)',
+    r'Copyright\ 2022\-2023\ ETSI\ TeraFlowSDN\ \-\ TFS\ OSG\ \(https\:\/\/tfs\.etsi\.org\/\)',
 ]
+RE_OLD_COPYRIGHTS = [
+    (re.compile(re_old_copyright), re.compile(r'.*{}.*'.format(re_old_copyright)))
+    for re_old_copyright in RE_OLD_COPYRIGHTS
+]
+
 STR_NEW_COPYRIGHT = 'Copyright 2022-2024 ETSI TeraFlowSDN - TFS OSG/SDG (https://tfs.etsi.org/)'
 
 def skip_file(file_path : str) -> bool:
+    if os.path.islink(file_path): return True
     if file_path.endswith('.pyc'): return True
     if file_path.endswith('_pb2_grpc.py'): return True
     if file_path.endswith('_pb2.py'): return True
@@ -43,10 +49,14 @@ def skip_file(file_path : str) -> bool:
     if file_path.endswith('.zip'): return True
     if file_path.endswith('.zip'): return True
     if file_path.endswith('.jar'): return True
+    if file_path.endswith('.onnx'): return True
     if file_path.endswith('/tstat'): return True
     if file_path.endswith('/.gitignore'): return True
     if file_path.endswith('/.gitkeep'): return True
     if file_path.endswith('/coverage/.coverage'): return True
+    if file_path.endswith('/grpc/grpcurl/grpcurl'): return True
+    if file_path.endswith('/probe/probe-tfs/target/x86_64-unknown-linux-musl/release/tfsagent'): return True
+    if file_path.endswith('/probe/probe-tfs/target/x86_64-unknown-linux-musl/release/tfsping'): return True
     if file_path.startswith('./netconf_openconfig/'): return True
     if file_path.startswith('./tmp/'): return True
     if '/manifests/cttc-ols/' in file_path: return True
@@ -70,9 +80,16 @@ def skip_file(file_path : str) -> bool:
     return False
 
 def process_line(line_in : str) -> str:
-    for re_old_copyright in RE_OLD_COPYRIGHTS:
-        if re_old_copyright.match(line_in) is None: continue
-        line_out = re_old_copyright.sub(STR_NEW_COPYRIGHT, line_in)
+    print('line_in', line_in)
+    for re_match, re_sub in RE_OLD_COPYRIGHTS:
+        print('re_match', re_match)
+        print('re_sub', re_sub)
+        match = re_match.match(line_in)
+        print('match', match)
+        if match is None: continue
+        print('matched!')
+        line_out = re_sub.sub(STR_NEW_COPYRIGHT, line_in)
+        print('line_out', line_out)
         return line_out
     return line_in
 
@@ -89,8 +106,8 @@ def process_file(
     replaced = False
     file_stat = os.stat(file_path)
     try:
-        with open(file_path, encoding='UTF-8') as source:
-            with open(temp_file_path, 'w', encoding='UTF-8') as target:
+        with open(file_path, encoding='UTF-8', newline='') as source:
+            with open(temp_file_path, 'w', encoding='UTF-8', newline='') as target:
                 for line_in in source:
                     line_out = process_line(line_in)
                     target.write(line_out)
@@ -106,6 +123,8 @@ def process_file(
     os.rename(temp_file_path, file_path)
     os.chmod(file_path, file_stat.st_mode)
 
+    raise Exception()
+
 def main() -> int:
     with open(FILE_PATH_NO_HEADER, 'w', encoding='UTF-8') as file_no_header:
         with open(FILE_PATH_SKIPPED, 'w', encoding='UTF-8') as file_skipped:
-- 
GitLab