add_headers Namespace Reference

Functions

def add_headers (directories, file_types, cchar="!", author="Rohit Goswami <rgoswami[at]ieee.org>", repository_url="https://github.com/HaoZeke/GaussJacobiQuad", library_name="GaussJacobiQuad", date=current_date, commit=commit_hash)
 

Variables

 GITROOT = os.popen("git rev-parse --show-toplevel").read().strip()
 
 current_date = datetime.now().strftime("%Y-%m-%d")
 
 commit_hash = os.popen("git rev-parse HEAD").read().strip()[:7]
 
 header_template
 
 parser = argparse.ArgumentParser(description="Add headers to source files.")
 
 type
 
 str
 
 required
 
 True
 
 nargs
 
 help
 
 args = parser.parse_args()
 
 file_types = args.ftypes.split(",")
 

Function Documentation

◆ add_headers()

def add_headers.add_headers (   directories,
  file_types,
  cchar = "!",
  author = "Rohit Goswami <rgoswami[at]ieee.org>",
  repository_url = "https://github.com/HaoZeke/GaussJacobiQuad",
  library_name = "GaussJacobiQuad",
  date = current_date,
  commit = commit_hash 
)

Definition at line 44 of file add_headers.py.

53 ):
54  # Fill in the template variables
55  header_text = header_template.render(
56  author=author,
57  repository_url=repository_url,
58  library_name=library_name,
59  date=current_date,
60  commit=commit_hash,
61  cchar=cchar,
62  )
63  for directory in directories:
64  # Iterate over all files in the specified directory
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)
69 
70  with open(filepath, "r") as file:
71  content = file.read()
72 
73  # Check for the existing header and replace or append
74  if "BEGIN_HEADER" in content and "END_HEADER" in content:
75  content = re.sub(
76  rf"{cchar} BEGIN_HEADER.*?{cchar} END_HEADER\n",
77  header_text,
78  content,
79  flags=re.DOTALL,
80  )
81  else:
82  content = header_text + content
83 
84  with open(filepath, "w") as file:
85  file.write(content)
86 
87  print("Headers added or updated in all files in" f" {directory} using {cchar}.")
88 
89 

Variable Documentation

◆ args

add_headers.args = parser.parse_args()

Definition at line 103 of file add_headers.py.

◆ commit_hash

add_headers.commit_hash = os.popen("git rev-parse HEAD").read().strip()[:7]

Definition at line 17 of file add_headers.py.

◆ current_date

add_headers.current_date = datetime.now().strftime("%Y-%m-%d")

Definition at line 14 of file add_headers.py.

◆ file_types

add_headers.file_types = args.ftypes.split(",")

Definition at line 104 of file add_headers.py.

◆ GITROOT

add_headers.GITROOT = os.popen("git rev-parse --show-toplevel").read().strip()

Definition at line 11 of file add_headers.py.

◆ header_template

add_headers.header_template
Initial value:
1 = Template(
2 
3 )

Definition at line 20 of file add_headers.py.

◆ help

add_headers.help

Definition at line 93 of file add_headers.py.

◆ nargs

add_headers.nargs

Definition at line 93 of file add_headers.py.

◆ parser

add_headers.parser = argparse.ArgumentParser(description="Add headers to source files.")

Definition at line 91 of file add_headers.py.

◆ required

add_headers.required

Definition at line 93 of file add_headers.py.

◆ str

add_headers.str

Definition at line 93 of file add_headers.py.

◆ True

add_headers.True

Definition at line 93 of file add_headers.py.

◆ type

add_headers.type

Definition at line 93 of file add_headers.py.