-
Notifications
You must be signed in to change notification settings - Fork 0
/
releaseZip.py
101 lines (83 loc) · 2.6 KB
/
releaseZip.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
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
#!/usr/bin/python
# Zip files for release
# Exclude list
# build
# dist
# .gitignore
# Releases
# *.spec
# *.git
# compile.bat
# if windows exclude *.sh
# releaseZip.py
# Inlcude list
# HackerPet_Setup.py
# HackerPet_Setup.bat
# ReadMe.md
# tools
import zipfile, os, sys, shutil
from pathlib import Path
from HackerPet_Setup import version as Version
# Path.lstat
version = Version
releaseLocation = 'Releases'
fileName = 'HackerPet_Setup'
zipFileName = f'{releaseLocation}/{fileName}_v{version}.zip'
zipFileName_versionless = f'{releaseLocation}/{fileName}.zip'
if Path(zipFileName).exists():
os.remove(zipFileName)
opperatingSystem = sys.platform
systemList = ['.bat', '.sh']
if opperatingSystem == 'win32':
systemList.pop(0)
# excludeList = ['build', 'dist', '.gitignore', 'Releases', '.spec', '.git', 'compile.bat', 'releaseZip.py', '.zip', '__pycache__']
excludeList = ['build', 'dist', '.gitignore', 'Releases', '.spec', '.git', 'releaseZip.py', '__pycache__']
excludeList.extend(systemList)
indexToRemove = []
def walk_dir():
directory = str(Path.cwd())
fileList = []
for root, dirs, files in os.walk(directory):
# print(f'root == {root}')
level = root.replace(f'{directory}', '')
if len(level) >= 1:
if level[0] == '\\':
level = level[1:]
# print(f'level == {level}')
# level = root.replace(directory, '').count(os.sep)
# indent = '---' * (level)
# print(f"{root}")
for file in files:
seperator = '\\'
if level == '':
seperator = ''
fileList.append(f"{level}{seperator}{file}")
# print(f"{root}\{file}")
return fileList
# walk_dir('/path/to/directory')
# def listAllFiles():
# root_dir = Path.cwd()
# for root, dirs, files in os.walk( root_dir ):
# for file in files:
# print(files)
# # file_path = os.path.join(root, file)
# # print(file_path)
fileList = walk_dir()
for eachExclusion in excludeList:
for i, eachFileFolder in enumerate(fileList):
if eachExclusion in eachFileFolder:
indexToRemove.append( i )
indexToRemove = sorted(indexToRemove, reverse = True )
for eachIndex in indexToRemove:
fileList.pop(eachIndex)
# for eachFile in fileList:
# print(eachFile)
with zipfile.ZipFile( zipFileName, 'w') as z:
for file in fileList:
# input(file)
z.write( file )
shutil.copy( zipFileName, zipFileName_versionless)
# openedZip = zipfile.ZipFile( fileList, 'w')
# openedZip.write( zipFileName )
# # with open( zipFileName, 'w' ) as f:
# # f.write( zipFileName, )