You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by ju...@apache.org on 2019/10/30 11:27:13 UTC

svn commit: r1869158 - /subversion/trunk/tools/dist/release.py

Author: julianfoad
Date: Wed Oct 30 11:27:13 2019
New Revision: 1869158

URL: http://svn.apache.org/viewvc?rev=1869158&view=rev
Log:
release.py: some Python 3 fixes.

Modified:
    subversion/trunk/tools/dist/release.py

Modified: subversion/trunk/tools/dist/release.py
URL: http://svn.apache.org/viewvc/subversion/trunk/tools/dist/release.py?rev=1869158&r1=1869157&r2=1869158&view=diff
==============================================================================
--- subversion/trunk/tools/dist/release.py (original)
+++ subversion/trunk/tools/dist/release.py Wed Oct 30 11:27:13 2019
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # python: coding=utf-8
 #
 # Licensed to the Apache Software Foundation (ASF) under one
@@ -41,7 +41,10 @@ import sys
 import glob
 import fnmatch
 import shutil
-import urllib2
+try:
+  from urllib.request import urlopen  # Python 3
+except:
+  from urllib2 import urlopen  # Python 2
 import hashlib
 import tarfile
 import logging
@@ -269,7 +272,7 @@ def get_tmplfile(filename):
         return open(os.path.join(get_tmpldir(), filename))
     except IOError:
         # Hmm, we had a problem with the local version, let's try the repo
-        return urllib2.urlopen(svn_repos + '/trunk/tools/dist/templates/' + filename)
+        return urlopen(svn_repos + '/trunk/tools/dist/templates/' + filename)
 
 def get_nullfile():
     return open(os.path.devnull, 'w')
@@ -302,8 +305,8 @@ def download_file(url, target, checksum)
     """
     assert checksum is None or isinstance(checksum, str)
 
-    response = urllib2.urlopen(url)
-    target_file = open(target, 'w+')
+    response = urlopen(url)
+    target_file = open(target, 'w+b')
     target_file.write(response.read())
     target_file.seek(0)
     m = hashlib.sha256()
@@ -376,7 +379,8 @@ class RollDep(object):
 
     def _test_version(self, cmd):
         proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
-                                stderr=subprocess.STDOUT)
+                                stderr=subprocess.STDOUT,
+                                universal_newlines=True)
         (stdout, stderr) = proc.communicate()
         rc = proc.wait()
         if rc: return ''
@@ -735,7 +739,7 @@ def compare_changes(repos, branch, revis
     mergeinfo_cmd = ['svn', 'mergeinfo', '--show-revs=eligible',
                      repos + '/trunk/CHANGES',
                      repos + '/' + branch + '/' + 'CHANGES']
-    stdout = subprocess.check_output(mergeinfo_cmd)
+    stdout = subprocess.check_output(mergeinfo_cmd, universal_newlines=True)
     if stdout:
       # Treat this as a warning since we are now putting entries for future
       # minor releases in CHANGES on trunk.
@@ -753,7 +757,7 @@ def check_copyright_year(repos, branch,
         file_url = (repos + '/' + branch + '/'
                     + branch_relpath + '@' + str(revision))
         cat_cmd = ['svn', 'cat', file_url]
-        stdout = subprocess.check_output(cat_cmd)
+        stdout = subprocess.check_output(cat_cmd, universal_newlines=True)
         m = _copyright_re.search(stdout)
         if m:
             year = m.group('year')
@@ -962,10 +966,10 @@ def roll_tarballs(args):
             # They are deprecated, however, so we don't publicly link them in
             # the announcements any more.
             m = hashlib.sha1()
-            m.update(open(filepath, 'r').read())
+            m.update(open(filepath, 'rb').read())
             open(filepath + '.sha1', 'w').write(m.hexdigest())
         m = hashlib.sha512()
-        m.update(open(filepath, 'r').read())
+        m.update(open(filepath, 'rb').read())
         open(filepath + '.sha512', 'w').write(m.hexdigest())
 
     # Nightlies do not get tagged so do not need the header
@@ -1092,7 +1096,8 @@ def bump_versions_on_branch(args):
                            args.version.patch + 1))
 
     HEAD = subprocess.check_output(['svn', 'info', '--show-item=revision',
-                                    '--', branch_url]).strip()
+                                    '--', branch_url],
+                                   universal_newlines=True).strip()
     HEAD = int(HEAD)
     def file_object_for(relpath):
         fd = tempfile.NamedTemporaryFile()
@@ -1139,7 +1144,8 @@ def clean_dist(args):
     '''Clean the distribution directory of release artifacts of
     no-longer-supported minor lines.'''
 
-    stdout = subprocess.check_output(['svn', 'list', dist_release_url])
+    stdout = subprocess.check_output(['svn', 'list', dist_release_url],
+                                     universal_newlines=True)
 
     def minor(version):
         """Return the minor release line of the parameter, which must be
@@ -1180,7 +1186,8 @@ def clean_dist(args):
 def move_to_dist(args):
     'Move candidate artifacts to the distribution directory.'
 
-    stdout = subprocess.check_output(['svn', 'list', dist_dev_url])
+    stdout = subprocess.check_output(['svn', 'list', dist_dev_url],
+                                     universal_newlines=True)
 
     filenames = []
     for entry in stdout.split('\n'):
@@ -1368,9 +1375,9 @@ def get_siginfo(args, quiet=False):
                                  % (n, filename, key_end))
                 sys.exit(1)
 
-            fd, fn = tempfile.mkstemp()
-            os.write(fd, key_start + key)
-            os.close(fd)
+            fd, fn = tempfile.mkstemp(text=True)
+            with os.fdopen(fd, 'w') as key_file:
+              key_file.write(key_start + key)
             verified = gpg.verify_file(open(fn, 'rb'), filename[:-4])
             os.unlink(fn)
 
@@ -1392,6 +1399,7 @@ def get_siginfo(args, quiet=False):
         gpg_output = subprocess.check_output(
             ['gpg', '--fixed-list-mode', '--with-colons', '--fingerprint', id],
             stderr=subprocess.STDOUT,
+            universal_newlines=True,
         )
         gpg_output = gpg_output.splitlines()
 
@@ -1459,7 +1467,7 @@ def get_keys(args):
     'Import the LDAP-based KEYS file to gpg'
     # We use a tempfile because urlopen() objects don't have a .fileno()
     with tempfile.SpooledTemporaryFile() as fd:
-        fd.write(urllib2.urlopen(KEYS).read())
+        fd.write(urlopen(KEYS).read())
         fd.flush()
         fd.seek(0)
         subprocess.check_call(['gpg', '--import'], stdin=fd)
@@ -1540,7 +1548,8 @@ def write_changelog(args):
     separator_line = ('-' * 72) + '\n'
     
     mergeinfo = subprocess.check_output(['svn', 'mergeinfo', '--show-revs',
-                    'eligible', '--log', branch_url, previous])
+                    'eligible', '--log', branch_url, previous],
+                                        universal_newlines=True)
     log_messages_dict = {
         # This is a dictionary mapping revision numbers to their respective
         # log messages.  The expression in the "key:" part of the dict