Compute Library
 21.08
add_copyright Namespace Reference

Functions

def add_cpp_copyright (f, content)
 
def add_python_copyright (f, content)
 
def remove_comment (content)
 
def remove_comment_python (content)
 
def check_file (path)
 

Variables

 mit_copyright = open("scripts/copyright_mit.txt",'r').read()
 
 path = os.path.join(root, f)
 

Function Documentation

◆ add_cpp_copyright()

def add_copyright.add_cpp_copyright (   f,
  content 
)

Definition at line 8 of file add_copyright.py.

Referenced by check_file().

8 def add_cpp_copyright( f, content):
9  global mit_copyright
10  out = open(f,'w')
11  out.write("/*\n")
12  for line in mit_copyright.split('\n')[:-1]:
13  out.write(" *");
14  if line.strip() != "":
15  out.write(" %s" %line)
16  out.write("\n")
17  out.write(" */\n")
18  out.write(content.strip())
19  out.write("\n")
20  out.close()
21 

◆ add_python_copyright()

def add_copyright.add_python_copyright (   f,
  content 
)

Definition at line 22 of file add_copyright.py.

Referenced by check_file().

22 def add_python_copyright( f, content):
23  global mit_copyright
24  out = open(f,'w')
25  for line in mit_copyright.split('\n')[:-1]:
26  out.write("#");
27  if line.strip() != "":
28  out.write(" %s" %line)
29  out.write("\n")
30  out.write(content.strip())
31  out.write("\n")
32  out.close()
33 

◆ check_file()

def add_copyright.check_file (   path)

Definition at line 60 of file add_copyright.py.

References add_cpp_copyright(), and add_python_copyright().

60 def check_file( path ):
61  root, f = os.path.split(path)
62  if f in ['.clang-tidy', '.clang-format']:
63  print("Skipping file: {}".format(path))
64  return
65 
66  with open(path, 'r', encoding='utf-8') as fd:
67  content = fd.read()
68  _, extension = os.path.splitext(f)
69 
70  if extension in ['.cpp', '.h', '.hpp', '.inl', '.cl', '.in', '.cs']:
71  if not content.startswith('/*'):
72  add_cpp_copyright(path, content)
73  elif extension == '.py' or f in ['SConstruct', 'SConscript']:
74  if not content.startswith('# Copyright'):
75  add_python_copyright(path, content)
76  elif f == 'CMakeLists.txt':
77  if not content.startswith('# Copyright'):
78  add_python_copyright(path, content)
79  else:
80  raise Exception("Unhandled file: {}".format(path))
81 

◆ remove_comment()

def add_copyright.remove_comment (   content)

Definition at line 34 of file add_copyright.py.

34 def remove_comment( content ):
35  comment=True
36  out=""
37  for line in content.split('\n'):
38  if comment:
39  if line.startswith(' */'):
40  comment=False
41  elif line.startswith('/*') or line.startswith(' *'):
42  #print(line)
43  continue
44  else:
45  raise Exception("ERROR: not a comment ? '%s'"% line)
46  else:
47  out += line + "\n"
48  return out

◆ remove_comment_python()

def add_copyright.remove_comment_python (   content)

Definition at line 49 of file add_copyright.py.

49 def remove_comment_python( content ):
50  comment=True
51  out=""
52  for line in content.split('\n'):
53  if comment and line.startswith('#'):
54  continue
55  else:
56  comment = False
57  out += line + "\n"
58  return out
59 

Variable Documentation

◆ mit_copyright

mit_copyright = open("scripts/copyright_mit.txt",'r').read()

Definition at line 6 of file add_copyright.py.

◆ path

path = os.path.join(root, f)

Definition at line 89 of file add_copyright.py.