From d08516555ac974ab7e256f2e8c61bb138a2fa696 Mon Sep 17 00:00:00 2001 From: Marcio Donadio Date: Thu, 22 Feb 2024 16:31:29 -0800 Subject: [PATCH 1/3] Wrong indentation was preventing the loop from reaching all files --- scripts/apply_slac_license.py | 42 +++++++++++++++++------------------ 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/scripts/apply_slac_license.py b/scripts/apply_slac_license.py index ecaa4f5e38..6ba73d5ea6 100644 --- a/scripts/apply_slac_license.py +++ b/scripts/apply_slac_license.py @@ -118,30 +118,30 @@ def updateFile(path,module,comment,log,script): src = "%s/%s" % (root,f) ret = None - # Skip .svn sub-directories - if f.find(".svn") > 0: - logFile.write("Ignored: %s\n" % (src)) + # Skip .svn sub-directories + if f.find(".svn") > 0: + logFile.write("Ignored: %s\n" % (src)) - # VHDL - elif f.endswith(".vhd"): - updateFile(src,module,"--",logFile,False) + # VHDL + elif f.endswith(".vhd"): + updateFile(src,module,"--",logFile,False) - # C files - elif f.endswith(".h") or f.endswith(".hh") or f.endswith(".c") or f.endswith(".cc") or f.endswith(".cpp"): - updateFile(src,module,"//",logFile,False) + # C files + elif f.endswith(".h") or f.endswith(".hh") or f.endswith(".c") or f.endswith(".cc") or f.endswith(".cpp"): + updateFile(src,module,"//",logFile,False) - # Verilog, Verilog, or System Verilog - elif f.endswith(".v") or f.endswith(".vh") or f.endswith(".sv"): - updateFile(src,module,"//",logFile,False) + # Verilog, Verilog, or System Verilog + elif f.endswith(".v") or f.endswith(".vh") or f.endswith(".sv"): + updateFile(src,module,"//",logFile,False) - # TCL / XDC - elif f.endswith(".tcl") or f.endswith(".xdc"): - updateFile(src,module,"##",logFile,False) + # TCL / XDC + elif f.endswith(".tcl") or f.endswith(".xdc"): + updateFile(src,module,"##",logFile,False) - # Python - elif f.endswith(".py"): - updateFile(src,module,"##",logFile,True) + # Python + elif f.endswith(".py"): + updateFile(src,module,"##",logFile,True) - # Unknown - else: - logFile.write("Unknown: %s\n" % (src)) + # Unknown + else: + logFile.write("Unknown: %s\n" % (src)) From 0fd160517108f21eaaeea0056e5a74ffea1711ad Mon Sep 17 00:00:00 2001 From: Marcio Donadio Date: Thu, 22 Feb 2024 16:32:20 -0800 Subject: [PATCH 2/3] Fixed typo in help message --- scripts/apply_slac_license.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/apply_slac_license.py b/scripts/apply_slac_license.py index 6ba73d5ea6..c040f4bafa 100644 --- a/scripts/apply_slac_license.py +++ b/scripts/apply_slac_license.py @@ -100,7 +100,7 @@ def updateFile(path,module,comment,log,script): # Check args if len(sys.argv) < 3: - print ("Usage: apply_license.py root_dir module_name") + print ("Usage: apply_slac_license.py root_dir module_name") exit() module = sys.argv[2] From b0e0c028c841351687bd248aa0a1a1f4828c10dd Mon Sep 17 00:00:00 2001 From: Marcio Donadio Date: Thu, 22 Feb 2024 16:52:55 -0800 Subject: [PATCH 3/3] Provided an optional argument so the user can choose the location of the LICENSE.txt file --- scripts/apply_slac_license.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/scripts/apply_slac_license.py b/scripts/apply_slac_license.py index c040f4bafa..06645bcd84 100644 --- a/scripts/apply_slac_license.py +++ b/scripts/apply_slac_license.py @@ -100,17 +100,27 @@ def updateFile(path,module,comment,log,script): # Check args if len(sys.argv) < 3: - print ("Usage: apply_slac_license.py root_dir module_name") + print ("Usage: apply_slac_license.py root_dir module_name [optional path_to_license]") exit() module = sys.argv[2] path = sys.argv[1] +# Path to license is an optional argument +license_path = "" +if len(sys.argv) == 4: + license_path = sys.argv[3] logFile = open (path + "/apply_license_log.txt","w") # Copy license file -baseDir = os.path.realpath(__file__).split('surf')[0] -shutil.copy(baseDir+"surf/LICENSE.txt",path + "/LICENSE.txt") +if license_path != "": + # Use user defined directory + baseDir = os.path.realpath(license_path) + shutil.copy(baseDir + "/LICENSE.txt", path + "/LICENSE.txt") +else: + # Use surf default directory + baseDir = os.path.realpath(__file__).split('surf')[0] + shutil.copy(baseDir + "surf/LICENSE.txt", path + "/LICENSE.txt") # Walk directories recursively for root,dirs,files in os.walk(path):