6 from datetime
import datetime
8 from jinja2
import Template
11 GITROOT = os.popen(
"git rev-parse --show-toplevel").read().strip()
14 current_date = datetime.now().strftime(
"%Y-%m-%d")
17 commit_hash = os.popen(
"git rev-parse HEAD").read().strip()[:7]
20 header_template = Template(
21 """{{cchar}} BEGIN_HEADER
22 {{cchar}} -----------------------------------------------------------------------------
23 {{cchar}} Gauss-Jacobi Quadrature Implementation
24 {{cchar}} Authors: {{author}}
25 {{cchar}} Source: {{library_name}} Library
26 {{cchar}} License: MIT
27 {{cchar}} GitHub Repository: {{repository_url}}
28 {{cchar}} Date: {{date}}
29 {{cchar}} Commit: {{commit}}
30 {{cchar}} -----------------------------------------------------------------------------
31 {{cchar}} This code is part of the {{library_name}} library, providing an efficient
32 {{cchar}} implementation for Gauss-Jacobi quadrature nodes and weights computation.
33 {{cchar}} -----------------------------------------------------------------------------
34 {{cchar}} To cite this software:
35 {{cchar}} Rohit Goswami (2023). HaoZeke/GaussJacobiQuad: v0.1.0.
36 {{cchar}} Zenodo: https://doi.org/10.5281/ZENODO.8285112
37 {{cchar}} ---------------------------------------------------------------------
48 author="Rohit Goswami <rgoswami[at]ieee.org>",
49 repository_url="https://github.com/HaoZeke/GaussJacobiQuad
",
50 library_name="GaussJacobiQuad",
55 header_text = header_template.render(
57 repository_url=repository_url,
58 library_name=library_name,
63 for directory
in directories:
65 for root, dirs, files
in os.walk(directory):
66 for filename
in files:
67 if any(filename.endswith(suffix)
for suffix
in file_types):
68 filepath = os.path.join(root, filename)
70 with open(filepath,
"r")
as file:
74 if "BEGIN_HEADER" in content
and "END_HEADER" in content:
76 rf
"{cchar} BEGIN_HEADER.*?{cchar} END_HEADER\n",
82 content = header_text + content
84 with open(filepath,
"w")
as file:
87 print(
"Headers added or updated in all files in" f
" {directory} using {cchar}.")
90 if __name__ ==
"__main__":
91 parser = argparse.ArgumentParser(description=
"Add headers to source files.")
93 "--dirs", type=str, required=
True, nargs=
"+", help=
"Directory(s) to process"
99 help=
"Comma-separated list of file types to process",
101 parser.add_argument(
"--cchar", type=str, required=
True, help=
"Comment character")
103 args = parser.parse_args()
104 file_types = args.ftypes.split(
",")