-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppCode.py
More file actions
81 lines (57 loc) · 1.94 KB
/
AppCode.py
File metadata and controls
81 lines (57 loc) · 1.94 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
#!/usr/bin/python
# coding=utf-8
import sys
import zipfile
import shutil
import os
import os.path
sys.path.append('../../')
sys.path.append('./')
from Project.Resource import mainResource
from Common.File.ZipUtil import ZipUtil
class AppCode():
# 删除子目录
def DeleteSubDir(self,sourceDir):
for file in os.listdir(sourceDir):
sourceFile = os.path.join(sourceDir, file)
#目录嵌套
if os.path.isdir(sourceFile):
if file!="CodeZip":
shutil.rmtree(sourceFile)
def GetDirScriptApps(self):
return mainResource.GetRootUnityAssets() + "/Script/Apps/"
def GetDirSourceCode(self):
return self.GetDirScriptApps() + "/" + mainResource.getGameType()
def GetFileSourceCodeZip(self):
return mainResource.GetRootUnityAssets() + "/Script/Apps/CodeZip/" + mainResource.getGameType() + ".zip"
# 备份游戏代码到CodeZip 压缩zip
def SaveCode(self):
dir_code = self.GetDirSourceCode()
file_zip = self.GetFileSourceCodeZip()
if not os.path.exists(dir_code):
return
print(dir_code)
print(file_zip)
# 压缩目录
ZipUtil.zipDir(dir_code,file_zip)
# 从CodeZip的zip文件里解压到assets目录
def CopyCode(self):
dir_code = self.GetDirScriptApps()
if not os.path.exists(dir_code):
return
file_zip = self.GetFileSourceCodeZip()
print(dir_code)
print(file_zip)
self.DeleteSubDir(dir_code)
flag = os.path.exists(file_zip)
if flag:
ZipUtil.un_zip(file_zip,dir_code)
# 主函数的实现
def Run(self,type):
gameName = mainResource.getGameName()
gameType = mainResource.getGameType()
if type == "save":
self.SaveCode()
if type == "copy":
self.CopyCode()
mainAppCode = AppCode()