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/09/26 11:38:01 UTC

svn commit: r1867572 - in /subversion/trunk/tools/dist: create-minor-release-branch.py release.py

Author: julianfoad
Date: Thu Sep 26 11:38:01 2019
New Revision: 1867572

URL: http://svn.apache.org/viewvc?rev=1867572&view=rev
Log:
Preparation for merging create-minor-release-branch.py into release.py.

Modified:
    subversion/trunk/tools/dist/create-minor-release-branch.py
    subversion/trunk/tools/dist/release.py

Modified: subversion/trunk/tools/dist/create-minor-release-branch.py
URL: http://svn.apache.org/viewvc/subversion/trunk/tools/dist/create-minor-release-branch.py?rev=1867572&r1=1867571&r2=1867572&view=diff
==============================================================================
--- subversion/trunk/tools/dist/create-minor-release-branch.py (original)
+++ subversion/trunk/tools/dist/create-minor-release-branch.py Thu Sep 26 11:38:01 2019
@@ -31,66 +31,27 @@ import logging
 import subprocess
 import argparse       # standard in Python 2.7
 
-from release import Version
+from release import Version, svn_repos, buildbot_repos, run_svn, get_tempdir, get_workdir
 
 
-# Some constants
-repos = 'https://svn.apache.org/repos/asf/subversion'
-secure_repos = 'https://svn.apache.org/repos/asf/subversion'
-buildbot_repos = 'https://svn.apache.org/repos/infra/infrastructure/buildbot/aegis/buildmaster'
-
-# Parameters
-dry_run = False
-
-# Local working copies
-base_dir = None  # set by main()
-
-def get_trunk_wc_path(path=None):
-    trunk_wc_path = os.path.join(base_dir, 'svn-trunk')
+def get_trunk_wc_path(base_dir, path=None):
+    trunk_wc_path = os.path.join(get_tempdir(base_dir), 'svn-trunk')
     if path is None: return trunk_wc_path
     return os.path.join(trunk_wc_path, path)
-def get_branch_wc_path(ver, path=None):
-    branch_wc_path = os.path.join(base_dir, ver.branch + '.x')
-    if path is None: return branch_wc_path
-    return os.path.join(branch_wc_path, path)
-def get_buildbot_wc_path(path=None):
-    buildbot_wc_path = os.path.join(base_dir, 'svn-buildmaster')
+
+def get_buildbot_wc_path(base_dir, path=None):
+    buildbot_wc_path = os.path.join(get_tempdir(base_dir), 'svn-buildmaster')
     if path is None: return buildbot_wc_path
     return os.path.join(buildbot_wc_path, path)
 
-def get_trunk_url():
-    return secure_repos + '/trunk'
-def get_branch_url(ver):
-    return secure_repos + '/branches/' + ver.branch + '.x'
-def get_tag_url(ver):
-    return secure_repos + '/tags/' + ver.base
-def get_buildbot_url():
-    return buildbot_repos
+def get_trunk_url(revnum=None):
+    return svn_repos + '/trunk' + '@' + (str(revnum) if revnum else '')
 
-#----------------------------------------------------------------------
-# Utility functions
+def get_branch_url(ver):
+    return svn_repos + '/branches/' + ver.branch + '.x'
 
-def run(cmd, dry_run=False):
-    print('+ ' + ' '.join(cmd))
-    if not dry_run:
-        stdout = subprocess.check_output(cmd)
-        print(stdout)
-    else:
-        print('  ## dry-run; not executed')
-
-def run_svn(cmd, dry_run=False):
-    run(['svn'] + cmd, dry_run)
-
-def svn_commit(cmd):
-    run_svn(['commit'] + cmd, dry_run=dry_run)
-
-def svn_copy_branch(src, dst, message):
-    args = ['copy', src, dst, '-m', message]
-    run_svn(args, dry_run=dry_run)
-
-def svn_checkout(url, wc, *args):
-    args = ['checkout', url, wc] + list(args)
-    run_svn(args)
+def get_tag_url(ver):
+    return svn_repos + '/tags/' + ver.base
 
 #----------------------------------------------------------------------
 def edit_file(path, pattern, replacement):
@@ -118,19 +79,23 @@ def edit_changes_file(path, newtext):
         break
 
 #----------------------------------------------------------------------
