-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalyze_files.py
More file actions
135 lines (96 loc) · 3.05 KB
/
analyze_files.py
File metadata and controls
135 lines (96 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import os
# ----------------------------
# Configuration
# ----------------------------
IGNORE_DIRS = [
'.git/', 'obj/', 'Debug/', 'Release/', 'bin/', 'ise_work/',
'x64/', 'x86/', 'tmp/', '_xmsgs/', '_ngo/'
]
IGNORE_SUFFIXES = [
'.log', '.pdb', '.obj', '.tmp', '.cache', '.xwbt', '.mrp',
'.vcd', '.jou', '.xml', '.html', '.wlf', '.sdf', '.hex', '.ngc'
]
# explicit filenames to ignore
IGNORE_EXACT = {
'wdf_from_fpga.bin', 'transcript', 'wdf_from_fpga.hex'
}
# explicit filenames to keep
KEEP_EXACT = {
'tw_model1_outbuf_golden.hex'
}
KEEP_SUFFIX = {
'.exe', '.dll', '.bit'
}
# ----------------------------
# Helper functions
# ----------------------------
def human(size):
for unit in ['B','K','M','G','T']:
if size < 1024:
return f"{size:.1f}{unit}"
size /= 1024
return f"{size:.1f}P"
def should_drop(path, suffix):
# This removes the filename, leaving only the folder path
folder_path = os.path.dirname(path)
folder_path = folder_path.replace("\\", "/") + "/"
# Extract file name (leaf)
leaf_file = os.path.basename(path) # → "abc.xyz"
# explicit suffix keep
if suffix in KEEP_SUFFIX :
return 'KEEP_SUFFIX', False
# explicit ignore
if os.path.basename(path) in IGNORE_EXACT:
return 'IGNORE_EXACT', True
# explicit keep
if os.path.basename(path) in KEEP_EXACT:
return 'KEEP_EXACT', False
# print(folder_path)
# directory-based ignore
for d in IGNORE_DIRS:
if d in folder_path :
return 'IGNORE_DIRS', True
# suffix-based ignore
if suffix in IGNORE_SUFFIXES:
return 'IGNORE_SUFFIXES', True
return 'KEEP', False
casue, drop = should_drop('./test_cases/target_model/logs_artsim_perl/tsim_mem_image.bin', 'bin')
# print(casue, drop)
# exit()
# ----------------------------
# Main logic
# ----------------------------
tracked_count = 0
tracked_size = 0
with open("all_files.txt") as f:
for line in f:
path = line.strip()
if not path or not os.path.isfile(path):
continue
# compute suffix
base = os.path.basename(path)
if "." in base:
suffix = "." + base.split(".")[-1]
else:
suffix = "NULL"
# get size
try:
size = os.path.getsize(path)
except:
size = -1
# determine TRACK / DROP
cause, drop = should_drop(path, suffix)
decision = "DROP" if drop else "TRACK"
# accumulate statistics
if not drop and size >= 0:
tracked_count += 1
tracked_size += size
# print formatted row
print(f"{path:<150}{suffix:<20}{size:>10} {decision:<10} {cause}")
if decision == 'TRACK' :
print(f"git add {path:<150}; ## {suffix:<20}{size:>10} {decision:<10} {cause}")
# final summary
print("\n---------------------------")
print(f"Tracked files: {tracked_count}")
print(f"Total tracked size: {human(tracked_size)}")
print("---------------------------")