@@ -34,22 +34,46 @@ def __init__(self, rtt_repo, rtt_branch):
3434 self .rtt_branch = rtt_branch
3535
3636 def __exclude_file (self , file_path ):
37- ignore_file_path = os .path .join (self .root , 'ignore_format.yml' )
38- try :
39- with open (ignore_file_path ) as f :
40- ignore_config = yaml .safe_load (f .read ())
41- file_ignore = ignore_config .get ("file_path" , [])
42- dir_ignore = ignore_config .get ("dir_path" , [])
43- except Exception as e :
44- logging .error (e )
45- return 1
46-
47- if file_path in file_ignore :
48- return 0
49-
50- file_dir_path = os .path .dirname (file_path )
51- if file_dir_path in dir_ignore :
52- return 0
37+ dir_number = file_path .split ('/' )
38+ ignore_path = file_path
39+
40+ # gets the file path depth.
41+ for i in dir_number :
42+ # current directory.
43+ dir_name = os .path .dirname (ignore_path )
44+ ignore_path = dir_name
45+ # judge the ignore file exists in the current directory.
46+ ignore_file_path = os .path .join (dir_name , ".ignore_format.yml" )
47+ if not os .path .exists (ignore_file_path ):
48+ continue
49+ try :
50+ with open (ignore_file_path ) as f :
51+ ignore_config = yaml .safe_load (f .read ())
52+ file_ignore = ignore_config .get ("file_path" , [])
53+ dir_ignore = ignore_config .get ("dir_path" , [])
54+ except Exception as e :
55+ logging .error (e )
56+ continue
57+
58+ try :
59+ # judge file_path in the ignore file.
60+ for file in file_ignore :
61+ if file is not None :
62+ file_real_path = os .path .join (dir_name , file )
63+ if file_real_path == file_path :
64+ logging .info ("ignore file path: {}" .format (file_real_path ))
65+ return 0
66+
67+ file_dir_path = os .path .dirname (file_path )
68+ for _dir in dir_ignore :
69+ if _dir is not None :
70+ dir_real_path = os .path .join (dir_name , _dir )
71+ if dir_real_path == file_dir_path :
72+ logging .info ("ignore dir path: {}" .format (dir_real_path ))
73+ return 0
74+ except Exception as e :
75+ logging .error (e )
76+ continue
5377
5478 return 1
5579
@@ -93,20 +117,20 @@ class FormatCheck:
93117 def __init__ (self , file_list ):
94118 self .file_list = file_list
95119
96- def __check_file (self , file_lines ):
120+ def __check_file (self , file_lines , file_path ):
97121 line_num = 1
98122 check_result = False
99123 for line in file_lines :
100124 # check line start
101125 line_start = line .replace (' ' , '' )
102126 # find tab
103127 if line_start .startswith ('\t ' ):
104- logging .error ("line[{}]: please use space replace tab at the start of this line." .format (line_num ))
128+ logging .error ("{} line[{}]: please use space replace tab at the start of this line." .format (file_path , line_num ))
105129 check_result = False
106130 # check line end
107131 lin_end = line .split ('\n ' )[0 ]
108132 if lin_end .endswith (' ' ) or lin_end .endswith ('\t ' ):
109- logging .error ("line[{}]: please delete extra space at the end of this line." .format (line_num ))
133+ logging .error ("{} line[{}]: please delete extra space at the end of this line." .format (file_path , line_num ))
110134 check_result = False
111135 line_num += 1
112136
@@ -140,7 +164,7 @@ def check(self):
140164
141165 with open (file_path , 'r' ) as f :
142166 file_lines = f .readlines ()
143- format_check_result = self .__check_file (file_lines )
167+ format_check_result = self .__check_file (file_lines , file_path )
144168
145169 if not encoding_check_result or not format_check_result :
146170 logging .error ("files format check fail." )
0 commit comments