MCPcopy Create free account
hub / github.com/ARM-software/ComputeLibrary / check_copyright

Function check_copyright

scripts/format_code.py:61–126  ·  view source on GitHub ↗
( filename )

Source from the content-addressed store, hash-verified

59 return ret_copyright_year
60
61def check_copyright( filename ):
62 f = open(filename, "r")
63 content = f.readlines()
64 f.close()
65 f = open(filename, "w")
66 year = datetime.datetime.now().year
67 ref = open("scripts/copyright_mit.txt","r").readlines()
68
69 # Need to handle python files separately
70 if("SConstruct" in filename or "SConscript" in filename):
71 start = 2
72 if("SConscript" in filename):
73 start = 3
74 m = re.match(r"(# Copyright \(c\) )(.*\d{4})( [Arm|ARM].*)", content[start])
75 line = m.group(1)
76
77 if m.group(2): # Is there a year already?
78 # Yes: adjust accordingly
79 line += adjust_copyright_year(m.group(2), year)
80 else:
81 # No: add current year
82 line += str(year)
83 line += m.group(3).replace("ARM", "Arm")
84 if("SConscript" in filename):
85 f.write('#!/usr/bin/python\n')
86
87 f.write('# -*- coding: utf-8 -*-\n\n')
88 f.write(line+"\n")
89 # Copy the rest of the file's content:
90 f.write("".join(content[start + 1:]))
91 f.close()
92
93 return
94
95 # This only works until year 9999
96 m = re.match(r"(.*Copyright \(c\) )(.*\d{4})( [Arm|ARM].*)", content[1])
97 start =len(ref)+2
98 if content[0] != "/*\n" or not m:
99 start = 0
100 f.write("/*\n * Copyright (c) %d Arm Limited.\n" % year)
101 else:
102 logger.debug("Found Copyright start")
103 logger.debug("\n\t".join([ g or "" for g in m.groups()]))
104 line = m.group(1)
105
106 if m.group(2): # Is there a year already?
107 # Yes: adjust accordingly
108 line += adjust_copyright_year(m.group(2), year)
109 else:
110 # No: add current year
111 line += str(year)
112 line += m.group(3).replace("ARM", "Arm")
113 f.write("/*\n"+line+"\n")
114 logger.debug(line)
115 # Write out the rest of the Copyright header:
116 for i in range(1, len(ref)):
117 line = ref[i]
118 f.write(" *")

Callers 1

runMethod · 0.85

Calls 3

adjust_copyright_yearFunction · 0.85
rangeFunction · 0.85
closeMethod · 0.45

Tested by

no test coverage detected