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

Method check

tools/ci/file_check.py:152–191  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

150 return check_result
151
152 def check(self):
153 logging.info("Start to check files format.")
154 if len(self.file_list) == 0:
155 logging.warning("There are no files to check format.")
156 return True
157 encoding_check_result = True
158 format_check_fail_files = 0
159 for file_path in self.file_list:
160 code = ''
161 if file_path.endswith(".c") or file_path.endswith(".h"):
162 try:
163 with open(file_path, 'rb') as f:
164 file = f.read()
165 # get file encoding
166 chardet_report = chardet.detect(file)
167 code = chardet_report['encoding']
168 confidence = chardet_report['confidence']
169 except Exception as e:
170 logging.error(e)
171 else:
172 continue
173
174 if code != 'utf-8' and code != 'ascii' and confidence > 0.8:
175 logging.error("[{0}]: encoding {1} not utf-8, please format it.".format(file_path, code))
176 encoding_check_result = False
177 else:
178 logging.info('[{0}]: encoding check success.'.format(file_path))
179
180 with open(file_path, 'r', encoding = "utf-8") as f:
181 file_lines = f.readlines()
182 if not self.__check_file(file_lines, file_path):
183 format_check_fail_files += 1
184
185 if (not encoding_check_result) or (format_check_fail_files != 0):
186 logging.error("files format check fail.")
187 return False
188
189 logging.info("files format check success.")
190
191 return True
192
193
194class LicenseCheck:

Callers 1

checkFunction · 0.95

Calls 4

__check_fileMethod · 0.95
openFunction · 0.50
readMethod · 0.45
detectMethod · 0.45

Tested by

no test coverage detected