scripts/release/release.py
author Lennard de Rijk <ljvderijk@gmail.com>
Sun, 15 Mar 2009 14:53:00 +0000
changeset 1868 6847be02943a
parent 1849 f8728d5e2e07
child 1888 ef350db7f753
permissions -rwxr-xr-x
Updated the accepted organization email for GSoC 2009. Left a TODO to use a proper template. Issue 200 addresses a possible solution. Patch by: Lennard de Rijk Reviewed by: to-be-reviewed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
     2
#
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
     3
# Copyright 2009 the Melange authors.
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
     4
#
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
     8
#
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    10
#
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    16
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    17
from __future__ import with_statement
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    18
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    19
"""Google Summer of Code Melange release script.
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    20
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    21
This script provides automation for the various tasks involved in
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    22
pushing a new release of Melange to the official Google Summer of Code
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    23
app engine instance.
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    24
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    25
It does not provide a turnkey autopilot solution. Notably, each stage
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    26
of the release process must be started by a human operator, and some
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    27
commands will request confirmation or extra details before
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    28
proceeding. It is not a replacement for a cautious human
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    29
operator.
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    30
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    31
Note that this script requires:
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    32
 - Python 2.5 or better (for various language features)
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    33
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    34
 - Subversion 1.5.0 or better (for working copy depth control, which
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    35
     cuts down checkout/update times by several orders of
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    36
     magnitude).
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    37
"""
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    38
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    39
__authors__ = [
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    40
    # alphabetical order by last name, please
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    41
    '"David Anderson" <dave@natulte.net>',
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    42
    ]
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    43
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    44
import functools
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    45
import os
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    46
import re
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    47
import subprocess
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    48
import sys
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    49
1822
c6bb25fa7f7b Create an error module containing the top-level error class.
David Anderson <david.jc.anderson@gmail.com>
parents: 1816
diff changeset
    50
import error
1834
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents: 1827
diff changeset
    51
import log
1849
f8728d5e2e07 Factor out the Subversion wrapper to a separate module.
David Anderson <david.jc.anderson@gmail.com>
parents: 1847
diff changeset
    52
import subversion
1824
c54c304e3c0e Refactor ANSI colorization into a new utility module.
David Anderson <david.jc.anderson@gmail.com>
parents: 1823
diff changeset
    53
import util
1822
c6bb25fa7f7b Create an error module containing the top-level error class.
David Anderson <david.jc.anderson@gmail.com>
parents: 1816
diff changeset
    54
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    55
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    56
# Default repository URLs for Melange and the Google release
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    57
# repository.
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    58
MELANGE_REPOS = 'http://soc.googlecode.com/svn'
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    59
GOOGLE_SOC_REPOS = 'https://soc-google.googlecode.com/svn'
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    60
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    61
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    62
# Regular expression matching an apparently well formed Melange
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    63
# release number.
1823
f55d0e1d3f82 Fix the Melange version regular expression to detect patch versions.
David Anderson <david.jc.anderson@gmail.com>
parents: 1822
diff changeset
    64
MELANGE_RELEASE_RE = re.compile(r'\d-\d-\d{8}p\d+')
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    65
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    66
1822
c6bb25fa7f7b Create an error module containing the top-level error class.
David Anderson <david.jc.anderson@gmail.com>
parents: 1816
diff changeset
    67
class Error(error.Error):
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    68
  pass
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    69
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    70
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    71
class AbortedByUser(Error):
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    72
  """The operation was aborted by the user."""
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    73
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    74
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    75
class FileAccessError(Error):
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    76
  """An error occured while accessing a file."""
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    77
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    78
1846
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1835
diff changeset
    79