-def make_release_branch(ver, revnum):
-    svn_copy_branch(get_trunk_url() + '@' + (str(revnum) if revnum else ''),
-                    get_branch_url(ver),
-                    'Create the ' + ver.branch + '.x release branch.')
+def make_release_branch(args):
+    ver = args.version
+    run_svn(['copy',
+             get_trunk_url(args.revnum),
+             get_branch_url(ver),
+             '-m', 'Create the ' + ver.branch + '.x release branch.'],
+            dry_run=args.dry_run)
 
 #----------------------------------------------------------------------
-def update_minor_ver_in_trunk(ver, revnum):
+def update_minor_ver_in_trunk(args):
     """Change the minor version in trunk to the next (future) minor version.
     """
-    trunk_wc = get_trunk_wc_path()
-    trunk_url = get_trunk_url()
-    svn_checkout(trunk_url + '@' + (str(revnum) if revnum else ''),
-                 trunk_wc)
+    ver = args.version
+    trunk_wc = get_trunk_wc_path(args.base_dir)
+    run_svn(['checkout',
+             get_trunk_url(args.revnum),
+             trunk_wc])
 
     prev_ver = Version('1.%d.0' % (ver.minor - 1,))
     next_ver = Version('1.%d.0' % (ver.minor + 1,))
