This repository was archived by the owner on Nov 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakeRelease.py
More file actions
136 lines (114 loc) · 4.54 KB
/
MakeRelease.py
File metadata and controls
136 lines (114 loc) · 4.54 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import sys, os, shutil, traceback, re, subprocess
from glob import glob
import datetime
todaystr = datetime.date.today().strftime("%Y.%m.%d")
textExts = ['.txt', '.ahk', '.py']
excludeExts = ['.swp']
Ahk2ExePath = r'C:\Program Files (x86)\AutoHotkey\Compiler\Ahk2Exe.exe'
MakeNSISPath = r"C:\Program Files\NSIS\makensis.exe"
def mktree(dirPath):
toks = list(os.path.split(dirPath))
path = ""
while toks:
path = os.path.join(path, toks.pop(0))
if not path: continue
if not os.path.exists(path):
os.mkdir(path)
else:
assert os.path.isdir(path)
def matchany(patterns, string):
for pattern in patterns:
if re.match(pattern, string):
return True
return False
def MakeRelease(**kwargs):
makeExe = kwargs.pop('makeExe', "")
makeNSIS = kwargs.pop('makeNSIS', [])
exclude = kwargs.pop('exclude', [])
headerPath = kwargs.pop('header', r'Header.txt')
outDir = kwargs.pop('outDir', r'release')
srcDir = kwargs.pop('srcDir', r'src')
srcDirSplit = [d for d in os.path.split(srcDir) if d]
iconPath = kwargs.pop('iconPath', '')
print "Building %s" % (outDir)
if exclude: print "Excluding %s" % (", ".join(exclude))
if os.path.exists(outDir):
shutil.rmtree(outDir)
mktree(outDir)
headerFile = None
try:
headerFile = open(headerPath, 'r')
header = headerFile.read()
header = header.replace("<DATESTR>", todaystr)
except:
print "Failed to read header file '%s':\n" % (headerPath)
traceback.print_tb()
sys.exit(1)
finally:
if headerFile: headerFile.close()
for root, dirs, files in os.walk(srcDir):
for fileName in files:
fileExt = os.path.splitext(fileName)[1]
filePath = os.path.join(root, fileName)
if matchany(exclude, filePath):
continue
fileDir = os.path.dirname(filePath)
assert fileDir.startswith(srcDir)
fileDirSplit = [d for d in os.path.split(fileDir) if d]
fileDirSplit = fileDirSplit[len(srcDirSplit):]
dstDir = os.path.join(outDir, *fileDirSplit)
mktree(dstDir)
dstPath = os.path.join(dstDir, fileName)
if fileExt in textExts and fileName != 'License.txt':
print "TEXT: %s" % (dstPath)
CopyFileWithHeader(filePath, dstPath, header)
elif fileExt not in excludeExts:
print "BINARY: %s" % (dstPath)
shutil.copy(filePath, dstPath)
else:
print "SKIP: %s" % (filePath)
if makeExe:
MakeExe(os.path.join(outDir, makeExe), iconPath)
if makeNSIS:
for nsisScript in makeNSIS:
MakeNSIS(nsisScript)
print "Done!"
def CopyFileWithHeader(srcPath, dstPath, header):
src = open(srcPath, 'r')
dst = open(dstPath, 'w')
try:
for line in header:
dst.write(line)
for line in src:
dst.write(line)
except:
traceback.print_tb()
sys.exit(1)
finally:
src.close()
dst.close()
def MakeExe(filePath, iconPath=''):
if not os.path.exists(Ahk2ExePath):
raise Exception("Ahk2Exe not found at '%s'. Set python var Ahk2ExePath." % Ahk2ExePath)
print "Compiling '%s' with ahk2exe..." % (filePath)
args = [Ahk2ExePath, '/in', filePath]
if iconPath:
args+= ['/icon', iconPath]
subprocess.call(args,
stderr=subprocess.PIPE, stdout=subprocess.PIPE)
def MakeNSIS(filePath):
if not os.path.exists(MakeNSISPath):
raise Exception("No makensis found at '%s'. Set python var MakeNSISPath." % MakeNSISPath)
print "Compiling '%s' with makensis..." % (filePath)
args = [MakeNSISPath, "/V2", "/DVERSION_STR=%s" % (todaystr,), filePath]
#ret = subprocess.call(args, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
proc = subprocess.Popen(args, stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=False)
output = proc.stdout.read()
if len(output) > 0:
print "\n%s" % (output.replace('\r', ''),)
raise Exception("makensis failed. Log printed above.")
if __name__ == "__main__":
MakeRelease(outDir = 'release',
makeExe = "UAWKS.ahk",
makeNSIS = ["UAWKS.nsi", "UAWKS Source.nsi"],
iconPath = "release\UAWKS.ico")