Skip to content

Commit

Permalink
Merge branch 'release-0.3.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
chipx86 committed Aug 16, 2011
2 parents ed576a8 + 26f9b14 commit 6003f9e
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 5 deletions.
123 changes: 119 additions & 4 deletions contrib/internal/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
# developers with release permissions.
#

import hashlib
import mimetools
import os
import re
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
Expand All @@ -26,17 +29,65 @@
__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):
print ">>> %s" % cmdline
if isinstance(cmdline, list):
print ">>> %s" % subprocess.list2cmdline(cmdline)
else:
print ">>> %s" % cmdline

p = subprocess.Popen(cmdline,
shell=True,
stdout=subprocess.PIPE)

s = ''

if os.system(cmdline) != 0:
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))
Expand All @@ -62,6 +113,23 @@ def build_targets():
(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))

Expand All @@ -71,7 +139,51 @@ def tag_release():


def register_release():
run_setup("register")
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():
Expand All @@ -80,6 +192,8 @@ def main():
"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')
Expand All @@ -89,6 +203,7 @@ def main():
git_dir = clone_git_tree(cur_dir)

build_targets()
build_checksums()
upload_files()

os.chdir(cur_dir)
Expand Down
2 changes: 1 addition & 1 deletion rbtools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#
# (Major, Minor, Micro, alpha/beta/rc/final, Release Number, Released)
#
VERSION = (0, 3, 2, 'final', 0, True)
VERSION = (0, 3, 4, 'alpha', 0, False)


def get_version_string():
Expand Down

0 comments on commit 6003f9e

Please sign in to comment.