Repository navigation
Expand file tree
/
Copy pathSVNLinker.py
More file actions
112 lines (87 loc) · 3.92 KB
/
Copy pathSVNLinker.py
File metadata and controls
112 lines (87 loc) · 3.92 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
import os
import unreal
import configparser # 설정 파일 파싱
import subprocess # cmd 명령 내리기
import shutil # 파일 복제
def get_src_folder():
# 기본값
src_folder = unreal.Paths.project_dir() + "../SVN/"
unreal.log(f"기본 SVN 소스 폴더 : {src_folder}")
unreal.log(f"사용자 지정 SVN 소스 폴더 탐색 중...")
# ini 파일 읽기
config = configparser.ConfigParser(strict=False)
ini_path = unreal.Paths.generated_config_dir() + unreal.GameplayStatics.get_platform_name() + "Editor/EditorPerProjectUserSettings.ini"
unreal.log(f"사용자 설정 INI 탐색 : {ini_path}")
if os.path.exists(ini_path) == True:
config.read(ini_path)
path = config.get(
'/Script/P_RD.SVNSettings',
'mSVNContentDir',
fallback=None
)
# 값이 있을 때만 소스 주소 덮어쓰기
if path:
src_folder = path.strip("()").split("=")[1].strip('"')
unreal.log(f"INI 내 사용자 지정 SVN Link 주소 발견!")
unreal.log(f"최종 SVN 소스 폴더 : {src_folder}")
return src_folder
def get_dest_folder():
content_folder = unreal.Paths.project_content_dir()
link_name = "SVN"
dest_folder = os.path.join(content_folder, link_name)
unreal.log(f"최종 SVN 타겟 폴더 : {dest_folder}")
return dest_folder
def get_junction_target(path):
return os.path.realpath(path)
def make_svn_junction():
unreal.log(f"1. SVN 에셋 폴더 파악...")
src_folder = get_src_folder()
dest_folder = get_dest_folder()
# 유효 경로 체크
if os.path.exists(src_folder) == False:
unreal.log_error(f"SVN 소스 폴더 접근 실패: {src_folder}")
return False
unreal.log(f"2. Junction 검사 및 생성...")
# 기존 Junction 체크
if os.path.lexists(dest_folder) == True:
post_src_norm_path = os.path.normpath(src_folder)
pre_src_norm_path = get_junction_target(dest_folder)
if post_src_norm_path.lower() == pre_src_norm_path.lower():
unreal.log(f"동일 경로를 가리키는 기존의 Junction 발견: {pre_src_norm_path}")
return True
else:
unreal.log(f"다른 경로를 가리키는 기존의 Junction 발견 : {pre_src_norm_path} != {post_src_norm_path}")
try:
cmd = f'rmdir "{dest_folder}"'
result = subprocess.run(cmd, shell=True, capture_output=True, text=True, encoding="cp949")
if result.returncode == 0:
unreal.log(f"기존 Junction 삭제 완료")
else:
unreal.log_error(f"기존 Junction 삭제 실패: {result.stderr}")
return False
except Exception as e:
unreal.log_error(f"기존 Junction 삭제 예외: {e}")
return False
# Junction 생성
try:
cmd = f'mklink /J "{dest_folder}" "{src_folder}"'
result = subprocess.run(cmd, shell=True, capture_output=True, text=True, encoding="cp949")
if result.returncode == 0:
unreal.log(f"새로운 Junction 생성 완료: {dest_folder} -> {src_folder}")
else:
unreal.log_error(f"새로운 Junction 생성 실패: {result.stderr}")
return False
except Exception as e:
unreal.log_error(f"새로운 Junction 생성 예외: {e}")
return False
return True
def copy_pre_commit_file():
unreal.log(f"3. Git에 사용된 SVN 리비전 넘버 남기기 자동화...")
src_file = unreal.Paths.project_dir() + ".githooks/commit-msg"
dest_file = unreal.Paths.project_dir() + ".git/hooks/commit-msg"
if os.path.exists(src_file) == True:
unreal.log(f"Git SVN 버전 기록용 Hook 복제: {src_file} -> {dest_file}")
shutil.copy2(src_file, dest_file)
if unreal.is_editor():
if make_svn_junction() == True:
copy_pre_commit_file()