forked from mr-kelly/TableML
-
Notifications
You must be signed in to change notification settings - Fork 9
/
zip_and_copy_to_ksframework.py
68 lines (52 loc) · 1.81 KB
/
zip_and_copy_to_ksframework.py
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
# -*- coding:utf-8 -*-
'''
Desc:1.把开发目录下的tabmlgui拷贝到ksframework下,用于快速测试 2.对tableml在当前目录下生成zip
Time: 2020/7/27 17:58
Author: qingqing-zhao([email protected])
'''
import os
import sys
import zipfile
import shutil
src_path = r"E:\Code\TableML\TableML\TableMLGUI\bin\Release"
dst_path = r"E:\Code\KSFramework\KSFramework\Product\Tableml_GUI"
zip_name = ".\\tableml_gui.zip"
def zip_dir(dirname,zipfilename):
filelist = []
if os.path.isfile(dirname):
filelist.append(dirname)
else :
for root, dirs, files in os.walk(dirname):
for dir in dirs:
filelist.append(os.path.join(root,dir))
for name in files:
filelist.append(os.path.join(root, name))
zf = zipfile.ZipFile(zipfilename, "w", zipfile.zlib.DEFLATED)
for tar in filelist:
arcname = tar[len(dirname):]
#参数二:zip文件夹内的名字,可以保留到去掉根目录的层级
zf.write(tar,arcname)
zf.close()
if __name__ == "__main__":
try:
if len(sys.argv) >= 2:
src_path = sys.argv[1];
zip_name = sys.argv[2];
if not os.path.exists(src_path):
os.makedirs(src_path)
print("not exist path,create", src_path)
zip_path = os.path.abspath(os.path.dirname(zip_name))
if not os.path.exists(zip_path):
os.makedirs(zip_path)
print("not exist path,create", zip_path)
zip_dir(src_path,zip_name)
#目录拷贝
if os.path.exists(dst_path):
shutil.rmtree(dst_path)
print("exist path,delete", dst_path)
shutil.copytree(src_path, dst_path)
print("zip finish")
except Exception as ex:
print(ex)
finally:
input("Press <Enter>")