def getString(prompt):
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1835
diff changeset
    80
  """Prompt for and return a string."""
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1835
diff changeset
    81
  prompt += ' '
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1835
diff changeset
    82
  log.stdout.write(prompt)
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1835
diff changeset
    83
  log.stdout.flush()
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1835
diff changeset
    84
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1835
diff changeset
    85
  response = sys.stdin.readline()
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1835
diff changeset
    86
  log.terminal_echo(prompt + response.strip())
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1835
diff changeset
    87
  if not response:
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1835
diff changeset
    88
    raise AbortedByUser('Aborted by ctrl+D')
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1835
diff changeset
    89
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1835
diff changeset
    90
  return response.strip()
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1835
diff changeset
    91
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1835
diff changeset
    92
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    93
def confirm(prompt, default=False):
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    94
  """Ask a yes/no question and return the answer.
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    95
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    96
  Will reprompt the user until one of "yes", "no", "y" or "n" is
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    97
  entered. The input is case insensitive.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    98
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    99
  Args:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   100
    prompt: The question to ask the user.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   101
    default: The answer to return if the user just hits enter.
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   102
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   103
  Returns:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   104
    True if the user answered affirmatively, False otherwise.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   105
  """
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   106
  if default:
1846
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1835
diff changeset
   107
    question = prompt + ' [Yn]'
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   108
  else:
1846
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1835
diff changeset
   109
    question = prompt + ' [yN]'
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   110
  while True:
1846
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1835
diff changeset
   111
    answer = getString(question)
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   112
    if not answer:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   113
      return default
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   114
    elif answer in ('y', 'yes'):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   115
      return True
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   116
    elif answer in ('n', 'no'):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   117
      return False
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   118
    else:
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   119
      log.error('Please answer yes or no.')
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   120
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   121
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   122
def getNumber(prompt):
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   123
  """Prompt for and return a number.
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   124
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   125
  Will reprompt the user until a number is entered.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   126
  """
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   127
  while True:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   128
    value_str = getString(prompt)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   129
    try:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   130
      return int(value_str)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   131
    except ValueError:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   132
      log.error('Please enter a number. You entered "%s".' % value_str)
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   133
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   134
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   135
def getChoice(intro, prompt, choices, done=None, suggest=None):
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   136
  """Prompt for and return a choice from a menu.
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   137
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   138
  Will reprompt the user until a valid menu entry is chosen.
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   139
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   140
  Args:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   141
    intro: Text to print verbatim before the choice menu.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   142
    prompt: The prompt to print right before accepting input.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   143
    choices: The list of string choices to display.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   144
    done: If not None, the list of indices of previously
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   145
          selected/completed choices.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   146
    suggest: If not None, the index of the choice to highlight as
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   147
             the suggested choice.
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   148
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   149
  Returns:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   150
    The index in the choices list of the selection the user made.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   151
  """
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   152
  done = set(done or [])
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   153
  while True:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   154
    print intro
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   155
    print
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   156
    for i, entry in enumerate(choices):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   157
      done_text = ' (done)' if i in done else ''
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   158
      indent = '--> ' if i == suggest else '    '
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   159
      print '%s%2d. %s%s' % (indent, i+1, entry, done_text)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   160
    print
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   161
    choice = getNumber(prompt)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   162
    if 0 < choice <= len(choices):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   163
      return choice-1
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   164
    log.error('%d is not a valid choice between %d and %d' %
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   165
              (choice, 1, len(choices)))
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   166
    print
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   167
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   168
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   169
def fileToLines(path):
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   170
  """Read a file and return it as a list of lines."""
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   171
  try:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   172
    with file(path) as f:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   173
      return f.read().split('\n')
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   174
  except (IOError, OSError), e:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   175
    raise FileAccessError(str(e))
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   176
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   177
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   178
def linesToFile(path, lines):
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   179
  """Write a list of lines to a file."""
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   180
  try:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   181
    with file(path, 'w') as f:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   182
      f.write('\n'.join(lines))
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   183
  except (IOError, OSError), e:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   184
    raise FileAccessError(str(e))
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   185
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   186
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   187
#
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   188
# Decorators for use in ReleaseEnvironment.
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   189
#
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   190
def pristine_wc(f):
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   191
  """A decorator that cleans up the release repository."""
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   192
  @functools.wraps(f)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   193
  def revert_wc(self, *args, **kwargs):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   194
    self.wc.revert()
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   195
    return f(self, *args, **kwargs)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   196
  return revert_wc
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   197
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   198
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   199
def requires_branch(f):
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   200
  """A decorator that checks that a release branch is active."""
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   201
  @functools.wraps(f)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   202
  def check_branch(self, *args, **kwargs):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   203
    if self.branch is None:
