forked from pandas-dev/pandas
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheck_and_build.py
194 lines (161 loc) · 5.67 KB
/
check_and_build.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
import datetime
import git
import logging
import os, re, time
import subprocess
import argparse
import pysftp
# parse the args
parser = argparse.ArgumentParser(description='build, test, and install updated versions of master pandas')
parser.add_argument('-b', '--build',
help='run just this build',
dest='build')
parser.add_argument('-u', '--update',
help='get a git update',
dest='update',
action='store_true',
default=False)
parser.add_argument('-t', '--test',
help='run the tests',
dest='test',
action='store_true',
default=False)
parser.add_argument('-c', '--compare',
help='show the last tests compare',
dest='compare',
action='store_true',
default=False)
parser.add_argument('-v', '--version',
help='show the last versions',
dest='version',
action='store_true',
default=False)
parser.add_argument('-i', '--install',
help='run the install',
dest='install',
action='store_true',
default=False)
parser.add_argument('--dry',
help='dry run',
dest='dry',
action='store_true',
default=False)
args = parser.parse_args()
dry_run = args.dry
builds = ['26-32','26-64','27-32','27-64','33-32','33-64','34-32','34-64']
base_dir = "C:\Users\Jeff Reback\Documents\GitHub\pandas"
remote_host='pandas.pydata.org'
username='pandas'
password=############
# drop python from our environment to avoid
# passing this onto sub-processes
env = os.environ
del env['PYTHONPATH']
# the stdout logger
fmt = '%(asctime)s: %(message)s'
logger = logging.getLogger('check_and_build')
logger.setLevel(logging.DEBUG)
stream_handler = logging.StreamHandler()
stream_handler.setFormatter(logging.Formatter(fmt))
logger.addHandler(stream_handler)
def run_all(test=False,compare=False,install=False,version=False,build=None):
# run everything
for b in builds:
if build is not None and build != b:
continue
if test:
do_rebuild(b)
if compare or test:
try:
do_compare(b)
except (Exception) as e:
logger.info("ERROR COMPARE {0} : {1}".format(b,e))
if version:
try:
do_version(b)
except (Exception) as e:
logger.info("ERROR VERSION {0} : {1}".format(b,e))
if install:
run_install()
def do_rebuild(build):
# trigger the rebuild
cmd = "c:/Builds/build_{0}.bat".format(build)
logger.info("rebuild : {0}".format(cmd))
p = subprocess.Popen("start /wait /min {0}".format(cmd),env=env,shell=True,close_fds=True)
ret = p.wait()
def do_compare(build):
# print the test outputs
f = os.path.join(base_dir,"test.{0}.log".format(build))
with open(f,'r') as fh:
for l in fh:
l = l.rstrip()
if l.startswith('ERROR:'):
logger.info("{0} : {1}".format(build,l))
if l.startswith('Ran') or l.startswith('OK') or l.startswith('FAIL'):
logger.info("{0} : {1}".format(build,l))
def do_version(build):
# print the version strings
f = os.path.join(base_dir,"versions.{0}.log".format(build))
with open(f,'r') as fh:
for l in fh:
l = l.rstrip()
logger.info("{0} : {1}".format(build,l))
def do_update(is_verbose=True):
# update git; return True if the commit has changed
repo = git.Repo(base_dir)
master = repo.heads.master
origin = repo.remotes.origin
start_commit = master.commit
if is_verbose:
logger.info("current commit : {0}".format(start_commit))
try:
origin.update()
except (Exception) as e:
logger.info("update exception : {0}".format(e))
try:
origin.pull()
except (Exception) as e:
logger.info("pull exception : {0}".format(e))
result = start_commit != master.commit
if result:
if is_verbose:
logger.info("commits changed : {0} -> {1}".format(start_commit,master.commit))
return result
def run_install():
# send the installation binaries
repo = git.Repo(base_dir)
master = repo.heads.master
commit = master.commit
short_hash = str(commit)[:7]
logger.info("sending files : {0}".format(commit))
d = os.path.join(base_dir,"dist")
files = [ f for f in os.listdir(d) if re.search(short_hash,f) ]
srv = pysftp.Connection(host=remote_host,username=username,password=password)
srv.chdir("www/pandas-build/dev")
# get current files
remote_files = set(srv.listdir(path='.'))
for f in files:
if f not in remote_files:
logger.info("sending: {0}".format(f))
local = os.path.join(d,f)
srv.put(localpath=local)
srv.close()
logger.info("sending files: done")
# just perform the action
if args.update or args.test or args.compare or args.install or args.version:
if args.update:
do_update()
run_all(test=args.test,compare=args.compare,install=args.install,version=args.version,build=args.build)
exit(0)
# file logging
file_handler = logging.FileHandler("C:\Builds\logs\check_and_build.log")
file_handler.setFormatter(logging.Formatter(fmt))
logger.addHandler(file_handler)
logger.info("start")
# main loop
while(True):
if do_update():
run_all(test=True,install=False)
time.sleep(60*60)
logger.info("exit")
file_handler.close()