-
Notifications
You must be signed in to change notification settings - Fork 8
/
makedist.py
109 lines (89 loc) · 2.98 KB
/
makedist.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
import win32api
import win32con
import sys
import os
import shutil
import re
from glob import glob
def runProcessGenerator(command):
streams = os.popen4(command)
while True:
line = streams[1].readline()
if line:
yield (line, None)
else:
break
exitCode = streams[0].close() or streams[1].close() or 0
yield (None, exitCode)
def runProcessRealtime(command):
for (line, exitCode) in runProcessGenerator(command):
if line:
sys.stdout.write(line)
else:
return exitCode
def runProcess(command):
result = []
for (line, exitCode) in runProcessGenerator(command):
if line:
result.append(line)
else:
return (result, exitCode)
def getRegValue(section, keyName, valueName):
key = None
value = None
try:
key = win32api.RegOpenKeyEx(section, keyName, 0, win32con.KEY_READ)
value = win32api.RegQueryValueEx(key, valueName)
finally:
if key:
win32api.RegCloseKey(key)
return value[0]
def getMsBuildPath():
return getRegValue(
win32con.HKEY_LOCAL_MACHINE,
r"SOFTWARE\Microsoft\MSBuild\ToolsVersions\3.5",
"MSBuildToolsPath"
)
def getSvnVersion():
(result, exitCode) = runProcess("svnversion")
if exitCode != 0:
for line in result:
sys.stderr.write(line)
raise Exception("svnversion.exe returned an error")
version = result[0].strip()
if version[-1] == 'M':
version = version[:-1]
elif (':' in version) or ('-' in version):
raise Exception("Working copy is not at a single revision")
return int(version)
def main():
wcVersion = getSvnVersion()
oldText = open("Version.cs", "r").read()
open("Version.cs", "w").write(
re.sub(
r"(const int Revision = )([0-9]*)(;)",
lambda m : m.group(1) + str(wcVersion) + m.group(3),
oldText
)
)
print "-- Building NDexer r%d --" % (wcVersion,)
if runProcessRealtime("%s\msbuild.exe ndexer.sln /v:m /nologo" % (getMsBuildPath(),)) != 0:
raise Exception("Build failed.")
print "-- Building package --"
shutil.rmtree(r"dist\temp", True)
os.makedirs(r"dist\temp")
shutil.copy(r"bin\debug\ndexer.exe", r"dist\temp")
for fn in glob(r"bin\debug\*.dll"):
shutil.copy(fn, r"dist\temp")
print "-- Compressing package --"
try:
os.makedirs(r"dist\packages")
except:
pass
(result, exitCode) = runProcess(r"ext\7zip\7z.exe a -r -t7z dist\packages\ndexer-r%d.7z .\dist\temp\*.*" % (wcVersion,))
if exitCode != 0:
for line in result:
sys.stdout.write(line)
raise Exception("Compress failed.")
print r"-- Done. Package built at dist\packages\ndexer-r%d.7z. --" % (wcVersion,)
main()