1849
f8728d5e2e07 Factor out the Subversion wrapper to a separate module.
David Anderson <david.jc.anderson@gmail.com>
parents: 1847
diff changeset
   204
      raise error.ExpectationFailed(
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   205
        'This operation requires an active release branch')
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   206
    return f(self, *args, **kwargs)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   207
  return check_branch
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   208
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   209
1825
a610a2df83d2 Move the Paths class to the util module.
David Anderson <david.jc.anderson@gmail.com>
parents: 1824
diff changeset
   210
class ReleaseEnvironment(util.Paths):
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   211
  """Encapsulates the state of a Melange release rolling environment.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   212
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   213
  This class contains the actual releasing logic, and makes use of
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   214
  the previously defined utility classes to carry out user commands.
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   215
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   216
  Attributes:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   217
    release_repos: The URL to the Google release repository root.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   218
    upstream_repos: The URL to the Melange upstream repository root.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   219
    wc: A Subversion object encapsulating a Google SoC working copy.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   220
  """
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   221
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   222
  BRANCH_FILE = 'BRANCH'
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   223
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   224
  def __init__(self, root, release_repos, upstream_repos):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   225
    """Initializer.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   226
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   227
    Args:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   228
      root: The root of the release environment.
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   229
      release_repos: The URL to the Google release repository root.
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   230
      upstream_repos: The URL to the Melange upstream repository root.
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   231
    """
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   232
    util.Paths.__init__(self, root)
1849
f8728d5e2e07 Factor out the Subversion wrapper to a separate module.
David Anderson <david.jc.anderson@gmail.com>
parents: 1847
diff changeset
   233
    self.wc = subversion.WorkingCopy(self.path('google-soc'))
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   234
    self.release_repos = release_repos.strip('/')
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   235
    self.upstream_repos = upstream_repos.strip('/')
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   236
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   237
    if not self.wc.exists():
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   238
      self._InitializeWC()
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   239
    else:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   240
      self.wc.revert()
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   241
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   242
      if self.exists(self.BRANCH_FILE):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   243
        branch = fileToLines(self.path(self.BRANCH_FILE))[0]
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   244
        self._switchBranch(branch)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   245
      else:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   246
        self._switchBranch(None)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   247
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   248
  def _InitializeWC(self):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   249
    """Check out the initial release repository.
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   250
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   251
    Will also select the latest release branch, if any, so that
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   252
    the end state is a fully ready to function release
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   253
    environment.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   254
    """
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   255
    log.info('Checking out the release repository')
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   256
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   257
    # Check out a sparse view of the relevant repository paths.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   258
    self.wc.checkout(self.release_repos, depth='immediates')
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   259
    self.wc.update('vendor', depth='immediates')
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   260
    self.wc.update('branches', depth='immediates')
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   261
    self.wc.update('tags', depth='immediates')
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   262
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   263
    # Locate the most recent release branch, if any, and switch
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   264
    # the release environment to it.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   265
    branches = self._listBranches()
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   266
    if not branches:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   267
      self._switchBranch(None)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   268
    else:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   269
      self._switchBranch(branches[-1])
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   270
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   271
  def _listBranches(self):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   272
    """Return a list of available Melange release branches.
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   273
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   274
    Branches are returned in sorted order, from least recent to
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   275
    most recent in release number ordering.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   276
    """
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   277
    assert self.wc.exists('branches')
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   278
    branches = self.wc.ls('branches')
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   279
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   280
    # Some early release branches used a different naming scheme
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   281
    # that doesn't sort properly with new-style release names. We
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   282
    # filter those out here, along with empty lines.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   283
    branches = [b.strip('/') for b in branches
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   284
          if MELANGE_RELEASE_RE.match(b.strip('/'))]
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   285
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   286
    return sorted(branches)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   287
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   288
  def _switchBranch(self, release):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   289
    """Activate the branch matching the given release.
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   290
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   291
    Once activated, this branch is the target of future release
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   292
    operations.
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   293
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   294
    None can be passed as the release. The result is that no
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   295
    branch is active, and all operations that require an active
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   296
    branch will fail until a branch is activated again. This is
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   297
    used only at initialization, when it is detected that there
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   298
    are no available release branches to activate.
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   299
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   300
    Args:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   301
      release: The version number of a Melange release already
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   302
           imported in the release repository, or None to
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   303
           activate no branch.
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   304
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   305
    """
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   306
    if release is None:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   307
      self.branch = None
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   308
      self.branch_dir = None
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   309
      log.info('No release branch available')
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   310
    else:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   311
      self.wc.update()
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   312
      assert self.wc.exists('branches/' + release)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   313
      linesToFile(self.path(self.BRANCH_FILE), [release])
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   314
      self.branch = release
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   315
      self.branch_dir = 'branches/' + release
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   316
      self.wc.update(self.branch_dir, depth='infinity')
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   317
      log.info('Working on branch ' + self.branch)
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   318
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   319
  def _branchPath(self, path):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   320
    """Return the given path with the release branch path prepended."""
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   321
    assert self.branch_dir is not None
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   322
    return os.path.join(self.branch_dir, path)
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   323
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   324
  #
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   325
  # Release engineering commands. See further down for their
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   326
  # integration into a commandline interface.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   327
  #
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   328
  @pristine_wc
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   329
  def update(self):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   330
    """Update and clean the release repository"""
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   331
    self.wc.update()
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   332
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   333
  @pristine_wc
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   334
  def switchToBranch(self):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   335
    """Switch to another Melange release branch"""
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   336
    branches = self._listBranches()
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   337
    if not branches:
