-
Notifications
You must be signed in to change notification settings - Fork 0
/
createAddonZip.py
118 lines (93 loc) · 3.87 KB
/
createAddonZip.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import os
import zipfile
import json
from datetime import date
from addoninfo import getInfo, addonInfo, getVersionString, getNextVersionString
today = date.today()
currentdir = os.path.dirname(os.path.realpath(__file__))
parentdir = os.path.dirname(currentdir)
addonInfoJson = getInfo()
addonname = addonInfoJson.get("name")
version = getVersionString()
datee = today.strftime("%d%m%Y")
def zip_dir(directory, zipname):
"""
Compress a directory (ZIP file).
"""
if os.path.exists(directory):
outZipFile = zipfile.ZipFile(zipname, 'w', zipfile.ZIP_DEFLATED)
# The root directory within the ZIP file.
rootdir = os.path.basename(directory)
for dirpath, dirnames, filenames in os.walk(directory):
for filename in filenames:
# Write the file named filename to the archive,
# giving it the archive name 'arcname'.
filepath = os.path.join(dirpath, filename)
parentpath = os.path.relpath(filepath, directory)
arcname = os.path.join(rootdir, parentpath)
outZipFile.write(filepath, arcname)
outZipFile.close()
def convertTuple(tup):
strr = '.'.join(str(tup).replace(".", "").replace(",", ""))
finall = strr.replace(". ", "").replace("(", "").replace(")", "")[1:-1]
return finall
def updateAddonInfoFile(version):
# Update the Addon info
file1 = open("addoninfo.py","r+")
liness = file1.read()
file1.close()
currentversion = getVersionString()
nextversion = getnextVersionsolo(version)
tuplestring = "("+nextversion.split('.')[0]+", " +nextversion.split('.')[1]+", " +nextversion.split('.')[2]+")"
tuplestringoriginal = "("+currentversion.split('.')[0]+", " +currentversion.split('.')[1]+", " +currentversion.split('.')[2]+")"
print(tuplestring)
print(tuplestringoriginal)
linessfixed = liness.replace(tuplestringoriginal,tuplestring)
file1 = open("addoninfo.py","w")
file1.write(linessfixed)
file1.close()
# Update the Addon for Blender now
file2 = open("__init__.py","r+")
liness2 = file2.read()
file2.close()
liness2fixed = liness2.replace(tuplestringoriginal,tuplestring)
file2 = open("__init__.py","w")
file2.write(liness2fixed)
file2.close()
def getnextVersion(currentverion):
lastindex = len(currentverion.split(".")) - 1
lastsplit = currentverion.split(".")[lastindex]
nextnum = int(lastsplit) + 1
print(nextnum)
outversion = currentverion[:-1] + str(nextnum)
print(outversion)
initialpath = [parentdir + "\\"+addonname +"_"+ outversion +"_"+ datee+"_.zip",outversion]
initialexists = os.path.exists(initialpath[0])
if(initialexists):
initialpath = getnextVersion(outversion)
return initialpath
def getnextVersionsolo(currentverion):
lastindex = len(currentverion.split(".")) - 1
lastsplit = currentverion.split(".")[lastindex]
nextnum = int(lastsplit) + 1
print(nextnum)
outversion = currentverion[:-1] + str(nextnum)
print(outversion)
return outversion
if __name__ == '__main__':
print(os.path.dirname(os.path.realpath(__file__)))
outpath = parentdir + "\\"+addonname +"_"+ version +"_"+ datee+"_.zip"
initialexists = os.path.exists(outpath)
if(initialexists):
outtuple = getnextVersion(version)
outpath = outtuple[0]
version = outtuple[1]
print(outpath)
print(version)
updateAddonInfoFile(version)
zip_dir(currentdir, outpath)
print("````````````````````````````````````````````````````````````````")
print("Finished Creating the Zip File!")
print(outpath)
print(version)
print("````````````````````````````````````````````````````````````````")