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 216 217
|
#!/usr/bin/env python
#
# Performs a release of Review Board. This can only be run by the core
# developers with release permissions.
#
import hashlib
import mimetools
import os
import shutil
import subprocess
import sys
import tempfile
import urllib2
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", ".."))
from rbtools import __version__, __version_info__, is_release
PY_VERSIONS = ["2.4", "2.5", "2.6", "2.7"]
LATEST_PY_VERSION = PY_VERSIONS[-1]
PACKAGE_NAME = 'RBTools'
RELEASES_URL = \
'reviewboard.org:/var/www/downloads.reviewboard.org/' \
'htdocs/releases/%s/%s.%s/' % (PACKAGE_NAME,
__version_info__[0],
__version_info__[1])
RBWEBSITE_API_URL = 'http://www.reviewboard.org/api/'
RELEASES_API_URL = '%sproducts/rbtools/releases/' % RBWEBSITE_API_URL
built_files = []
def load_config():
filename = os.path.join(os.path.expanduser('~'), '.rbwebsiterc')
if not os.path.exists(filename):
sys.stderr.write("A .rbwebsiterc file must exist in the form of:\n")
sys.stderr.write("\n")
sys.stderr.write("USERNAME = '<username>'\n")
sys.stderr.write("PASSWORD = '<password>'\n")
sys.exit(1)
user_config = {}
try:
execfile(filename, user_config)
except SyntaxError, e:
sys.stderr.write('Syntax error in config file: %s\n'
'Line %i offset %i\n' % (filename, e.lineno, e.offset))
sys.exit(1)
auth_handler = urllib2.HTTPBasicAuthHandler()
auth_handler.add_password(realm='Web API',
uri=RBWEBSITE_API_URL,
user=user_config['USERNAME'],
passwd=user_config['PASSWORD'])
opener = urllib2.build_opener(auth_handler)
urllib2.install_opener(opener)
def execute(cmdline):
if isinstance(cmdline, list):
print ">>> %s" % subprocess.list2cmdline(cmdline)
else:
print ">>> %s" % cmdline
p = subprocess.Popen(cmdline,
shell=True,
stdout=subprocess.PIPE)
s = ''
for data in p.stdout.readlines():
s += data
sys.stdout.write(data)
rc = p.wait()
if rc != 0:
print "!!! Error invoking command."
sys.exit(1)
return s
def run_setup(target, pyver = LATEST_PY_VERSION):
execute("python%s ./setup.py release %s" % (pyver, target))
def clone_git_tree(git_dir):
new_git_dir = tempfile.mkdtemp(prefix='rbtools-release.')
os.chdir(new_git_dir)
execute('git clone %s .' % git_dir)
return new_git_dir
def build_targets():
for pyver in PY_VERSIONS:
run_setup("bdist_egg", pyver)
built_files.append("dist/%s-%s-py%s.egg" %
(PACKAGE_NAME, __version__, pyver))
run_setup("sdist")
built_files.append("dist/%s-%s.tar.gz" %
(PACKAGE_NAME, __version__))
def build_checksums():
sha_filename = 'dist/%s-%s.sha256sum' % (PACKAGE_NAME, __version__)
out_f = open(sha_filename, 'w')
for filename in built_files:
m = hashlib.sha256()
in_f = open(filename, 'r')
m.update(in_f.read())
in_f.close()
out_f.write('%s %s\n' % (m.hexdigest(), os.path.basename(filename)))
out_f.close()
built_files.append(sha_filename)
def upload_files():
execute("scp %s %s" % (" ".join(built_files), RELEASES_URL))
def tag_release():
execute("git tag release-%s" % __version__)
def register_release():
if __version_info__[4] == 'final':
run_setup("register")
scm_revision = execute(['git rev-parse', 'release-%s' % __version__])
data = {
'major_version': __version_info__[0],
'minor_version': __version_info__[1],
'micro_version': __version_info__[2],
'release_type': __version_info__[3],
'release_num': __version_info__[4],
'scm_revision': scm_revision,
}
boundary = mimetools.choose_boundary()
content = ''
for key, value in data.iteritems():
content += '--%s\r\n' % boundary
content += 'Content-Disposition: form-data; name="%s"\r\n' % key
content += '\r\n'
content += str(value) + '\r\n'
content += '--%s--\r\n' % boundary
content += '\r\n'
headers = {
'Content-Type': 'multipart/form-data; boundary=%s' % boundary,
'Content-Length': str(len(content)),
}
print 'Posting release to reviewboard.org'
try:
f = urllib2.urlopen(urllib2.Request(url=RELEASES_API_URL, data=content,
headers=headers))
f.read()
except urllib2.HTTPError, e:
print "Error uploading. Got HTTP code %d:" % e.code
print e.read()
except urllib2.URLError, e:
try:
print "Error uploading. Got URL error:" % e.code
print e.read()
except AttributeError:
pass
def main():
if not os.path.exists("setup.py"):
sys.stderr.write("This must be run from the root of the "
"Djblets tree.\n")
sys.exit(1)
load_config()
if not is_release():
sys.stderr.write('This has not been marked as a release in '
'rbtools/__init__.py\n')
sys.exit(1)
cur_dir = os.getcwd()
git_dir = clone_git_tree(cur_dir)
build_targets()
build_checksums()
upload_files()
os.chdir(cur_dir)
shutil.rmtree(git_dir)
tag_release()
register_release()
if __name__ == "__main__":
main()
|