-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcombine_files.py
More file actions
63 lines (52 loc) · 1.8 KB
/
combine_files.py
File metadata and controls
63 lines (52 loc) · 1.8 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
#!/usr/bin/env python3
import glob
import os
def combine_files():
# Find all .py, .js, and .json files excluding dist folder
all_files = []
for ext in ["*.py", "*.js", "*.json"]:
files = glob.glob(f"/home/erpnext/frappe-bench/apps/uph/**/{ext}", recursive=True)
# Filter out files in dist folder
files = [f for f in files if "/dist/" not in f]
all_files.extend(files)
# Separate test files (those that start with 'test' or contain 'test')
test_files = []
non_test_files = []
for file in all_files:
filename = os.path.basename(file)
if filename.startswith("test") or "test" in file.lower():
test_files.append(file)
else:
non_test_files.append(file)
# Sort files to ensure consistent ordering
non_test_files.sort()
test_files.sort()
# Combine all files into one
with open("/home/erpnext/Desktop/combined_files.txt", "w", encoding="utf-8") as outfile: # nosemgrep
# Write non-test files first
for file_path in non_test_files:
outfile.write(f"\n{'=' * 50}\n")
outfile.write(f"FILE: {file_path}\n")
outfile.write(f"{'=' * 50}\n")
try:
with open(file_path, encoding="utf-8") as infile: # nosemgrep
content = infile.read()
outfile.write(content)
outfile.write("\n")
except Exception as e:
outfile.write(f"ERROR READING FILE {file_path}: {e!s}\n")
# Write test files at the end
for file_path in test_files:
outfile.write(f"\n{'=' * 50}\n")
outfile.write(f"TEST FILE: {file_path}\n")
outfile.write(f"{'=' * 50}\n")
try:
with open(file_path, encoding="utf-8") as infile: # nosemgrep
content = infile.read()
outfile.write(content)
outfile.write("\n")
except Exception as e:
outfile.write(f"ERROR READING TEST FILE {file_path}: {e!s}\n")
if __name__ == "__main__":
combine_files()
print("Files combined successfully!")