1849
f8728d5e2e07 Factor out the Subversion wrapper to a separate module.
David Anderson <david.jc.anderson@gmail.com>
parents: 1847
diff changeset
   338
      raise error.ExpectationFailed(
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   339
        'No branches available. Please import one.')
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   340
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   341
    choice = getChoice('Available release branches:',
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   342
               'Your choice?',
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   343
               branches,
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   344
               suggest=len(branches)-1)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   345
    self._switchBranch(branches[choice])
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   346
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   347
  def _addAppYaml(self):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   348
    """Create a Google production app.yaml configuration.
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   349
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   350
    The file is copied and modified from the upstream
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   351
    app.yaml.template, configure for Google's Summer of Code App
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   352
    Engine instance, and committed.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   353
    """
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   354
    if self.wc.exists(self._branchPath('app/app.yaml')):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   355
      raise ObstructionError('app/app.yaml exists already')
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   356
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   357
    yaml_path = self._branchPath('app/app.yaml')
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   358
    self.wc.copy(yaml_path + '.template', yaml_path)
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   359
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   360
    yaml = fileToLines(self.wc.path(yaml_path))
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   361
    out = []
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   362
    for i, line in enumerate(yaml):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   363
      stripped_line = line.strip()
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   364
      if 'TODO' in stripped_line:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   365
        continue
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   366
      elif stripped_line == '# application: FIXME':
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   367
        out.append('application: socghop')
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   368
      elif stripped_line.startswith('version:'):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   369
        out.append(line.lstrip() + 'g0')
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   370
        out.append('# * initial Google fork of Melange ' +
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   371
               self.branch)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   372
      else:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   373
        out.append(line)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   374
    linesToFile(self.wc.path(yaml_path), out)
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   375
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   376
    self.wc.commit('Create app.yaml with Google patch version g0 '
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   377
             'in branch ' + self.branch)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   378
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   379
  def _applyGooglePatches(self):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   380
    """Apply Google-specific patches to a vanilla Melange release.
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   381
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   382
    Each patch is applied and committed in turn.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   383
    """
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   384
    # Edit the base template to point users to the Google fork
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   385
    # of the Melange codebase instead of the vanilla release.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   386
    tmpl_file = self.wc.path(
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   387
      self._branchPath('app/soc/templates/soc/base.html'))
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   388
    tmpl = fileToLines(tmpl_file)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   389
    for i, line in enumerate(tmpl):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   390
      if 'http://code.google.com/p/soc/source/browse/tags/' in line:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   391
        tmpl[i] = line.replace('/p/soc/', '/p/soc-google/')
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   392
        break
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   393
    else:
