From 38af6239b1823908c3c2522245d41bd4105ec1e8 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 18 Jun 2013 15:31:41 -0500 Subject: Update release script to run under Python 3 --- release.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'release.py') diff --git a/release.py b/release.py index 632bf4cb..0a2e2bde 100644 --- a/release.py +++ b/release.py @@ -11,12 +11,21 @@ import subprocess import shutil import os import sys -import urllib2 import getpass import collections import itertools import re +try: + import urllib.request as urllib_request +except ImportError: + import urllib2 as urllib_request + +try: + input = raw_input +except NameError: + pass + try: import keyring except Exception: @@ -27,7 +36,7 @@ PACKAGE_INDEX = 'https://pypi.python.org/pypi' def set_versions(): global VERSION - version = raw_input("Release as version [%s]> " % VERSION) or VERSION + version = input("Release as version [%s]> " % VERSION) or VERSION if version != VERSION: VERSION = bump_versions(version) @@ -99,11 +108,11 @@ def add_milestone_and_version(version): for type in 'milestones', 'versions': url = (base + '/1.0/repositories/{repo}/issues/{type}' .format(repo = get_repo_name(), type=type)) - req = urllib2.Request(url = url, headers = headers, + req = urllib_request.Request(url = url, headers = headers, data='name='+version) try: - urllib2.urlopen(req) - except urllib2.HTTPError as e: + urllib_request.urlopen(req) + except urllib_request.HTTPError as e: print(e.fp.read()) def bump_versions(target_ver): @@ -116,7 +125,10 @@ def bump_versions(target_ver): def bump_version(filename, target_ver): with open(filename, 'rb') as f: - lines = [line.replace(VERSION, target_ver) for line in f] + lines = [ + line.replace(VERSION.encode('ascii'), target_ver.encode('ascii')) + for line in f + ] with open(filename, 'wb') as f: f.writelines(lines) -- cgit v1.2.3