@@ -138,13 +103,13 @@ def update_minor_ver_in_trunk(ver, revnu
 
     relpath = 'subversion/include/svn_version.h'
     relpaths.append(relpath)
-    edit_file(get_trunk_wc_path(relpath),
+    edit_file(get_trunk_wc_path(args.base_dir, relpath),
               r'(#define SVN_VER_MINOR *)%s' % (ver.minor,),
               r'\g<1>%s' % (next_ver.minor,))
 
     relpath = 'subversion/tests/cmdline/svntest/main.py'
     relpaths.append(relpath)
-    edit_file(get_trunk_wc_path(relpath),
+    edit_file(get_trunk_wc_path(args.base_dir, relpath),
               r'(SVN_VER_MINOR = )%s' % (ver.minor,),
               r'\g<1>%s' % (next_ver.minor,))
 
@@ -152,22 +117,22 @@ def update_minor_ver_in_trunk(ver, revnu
     relpaths.append(relpath)
     try:
         # since r1817921 (just after branching 1.10)
-        edit_file(get_trunk_wc_path(relpath),
+        edit_file(get_trunk_wc_path(args.base_dir, relpath),
                   r'SVN_VER_MINOR = %s;' % (ver.minor,),
                   r'SVN_VER_MINOR = %s;' % (next_ver.minor,))
     except:
         # before r1817921: two separate places
-        edit_file(get_trunk_wc_path(relpath),
+        edit_file(get_trunk_wc_path(args.base_dir, relpath),
                   r'version.isAtLeast\(1, %s, 0\)' % (ver.minor,),
                   r'version.isAtLeast\(1, %s, 0\)' % (next_ver.minor,))
-        edit_file(get_trunk_wc_path(relpath),
+        edit_file(get_trunk_wc_path(args.base_dir, relpath),
                   r'1.%s.0, but' % (ver.minor,),
                   r'1.%s.0, but' % (next_ver.minor,))
 
     relpath = 'CHANGES'
     relpaths.append(relpath)
     # insert at beginning of CHANGES file
-    edit_changes_file(get_trunk_wc_path(relpath),
+    edit_changes_file(get_trunk_wc_path(args.base_dir, relpath),
                  'Version ' + next_ver.base + '\n'
                  + '(?? ??? 20XX, from /branches/' + next_ver.branch + '.x)\n'
                  + get_tag_url(next_ver) + '\n'
@@ -184,14 +149,16 @@ section, following the creation of the %
 
 * CHANGES: New section for %s.0.
 ''' % (next_ver.branch, ver.branch, next_ver.minor, next_ver.branch)
-    commit_paths = [get_trunk_wc_path(p) for p in relpaths]
-    svn_commit(commit_paths + ['-m', log_msg])
+    commit_paths = [get_trunk_wc_path(args.base_dir, p) for p in relpaths]
+    run_svn(['commit'] + commit_paths + ['-m', log_msg],
+            dry_run=args.dry_run)
 
 #----------------------------------------------------------------------
-def create_status_file_on_branch(ver):
-    branch_wc = get_branch_wc_path(ver)
+def create_status_file_on_branch(args):
+    ver = args.version
+    branch_wc = get_workdir(args.base_dir)
     branch_url = get_branch_url(ver)
-    svn_checkout(branch_url, branch_wc, '--depth=immediates')
+    run_svn(['checkout', branch_url, branch_wc, '--depth=immediates'])
 
     status_local_path = os.path.join(branch_wc, 'STATUS')
     text='''\
@@ -222,11 +189,13 @@ Approved changes:
 ''' % (ver.branch, ver.base)
     open(status_local_path, 'wx').write(text)
     run_svn(['add', status_local_path])
-    svn_commit([status_local_path,
-                '-m', '* branches/' + ver.branch + '.x/STATUS: New file.'])
+    run_svn(['commit', status_local_path,
+             '-m', '* branches/' + ver.branch + '.x/STATUS: New file.'],
+            dry_run=args.dry_run)
 
 #----------------------------------------------------------------------
-def update_backport_bot(ver):
+def update_backport_bot(args):
+    ver = args.version
     print("""MANUAL STEP: Fork & edit & pull-request on GitHub:
 https://github.com/apache/infrastructure-puppet/blob/deployment/modules/svnqavm_pvm_asf/manifests/init.pp
 "Add new %s.x branch to list of backport branches"
@@ -238,35 +207,36 @@ hostname).
 """)
 
 #----------------------------------------------------------------------
-def update_buildbot_config(ver):
+def update_buildbot_config(args):
     """Add the new branch to the list of branches monitored by the buildbot
        master.
     """
-    buildbot_wc = get_buildbot_wc_path()
-    buildbot_url = get_buildbot_url()
-    svn_checkout(buildbot_url, buildbot_wc)
+    ver = args.version
+    buildbot_wc = get_buildbot_wc_path(args.base_dir)
+    run_svn(['checkout', buildbot_repos, buildbot_wc])
 
     prev_ver = Version('1.%d.0' % (ver.minor - 1,))
     next_ver = Version('1.%d.0' % (ver.minor + 1,))
 
     relpath = 'master1/projects/subversion.conf'
-    edit_file(get_buildbot_wc_path(relpath),
+    edit_file(get_buildbot_wc_path(args.base_dir, relpath),
               r'(MINOR_LINES=\[.*%s)(\])' % (prev_ver.minor,),
               r'\1, %s\2' % (ver.minor,))
 
     log_msg = '''\
 Subversion: start monitoring the %s branch.
 ''' % (ver.branch)
-    commit_paths = [get_buildbot_wc_path(relpath)]
-    svn_commit(commit_paths + ['-m', log_msg])
+    commit_paths = [get_buildbot_wc_path(args.base_dir, relpath)]
+    run_svn(['commit'] + commit_paths + ['-m', log_msg],
+            dry_run=args.dry_run)
 
 #----------------------------------------------------------------------
 def create_release_branch(args):
-    make_release_branch(args.version, args.revnum)
-    update_minor_ver_in_trunk(args.version, args.revnum)
-    create_status_file_on_branch(args.version)
-    update_backport_bot(args.version)
-    update_buildbot_config(args.version)
+    make_release_branch(args)
+    update_minor_ver_in_trunk(args)
+    create_status_file_on_branch(args)
+    update_backport_bot(args)
+    update_buildbot_config(args)
 
 
 #----------------------------------------------------------------------
@@ -278,6 +248,12 @@ def main():
     # Setup our main parser
     parser = argparse.ArgumentParser(
                             description='Create an Apache Subversion release branch.')
+    parser.add_argument('--verbose', action='store_true', default=False,
+                   help='Increase output verbosity')
+    parser.add_argument('--base-dir', default=os.getcwd(),
+                   help='''The directory in which to create needed files and
+                           folders.  The default is the current working
+                           directory.''')
     subparsers = parser.add_subparsers(title='subcommands')
 
     # Setup the parser for the create-release-branch subcommand
@@ -296,20 +272,10 @@ def main():
                             Default is HEAD.''')
     subparser.add_argument('--dry-run', action='store_true', default=False,
                    help='Avoid committing any changes to repositories.')
-    subparser.add_argument('--verbose', action='store_true', default=False,
-                   help='Increase output verbosity')
-    subparser.add_argument('--base-dir', default=os.getcwd(),
-                   help='''The directory in which to create needed files and
-                           folders.  The default is the current working
-                           directory.''')
 
     # Parse the arguments
     args = parser.parse_args()
 
-    global base_dir, dry_run
-    base_dir = args.base_dir
-    dry_run = args.dry_run
-
     # Set up logging
     logger = logging.getLogger()
     if args.verbose:

Modified: subversion/trunk/tools/dist/release.py
URL: http://svn.apache.org/viewvc/subversion/trunk/tools/dist/release.py?rev=1867572&r1=1867571&r2=1867572&view=diff
==============================================================================
--- subversion/trunk/tools/dist/release.py (original)
+++ subversion/trunk/tools/dist/release.py Thu Sep 26 11:38:01 2019
@@ -134,11 +134,12 @@ recommended_release = '1.12'
 supported_release_lines = frozenset({"1.9", "1.10", "1.12", "1.13"})
 
 # Some constants
-svn_repos = 'https://svn.apache.org/repos/asf/subversion'
-dist_repos = 'https://dist.apache.org/repos/dist'
+svn_repos = 'file:///opt/svn/dummy-asf-repos/svn-repo/subversion'
+dist_repos = 'file:///opt/svn/dummy-asf-repos/dist-repo'
 dist_dev_url = dist_repos + '/dev/subversion'
 dist_release_url = dist_repos + '/release/subversion'
 dist_archive_url = 'https://archive.apache.org/dist/subversion'
+buildbot_repos = 'https://svn.apache.org/repos/infra/infrastructure/buildbot/aegis/buildmaster'
 KEYS = 'https://people.apache.org/keys/group/subversion.asc'
 extns = ['zip', 'tar.gz', 'tar.bz2']
 
@@ -314,7 +315,7 @@ def get_tmplfile(filename):
 def get_nullfile():
     return open(os.path.devnull, 'w')
 
-def run_command(cmd, verbose=True, hide_stderr=False):
+def run_command(cmd, verbose=True, hide_stderr=False, dry_run=False):
     if verbose:
         print("+ " + ' '.join(cmd))
     stderr = None
@@ -325,7 +326,10 @@ def run_command(cmd, verbose=True, hide_
         if hide_stderr:
             stderr = get_nullfile()
 
-    subprocess.check_call(cmd, stdout=stdout, stderr=stderr)
+    if not dry_run:
+        subprocess.check_call(cmd, stdout=stdout, stderr=stderr)
+    else:
+        print('  ## dry-run; not executed')
 
 def run_script(verbose, script, hide_stderr=False):
     for l in script.split('\n'):
@@ -345,15 +349,15 @@ def download_file(url, target, checksum)
                            "downloaded: '%s'; expected: '%s'" % \
                            (target, checksum, checksum2))
 
-def run_svn(cmd, verbose=True, username=None):
+def run_svn(cmd, verbose=True, dry_run=False, username=None):
     if (username):
         cmd[:0] = ['--username', username]
-    run_command(['svn'] + cmd, verbose)
+    run_command(['svn'] + cmd, verbose=verbose, dry_run=dry_run)
 
-def run_svnmucc(cmd, verbose=True, username=None):
+def run_svnmucc(cmd, verbose=True, dry_run=False, username=None):
     if (username):
         cmd[:0] = ['--username', username]
-    run_command(['svnmucc'] + cmd, verbose)
+    run_command(['svnmucc'] + cmd, verbose=verbose, dry_run=dry_run)
 
 #----------------------------------------------------------------------
 # ezt helpers



Re: svn commit: r1867572 - in /subversion/trunk/tools/dist: create-minor-release-branch.py release.py

Posted by Julian Foad <ju...@apache.org>.
Daniel Shahaf wrote:
> julianfoad@apache.org wrote on Thu, 26 Sep 2019 
> > -svn_repos = 'https://svn.apache.org/repos/asf/subversion'
> > -dist_repos = 'https://dist.apache.org/repos/dist'
> > +svn_repos = 'file:///opt/svn/dummy-asf-repos/svn-repo/subversion'
> > +dist_repos = 'file:///opt/svn/dummy-asf-repos/dist-repo'
> 
> Scalpel.
 
Argh. Second time I've done that particular one.
 
> P.S. You might change the lines to, say, «svn_repos =
> os.getenv("SVN_REPOS", 'https://…')» to avoid running into
> this again.
 
Good idea. Will do. Thanks.