-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeploy.py
143 lines (131 loc) · 4.66 KB
/
deploy.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import baker
import rpyc
import time
from glob import glob
import sys
import os
def uploadFile(src, target, remote):
if remote.modules.os.path.isfile(target):
try:
remote.modules.os.remove(target)
except:
tempName = target
pos = tempName.rfind('.')
if -1 == pos:
tempName += str(int(time.time()))
else:
tempName = tempName[:pos] + str(int(time.time())) + tempName[pos:]
remote.modules.os.rename(target, tempName)
targetPath = remote.modules.os.path.dirname(target)
if '' != targetPath:
if not remote.modules.os.path.isdir(targetPath):
remote.modules.os.makedirs(targetPath)
print "Uploading %s to %s" % (src, target)
remote.builtins.open(target, 'wb').write(
open(src, 'rb').read())
def uploadDir(src, target, remote, filterTempFiles=True):
for fileName in glob(src + '\\*'):
baseName = os.path.basename(fileName)
if filterTempFiles:
if fileName.endswith('~'):
continue
if fileName.endswith('.pyc'):
continue
if fileName.endswith('.bak'):
continue
if os.path.isdir(fileName):
uploadDir(fileName, target + '\\' + baseName, remote)
else:
uploadFile(fileName, target + '\\' + baseName, remote)
def getConnection(target=None):
if None == target:
target = 'win8tester'
return rpyc.classic.connect(target)
def getTargetFromInf(infFile):
lines = file(infFile, 'rb').readlines()
result = None
for line in lines:
if line.startswith('InstallDir='):
start = line.find('"')
if -1 == start:
raise Exception("Target not found")
start += 1
end = line.find('"', start)
if -1 == end:
raise Exception("Target end not found")
result = line[start:end]
if None == result:
raise Exception("No target in inf file")
return result
@baker.command
def updateDriver(target=None, debug=True):
FILES_TO_DEPLOY = ['Oregano.sys', 'Oregano.pdb', 'Oregano.inf']
remote = getConnection(target)
print "Deploing to %s" % target
remote.modules.os.system('sc stop oregano')
is64 = '64' in remote.modules.platform.machine()
binaryDir = 'output\\'
if is64:
binaryDir += 'x64\\'
else:
binaryDir += 'x86\\'
if debug:
binaryDir += 'Debug\\'
else:
binaryDir += 'Release\\'
targetDir = "c:\\" + getTargetFromInf("Oregano\\Oregano.inf")
for fileName in FILES_TO_DEPLOY:
uploadFile(binaryDir + fileName, targetDir + os.sep + fileName, remote)
remote.modules.os.system('c:\System32\InfDefaultInstall.exe %soregano.inf' % targetDir)
remote.modules.os.system('sc start oregano')
remote.close()
@baker.command
def updatePython(target=None):
remote = getConnection(target)
src = 'PyOregano'
dst = 'c:\\temp\\pyOregano'
uploadDir(src, dst, remote)
remote.modules.os.chdir('c:\\temp\\pyOregano')
print "Installing Oregano Python module"
remote.modules.os.system('python setup.py install')
remote.close()
@baker.command
def updateTests(target=None):
remote = getConnection(target)
uploadDir('tests', 'c:\\temp\\tests', remote)
remote.close()
@baker.command
def updateAll(target=None, debug=True):
updateDriver(target, debug)
updatePython(target)
updateTests(target)
@baker.command
def runTest(testName=None, target=None):
remote = getConnection(target)
print "Running tests on %s" % target
if None == testName:
testName = 'notepadTest.py'
testFile = 'tests\\' + testName
remoteDir = 'c:\\temp\\tests'
remoteFile = remoteDir + '\\' + testName
uploadFile(testFile, remoteFile, remote)
originalStdout = remote.modules.sys.stdout
originalStdin = remote.modules.sys.stdin
originalStderr = remote.modules.sys.stderr
remote.modules.sys.stdout = sys.stdout
remote.modules.sys.stdin = sys.stdin
remote.modules.sys.stderr = sys.stderr
print "Executing remotly"
remote.modules.subprocess.Popen(
"python %s" % remoteFile,
shell=True).communicate()
remote.modules.sys.stdout = originalStdout
remote.modules.sys.stdin = originalStdin
remote.modules.sys.stderr = originalStderr
remote.close()
@baker.command
def reboot(target=None):
remote = getConnection(target)
remote.modules.os.system('shutdown /r /t 1')
remote.close()
baker.run()