-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmergesrc.py
More file actions
51 lines (45 loc) · 2.38 KB
/
mergesrc.py
File metadata and controls
51 lines (45 loc) · 2.38 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
import os
def merge_files(src_directories, output_file, extensions=['.java', '.yml', '.gradle']):
with open(output_file, 'w', encoding='utf-8') as outfile:
for src_directory in src_directories:
for root, dirs, files in os.walk(src_directory):
for file in files:
if any(file.endswith(ext) for ext in extensions):
file_path = os.path.join(root, file)
try:
with open(file_path, 'r', encoding='utf-8') as infile:
content = infile.read()
if content:
outfile.write(f"// File: {file_path}\n")
outfile.write(content)
outfile.write("\n\n")
print(f"Added {file_path}")
else:
print(f"Skipped empty file: {file_path}")
except Exception as e:
print(f"Error reading {file_path}: {e}")
# 현재 디렉토리의 settings.gradle과 build.gradle 파일 추가
current_dir = os.path.abspath(os.path.dirname(__file__))
for file_name in ['settings.gradle', 'build.gradle']:
file_path = os.path.join(current_dir, file_name)
if os.path.isfile(file_path):
try:
with open(file_path, 'r', encoding='utf-8') as infile:
content = infile.read()
if content:
outfile.write(f"// File: {file_path}\n")
outfile.write(content)
outfile.write("\n\n")
print(f"Added {file_path}")
except Exception as e:
print(f"Error reading {file_path}: {e}")
if __name__ == "__main__":
default_directories = "subrecommend-biz subrecommend-infra"
input_directories = input(f"# 소스 디렉토리명 (기본값: {default_directories}): ")
if input_directories.strip() == "":
src_directories = default_directories.split()
else:
src_directories = input_directories.split()
output_file = 'MergedSource.java'
merge_files(src_directories, output_file)
print(f"All files have been merged into {output_file}")