-
Notifications
You must be signed in to change notification settings - Fork 24
/
snapshot.py
executable file
·215 lines (185 loc) · 6.38 KB
/
snapshot.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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#!/usr/bin/python
#
# Usage:
# snapshot.py suffix --server server --user username --pass password -nodocs -noupload
#
# Our goal is to make four files:
# boost-posix<suffix>.tar.gz
# boost-posix<suffix>.tar.bz2
# boost-windows<suffix>.zip
# boost-windows<suffix>.7z
#
# And them we upload them (via ftp) to <server>
#
import os, sys
import shutil
import hashlib
import argparse
import subprocess
from ftplib import FTP
kDocsFileName = "boost-release-docs.7z"
kDocsTemp = "docs_temp"
kDocsFolder = "docs_temp"
k7zName = "7za"
def mergetree(src, dst, symlinks=False, ignore=None):
from shutil import copy2, copystat, Error
import os
names = os.listdir(src)
if ignore is not None:
ignored_names = ignore(src, names)
else:
ignored_names = set()
try:
os.makedirs(dst)
except OSError as exc:
strexc=str(exc)
if "file already exists" in strexc: # Windows
pass
elif "File exists" in strexc: # Linux
pass
else:
raise
errors = []
for name in names:
if name in ignored_names:
continue
srcname = os.path.join(src, name)
dstname = os.path.join(dst, name)
try:
if symlinks and os.path.islink(srcname):
linkto = os.readlink(srcname)
os.symlink(linkto, dstname)
elif os.path.isdir(srcname):
mergetree(srcname, dstname, symlinks, ignore)
else:
copy2(srcname, dstname)
# XXX What about devices, sockets etc.?
except (IOError, os.error) as why:
errors.append((srcname, dstname, str(why)))
# catch the Error from the recursive mergetree so that we can
# continue with other files
except Error as err:
errors.extend(err.args[0])
try:
copystat(src, dst)
except WindowsError:
# can't copy file access times on Windows
pass
except OSError as why:
errors.extend((src, dst, str(why)))
if errors:
raise Error(errors)
def svnExport(url, eol, revisionStr, dest):
command_arr = [ "svn", "export", "--non-interactive", "--native-eol", eol, "-r", revisionStr, url, dest ]
subprocess.check_output ( command_arr )
def ftp_get_file(ftp, filename, dest_file):
f = open(dest_file, 'wb')
ftp.retrbinary( "RETR " + filename, f.write)
f.close ()
def ftp_put_file(ftp, filename):
ftp.storbinary( "STOR " + filename, open(filename, 'rb'))
def hash_file(filename):
blockSize = 65536
hasher = hashlib.md5()
aFile = open(filename, "rb")
buf = aFile.read(blockSize)
while len(buf) > 0:
hasher.update(buf)
buf = aFile.read(blockSize)
aFile.close ()
return hasher
def print_hash(filename):
print("%s *%s" % (hash_file(filename).hexdigest(), filename))
def compress_7z (dest, source):
command_arr = [ k7zName, "a", "-r", dest + ".7z", source ]
subprocess.check_output ( command_arr )
# os.system ( "%s a -r %s.7z %s > /dev/null" % (k7zName, dest, source))
def expand_7z (dest, source):
command_arr = [ k7zName, "x", "-y", "-o" + dest, source ]
subprocess.check_output ( command_arr )
# os.system ( "%s x -y -o%s %s > /dev/null" % (k7zName, dest, source))
def fixDirPerms (dir):
os.system ( "find %s -type d -exec chmod 755 {} \;" % dir )
def do_it(svnUrl, tag, suffix, releaseRevision, server, username, password, doUpload, doDocs):
windowsDir = "windows"
posixDir = "posix"
boostName = "boost_" + tag
windowsName = windowsDir + "/" + boostName
posixName = posixDir + "/" + boostName
# Download the docs - stash them somewhere (docs_temp)
## Old script "snapshot_download_docs.bat"
if doDocs:
ftp = FTP(server)
ftp.login(username, password)
ftp_get_file ( ftp, kDocsFileName, kDocsFileName )
expand_7z ( kDocsTemp, kDocsFileName )
fixDirPerms ( kDocsTemp )
ftp.quit ()
# Make Posix folder and export with LF line endings
os.mkdir ( posixDir )
svnExport(svnUrl, "LF", releaseRevision, posixName)
# fixDirPerms ( posixName )
# Merge in the docs
if doDocs:
mergetree ( kDocsTemp, posixName )
# Make Windows folder export with CRLF line endings
os.mkdir ( windowsDir )
svnExport(svnUrl, "CRLF", releaseRevision, windowsName)
# fixDirPerms ( windowsName )
# Merge in the docs
if doDocs:
mergetree ( kDocsTemp, windowsName )
# Create tar.gz and tar.bz2 files
outputName = "boost_" + tag
if suffix != None:
outputName += suffix
shutil.make_archive ( outputName, "bztar", posixDir, boostName )
shutil.make_archive ( outputName, "gztar", posixDir, boostName )
shutil.make_archive ( outputName, "zip", windowsDir, boostName )
hereDir = os.getcwd ()
os.chdir ( windowsDir )
compress_7z ( "../" + outputName, boostName )
os.chdir ( hereDir )
files = [
outputName + ".tar.gz",
outputName + ".tar.bz2",
outputName + ".zip",
outputName + ".7z"
]
# Create the MD5 checksums; list them for easy checking
for f in files:
print_hash ( f )
# Upload the four files
if doUpload:
ftp = FTP(server)
ftp.login(username, password)
for f in files:
ftp_put_file(ftp, f )
ftp.quit ()
# Clean up the remains
shutil.rmtree(posixDir)
shutil.rmtree(windowsDir)
if doDocs:
shutil.rmtree(kDocsTemp)
os.remove(kDocsFileName)
# $ date "+%Y-%m-%d"
# --> 2012-07-23
parser = argparse.ArgumentParser ( description='Build Boost snapshot')
parser.add_argument ('-nodocs', action='store_true', default=False, dest='nodocs',
help='Do not fetch (and merge) documentation into the snapshot')
parser.add_argument ('-noupload', action='store_true', default=False, dest='noupload',
help='Do not upload the snapshots to the server')
parser.add_argument ('-revision', dest="revision", default="HEAD",
help='svn revision to snapshot (default=HEAD)')
parser.add_argument ('-svnURL', dest="svnURL",
default="https://svn.boost.org/svn/boost/branches/release",
help='subversion URL to fetch (optional; mostly for debugging)')
parser.add_argument('-suffix', help='suffix to append to the snapshot name; i.e, rc1')
parser.add_argument('--server', dest='server', default="results.boost.org", action="store",
help='ftp server to download docs from and upload snapshots to')
parser.add_argument('--user', dest='username', default="", action="store")
parser.add_argument('--pass', dest='password', default="", action="store")
parser.add_argument('tag', help='the tag to label the snapshot with')
results = parser.parse_args()
do_it(results.svnURL, results.tag, results.suffix, results.revision, results.server, results.username, \
results.password, not results.noupload, not results.nodocs)