1849
f8728d5e2e07 Factor out the Subversion wrapper to a separate module.
David Anderson <david.jc.anderson@gmail.com>
parents: 1847
diff changeset
   394
      raise error.ExpectationFailed(
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   395
        'No source code link found in base.html')
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   396
    linesToFile(tmpl_file, tmpl)
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   397
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   398
    self.wc.commit(
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   399
      'Customize the Melange release link in the sidebar menu')
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   400
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   401
  @pristine_wc
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   402
  def importTag(self):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   403
    """Import a new Melange release"""
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   404
    release = getString('Enter the Melange release to import:')
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   405
    if not release:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   406
      AbortedByUser('No release provided, import aborted')
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   407
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   408
    branch_dir = 'branches/' + release
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   409
    if self.wc.exists(branch_dir):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   410
      raise ObstructionError('Release %s already imported' % release)
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   411
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   412
    tag_url = '%s/tags/%s' % (self.upstream_repos, release)
1849
f8728d5e2e07 Factor out the Subversion wrapper to a separate module.
David Anderson <david.jc.anderson@gmail.com>
parents: 1847
diff changeset
   413
    release_rev = subversion.find_tag_rev(tag_url)
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   414
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   415
    if confirm('Confirm import of release %s, tagged at r%d?' %
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   416
           (release, release_rev)):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   417
      # Add an entry to the vendor externals for the Melange
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   418
      # release.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   419
      externals = self.wc.propget('svn:externals', 'vendor/soc')
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   420
      externals.append('%s -r %d %s' % (release, release_rev, tag_url))
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   421
      self.wc.propset('svn:externals', '\n'.join(externals), 'vendor/soc')
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   422
      self.wc.commit('Add svn:externals entry to pull in Melange '
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   423
               'release %s at r%d.' % (release, release_rev))
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   424
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   425
      # Export the tag into the release repository's branches
1849
f8728d5e2e07 Factor out the Subversion wrapper to a separate module.
David Anderson <david.jc.anderson@gmail.com>
parents: 1847
diff changeset
   426
      subversion.export(tag_url, release_rev, self.wc.path(branch_dir))
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   427
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   428
      # Add and commit the branch add (very long operation!)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   429
      self.wc.add([branch_dir])
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   430
      self.wc.commit('Branch of Melange release %s' % release,
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   431
               branch_dir)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   432
      self._switchBranch(release)
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   433
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   434
      # Commit the production GSoC configuration and
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   435
      # google-specific patches.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   436
      self._addAppYaml()
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   437
      self._applyGooglePatches()
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   438
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   439
      # All done!
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   440
      log.info('Melange release %s imported and googlified' % self.branch)
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   441
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   442
  @requires_branch
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   443
  @pristine_wc
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   444
  def cherryPickChange(self):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   445
    """Cherry-pick a change from the Melange trunk"""
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   446
    rev = getNumber('Revision number to cherry-pick:')
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   447
    bug = getNumber('Issue fixed by this change:')
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   448
1849
f8728d5e2e07 Factor out the Subversion wrapper to a separate module.
David Anderson <david.jc.anderson@gmail.com>
parents: 1847
diff changeset
   449
    diff = subversion.diff(self.upstream_repos + '/trunk', rev)
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   450
    if not diff.strip():
1849
f8728d5e2e07 Factor out the Subversion wrapper to a separate module.
David Anderson <david.jc.anderson@gmail.com>
parents: 1847
diff changeset
   451
      raise error.ExpectationFailed(
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   452
        'Retrieved diff is empty. '
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   453
        'Did you accidentally cherry-pick a branch change?')
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   454
    util.run(['patch', '-p0'], cwd=self.wc.path(self.branch_dir),
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   455
         stdin=diff)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   456
    self.wc.addRemove(self.branch_dir)
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   457
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   458
    yaml_path = self.wc.path(self._branchPath('app/app.yaml'))
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   459
    out = []
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   460
    updated_patchlevel = False
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   461
    for line in fileToLines(yaml_path):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   462
      if line.strip().startswith('version: '):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   463
        version = line.strip().split()[-1]
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   464
        base, patch = line.rsplit('g', 1)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   465
        new_version = '%sg%d' % (base, int(patch) + 1)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   466
        message = ('Cherry-picked r%d from /p/soc/ to fix issue %d' %
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   467
               (rev, bug))
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   468
        out.append('version: ' + new_version)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   469
        out.append('# * ' + message)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   470
        updated_patchlevel = True
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   471
      else:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   472
        out.append(line)
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   473
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   474
    if not updated_patchlevel:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   475
      log.error('Failed to update Google patch revision')
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   476
      log.error('Cherry-picking failed')
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   477
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   478
    linesToFile(yaml_path, out)
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   479
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   480
    log.info('Check the diff about to be committed with:')
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   481
    log.info('svn diff ' + self.wc.path(self.branch_dir))
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   482
    if not confirm('Commit this change?'):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   483
      raise AbortedByUser('Cherry-pick aborted')
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   484
    self.wc.commit(message)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   485
    log.info('Cherry-picked r%d from the Melange trunk.' % rev)
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   486
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   487
  MENU_ORDER = [
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   488
    update,
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   489
    switchToBranch,
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   490
    importTag,
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   491
    cherryPickChange,
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   492
    ]
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   493
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   494
  MENU_STRINGS = [d.__doc__ for d in MENU_ORDER]
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   495
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   496
  MENU_SUGGESTIONS = {
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   497
    None: update,
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   498
    update: cherryPickChange,
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   499
    switchToBranch: cherryPickChange,
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   500
    importTag: cherryPickChange,
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   501
    cherryPickChange: None,
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   502
    }
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   503
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   504
  def interactiveMenu(self):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   505
    done = []
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   506
    last_choice = None
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   507
    while True:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   508
      # Show the user their previously completed operations and
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   509
      # a suggested next op, to remind them where they are in
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   510
      # the release process (useful after long operations that
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   511
      # may have caused lunch or an extended context switch).
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   512
      if last_choice is not None:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   513
        last_command = self.MENU_ORDER[last_choice]
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   514
      else:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   515
        last_command = None
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   516
      suggested_next = self.MENU_ORDER.index(
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   517
        self.MENU_SUGGESTIONS[last_command])
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   518
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   519
      try:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   520
        choice = getChoice('Main menu:', 'Your choice?',
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   521
                   self.MENU_STRINGS, done=done,
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   522
                   suggest=suggested_next)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   523
      except (KeyboardInterrupt, AbortedByUser):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   524
        log.info('Exiting.')
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   525
        return
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   526
      try:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   527
        self.MENU_ORDER[choice](self)
1849
f8728d5e2e07 Factor out the Subversion wrapper to a separate module.
David Anderson <david.jc.anderson@gmail.com>
parents: 1847
diff changeset
   528
      except error.Error, e:
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   529
        log.error(str(e))
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   530
      else:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   531
        done.append(choice)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   532
        last_choice = choice
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   533
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   534
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   535
def main(argv):
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   536
  if not (1 <= len(argv) <= 3):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   537
    print ('Usage: gsoc-release.py [release repos root URL] '
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   538
           '[upstream repos root URL]')
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   539
    sys.exit(1)
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   540
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   541
  release_repos, upstream_repos = GOOGLE_SOC_REPOS, MELANGE_REPOS
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   542
  if len(argv) >= 2:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   543
    release_repos = argv[1]
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   544
  if len(argv) == 3:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   545
    upstream_repos = argv[2]
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   546
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   547
  log.init('release.log')
1834
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents: 1827
diff changeset
   548
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   549
  log.info('Release repository: ' + release_repos)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   550
  log.info('Upstream repository: ' + upstream_repos)
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   551
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   552
  r = ReleaseEnvironment(os.path.abspath('_release_'),
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   553
                         release_repos,
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   554
                         upstream_repos)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   555
  r.interactiveMenu()
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   556
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   557
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   558
if __name__ == '__main__':
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   559
  main(sys.argv)