MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / LicenseCheck

Class LicenseCheck

tools/ci/file_check.py:194–234  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

192
193
194class LicenseCheck:
195 def __init__(self, file_list):
196 self.file_list = file_list
197
198 def check(self):
199 current_year = datetime.date.today().year
200 logging.info("current year: {}".format(current_year))
201 if len(self.file_list) == 0:
202 logging.warning("There are no files to check license.")
203 return 0
204 logging.info("Start to check files license.")
205 check_result = True
206 for file_path in self.file_list:
207 if file_path.endswith(".c") or file_path.endswith(".h"):
208 try:
209 with open(file_path, 'r') as f:
210 file = f.readlines()
211 except Exception as e:
212 logging.error(e)
213 else:
214 continue
215
216 if 'Copyright' in file[1] and 'SPDX-License-Identifier: Apache-2.0' in file[3]:
217 try:
218 license_year = re.search(r'2006-\d{4}', file[1]).group()
219 true_year = '2006-{}'.format(current_year)
220 if license_year != true_year:
221 logging.warning("[{0}]: license year: {} is not true: {}, please update.".format(file_path,
222 license_year,
223 true_year))
224
225 else:
226 logging.info("[{0}]: license check success.".format(file_path))
227 except Exception as e:
228 logging.error(e)
229
230 else:
231 logging.error("[{0}]: license check fail.".format(file_path))
232 check_result = False
233
234 return check_result
235
236
237@click.group()

Callers 1

checkFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected