1
+ #
2
+ # Copyright (c) 2006-2023, RT-Thread Development Team
3
+ #
4
+ # SPDX-License-Identifier: Apache-2.0
5
+ #
6
+ # Change Logs:
7
+ # Date Author Notes
8
+ # 2023-05-16 dejavudwh the first version
9
+ #
10
+
11
+ import yaml
12
+ import logging
13
+ import os
14
+ import subprocess
15
+
16
+ def init_logger ():
17
+ log_format = "[%(filename)s %(lineno)d %(levelname)s] %(message)s "
18
+ date_format = '%Y-%m-%d %H:%M:%S %a '
19
+ logging .basicConfig (level = logging .INFO ,
20
+ format = log_format ,
21
+ datefmt = date_format ,
22
+ )
23
+
24
+ class CheckOut :
25
+ def __init__ (self ):
26
+ pass
27
+
28
+ def __exclude_file (self , file_path ):
29
+ dir_number = file_path .split ('/' )
30
+ ignore_path = file_path
31
+
32
+ # gets the file path depth.
33
+ for i in dir_number :
34
+ # current directory.
35
+ dir_name = os .path .dirname (ignore_path )
36
+ ignore_path = dir_name
37
+ # judge the ignore file exists in the current directory.
38
+ ignore_file_path = os .path .join (dir_name , ".ignore_format.yml" )
39
+ if not os .path .exists (ignore_file_path ):
40
+ continue
41
+ try :
42
+ with open (ignore_file_path ) as f :
43
+ ignore_config = yaml .safe_load (f .read ())
44
+ file_ignore = ignore_config .get ("file_path" , [])
45
+ dir_ignore = ignore_config .get ("dir_path" , [])
46
+ except Exception as e :
47
+ logging .error (e )
48
+ continue
49
+ logging .debug ("ignore file path: {}" .format (ignore_file_path ))
50
+ logging .debug ("file_ignore: {}" .format (file_ignore ))
51
+ logging .debug ("dir_ignore: {}" .format (dir_ignore ))
52
+ try :
53
+ # judge file_path in the ignore file.
54
+ for file in file_ignore :
55
+ if file is not None :
56
+ file_real_path = os .path .join (dir_name , file )
57
+ if file_real_path == file_path :
58
+ logging .info ("ignore file path: {}" .format (file_real_path ))
59
+ return 0
60
+
61
+ file_dir_path = os .path .dirname (file_path )
62
+ for _dir in dir_ignore :
63
+ if _dir is not None :
64
+ dir_real_path = os .path .join (dir_name , _dir )
65
+ if file_dir_path .startswith (dir_real_path ):
66
+ logging .info ("ignore dir path: {}" .format (dir_real_path ))
67
+ return 0
68
+ except Exception as e :
69
+ logging .error (e )
70
+ continue
71
+
72
+ return 1
73
+
74
+ def get_new_file (self ):
75
+ result = subprocess .run (['git' , 'diff' , '--name-only' , 'HEAD' , 'origin/master' , '--diff-filter=ACMR' , '--no-renames' , '--full-index' ], stdout = subprocess .PIPE )
76
+ file_list = result .stdout .decode ().strip ().split ('\n ' )
77
+ new_files = []
78
+ for line in file_list :
79
+ logging .info ("modified file -> {}" .format (line ))
80
+ result = self .__exclude_file (line )
81
+ if result != 0 :
82
+ new_files .append (line )
83
+
84
+ return new_files
0 commit comments