MCPcopy Create free account
hub / github.com/NVIDIA/TensorRT / update

Function update

scripts/copyright-scan.py:110–151  ·  view source on GitHub ↗

Update copyright header for specified file

(filename, args)

Source from the content-addressed store, hash-verified

108 return parser
109
110def update(filename, args):
111 """
112 Update copyright header for specified file
113 """
114 if filename.endswith(extensions_p):
115 pattern = re.compile(pattern_p)
116 header = header_p
117 shebang = re.compile(r'^(\#\!.*\n)', re.MULTILINE)
118 elif filename.endswith(extensions_c):
119 pattern = re.compile(pattern_c)
120 header = header_c
121 shebang = None
122 else:
123 return
124
125 with open(filename, "r+") as f:
126 data = f.read()
127 match = pattern.search(data)
128 if match:
129 year = match.group(1)
130 if copyright_year == year:
131 if args.force_update:
132 print(filename,": FORCED")
133 new_data = pattern.sub(header, data, count=1)
134 else:
135 print(filename,": SKIP")
136 return
137 else:
138 print(filename,": UPDATE (",year,"->",copyright_year,")")
139 new_data = pattern.sub(header, data, count=1)
140 else:
141 match = shebang.search(data) if shebang else None
142 if match:
143 print(filename,": ADD ( after",match.group(1),")")
144 new_data = shebang.sub(match.group(1)+header, data, count=1)
145 else:
146 print(filename,": ADD ( top )")
147 new_data = header+data
148
149 if not args.dry_run:
150 with open(filename, "w") as f:
151 f.write(new_data)
152
153def copyright_scan(directory, depth, args, exclude_dirs=[]):
154 """

Callers 2

nextMethod · 0.85
copyright_scanFunction · 0.85

Calls 3

printFunction · 0.85
readMethod · 0.80
writeMethod · 0.80

Tested by

no test coverage detected