scripts/release/release.py
author David Anderson <david.jc.anderson@gmail.com>
Fri, 13 Mar 2009 23:18:06 +0000
changeset 1847 15ad1ee02dc5
parent 1846 ac30e04bcbba
child 1849 f8728d5e2e07
permissions -rwxr-xr-x
Followup to r2517: don't import threading in release.py
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
1824
c54c304e3c0e Refactor ANSI colorization into a new utility module.
David Anderson <david.jc.anderson@gmail.com>
parents: 1823
diff changeset
    52
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
    53
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    54
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    55
# 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
    56
# repository.
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    57
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
    58
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
    59
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
# 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
    62
# 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
    63
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
    64
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    65
1822
c6bb25fa7f7b Create an error module containing the top-level error class.
David Anderson <david.jc.anderson@gmail.com>
parents: 1816
diff changeset
    66
class Error(error.Error):
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    67
  pass
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    68
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
class AbortedByUser(Error):
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    71
  """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
    72
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
class ObstructionError(Error):
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    75
  """An operation was obstructed by existing data."""
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    76
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
class ExpectationFailed(Error):
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    79
  """An unexpected state was encountered by an automated step."""
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    80
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    81
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    82
class FileAccessError(Error):
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    83
  """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
    84
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    85
1846
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1835
diff changeset
    86
def getString(prompt):
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1835
diff changeset
    87
  """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
    88
  prompt += ' '
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1835
diff changeset
    89
  log.stdout.write(prompt)
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1835
diff changeset
    90
  log.stdout.flush()
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
  response = sys.stdin.readline()
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1835
diff changeset
    93
  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
    94
  if not response:
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1835
diff changeset
    95
    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
    96
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1835
diff changeset
    97
  return response.strip()
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1835
diff changeset
    98
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1835
diff changeset
    99
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   100
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
   101
  """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
   102
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   103
  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
   104
  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
   105
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   106
  Args:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   107
    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
   108
    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
   109
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   110
  Returns:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   111
    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
   112
  """
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   113
  if default:
1846
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1835
diff changeset
   114
    question = prompt + ' [Yn]'
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   115
  else:
1846
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1835
diff changeset
   116
    question = prompt + ' [yN]'
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   117
  while True:
1846
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1835
diff changeset
   118
    answer = getString(question)
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   119
    if not answer:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   120
      return default
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   121
    elif answer in ('y', 'yes'):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   122
      return True
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   123
    elif answer in ('n', 'no'):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   124
      return False
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   125
    else:
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   126
      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
   127
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   128
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   129
def getNumber(prompt):
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   130
  """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
   131
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   132
  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
   133
  """
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   134
  while True:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   135
    value_str = getString(prompt)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   136
    try:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   137
      return int(value_str)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   138
    except ValueError:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   139
      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
   140
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   141
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   142
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
   143
  """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
   144
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   145
  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
   146
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   147
  Args:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   148
    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
   149
    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
   150
    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
   151
    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
   152
          selected/completed choices.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   153
    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
   154
             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
   155
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   156
  Returns:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   157
    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
   158
  """
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   159
  done = set(done or [])
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   160
  while True:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   161
    print intro
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   162
    print
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   163
    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
   164
      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
   165
      indent = '--> ' if i == suggest else '    '
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   166
      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
   167
    print
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   168
    choice = getNumber(prompt)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   169
    if 0 < choice <= len(choices):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   170
      return choice-1
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   171
    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
   172
              (choice, 1, len(choices)))
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   173
    print
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   174
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   175
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   176
def fileToLines(path):
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   177
  """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
   178
  try:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   179
    with file(path) as f:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   180
      return f.read().split('\n')
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   181
  except (IOError, OSError), e:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   182
    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
   183
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   184
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   185
def linesToFile(path, lines):
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   186
  """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
   187
  try:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   188
    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
   189
      f.write('\n'.join(lines))
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   190
  except (IOError, OSError), e:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   191
    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
   192
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   193
1825
a610a2df83d2 Move the Paths class to the util module.
David Anderson <david.jc.anderson@gmail.com>
parents: 1824
diff changeset
   194
class Subversion(util.Paths):
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   195
  """Wrapper for operations on a Subversion working copy.
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   196
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   197
  An instance of this class is bound to a specific working copy
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   198
  directory, and provides an API to perform various Subversion
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   199
  operations on this working copy.
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   200
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   201
  Some methods take a 'depth' argument. Depth in Subversion is a
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   202
  feature that allows the creation of arbitrarily shallow or deep
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   203
  working copies on a per-directory basis. Possible values are
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   204
  'none' (no files or directories), 'files' (only files in .),
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   205
  'immediates' (files and directories in ., directories checked out
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   206
  at depth 'none') or 'infinity' (a normal working copy with
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   207
  everything).
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   208
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   209
  This class also provides a few static functions that run the 'svn'
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   210
  tool against remote repositories to gather information or retrieve
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   211
  data.
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   212
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   213
  Note that this wrapper also doubles as a Paths object, offering an
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   214
  easy way to get or check the existence of paths in the working
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   215
  copy.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   216
  """
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   217
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   218
  def __init__(self, wc_dir):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   219
    util.Paths.__init__(self, wc_dir)
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   220
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   221
  def _unknownAndMissing(self, path):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   222
    """Returns lists of unknown and missing files in the working copy.
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   223
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   224
    Args:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   225
      path: The working copy path to scan.
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   226
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   227
    Returns:
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   228
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   229
      Two lists. The first is a list of all unknown paths
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   230
      (subversion has no knowledge of them), the second is a list
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   231
      of missing paths (subversion knows about them, but can't
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   232
      find them). Paths in either list are relative to the input
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   233
      path.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   234
    """
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   235
    assert self.exists()
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   236
    unknown = []
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   237
    missing = []
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   238
    for line in self.status(path):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   239
      if not line.strip():
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   240
        continue
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   241
      if line[0] == '?':
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   242
        unknown.append(line[7:])
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   243
      elif line[0] == '!':
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   244
        missing.append(line[7:])
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   245
    return unknown, missing
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   246
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   247
  def checkout(self, url, depth='infinity'):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   248
    """Check out a working copy from the given URL.
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   249
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   250
    Args:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   251
      url: The Subversion repository URL to check out.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   252
      depth: The depth of the working copy root.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   253
    """
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   254
    assert not self.exists()
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   255
    util.run(['svn', 'checkout', '--depth=' + depth, url, self.path()])
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
  def update(self, path='', depth=None):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   258
    """Update a working copy path, optionally changing depth.
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   259
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   260
    Args:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   261
      path: The working copy path to update.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   262
      depth: If set, change the depth of the path before updating.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   263
    """
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   264
    assert self.exists()
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   265
    if depth is None:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   266
      util.run(['svn', 'update', self.path(path)])
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   267
    else:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   268
      util.run(['svn', 'update', '--set-depth=' + depth, self.path(path)])
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   269
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   270
  def revert(self, path=''):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   271
    """Recursively revert a working copy path.
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   272
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   273
    Note that this command is more zealous than the 'svn revert'
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   274
    command, as it will also delete any files which subversion
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   275
    does not know about.
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
    util.run(['svn', 'revert', '-R', self.path(path)])
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   278
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   279
    unknown, missing = self._unknownAndMissing(path)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   280
    unknown = [os.path.join(self.path(path), p) for p in unknown]
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   281
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   282
    if unknown:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   283
      # rm -rf makes me uneasy. Verify that all paths to be deleted
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   284
      # are within the release working copy.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   285
      for p in unknown:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   286
        assert p.startswith(self.path())
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   287
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   288
      util.run(['rm', '-rf', '--'] + unknown)
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   289
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   290
  def ls(self, dir=''):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   291
    """List the contents of a working copy directory.
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   292
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   293
    Note that this returns the contents of the directory as seen
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   294
    by the server, not constrained by the depth settings of the
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   295
    local path.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   296
    """
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   297
    assert self.exists()
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   298
    return util.run(['svn', 'ls', self.path(dir)], capture=True)
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
  def copy(self, src, dest):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   301
    """Copy a working copy path.
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   302
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   303
    The copy is only scheduled for commit, not committed.
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
    Args:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   306
      src: The source working copy path.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   307
      dst: The destination working copy path.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   308
    """
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   309
    assert self.exists()
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   310
    util.run(['svn', 'cp', self.path(src), self.path(dest)])
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   311
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   312
  def propget(self, prop_name, path):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   313
    """Get the value of a property on a working copy path.
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   314
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   315
    Args:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   316
      prop_name: The property name, eg. 'svn:externals'.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   317
      path: The working copy path on which the property is set.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   318
    """
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   319
    assert self.exists()
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   320
    return util.run(['svn', 'propget', prop_name, self.path(path)],
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   321
            capture=True)
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   322
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   323
  def propset(self, prop_name, prop_value, path):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   324
    """Set the value of a property on a working copy path.
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   325
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   326
    The property change is only scheduled for commit, not committed.
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   327
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   328
    Args:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   329
      prop_name: The property name, eg. 'svn:externals'.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   330
      prop_value: The value that should be set.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   331
      path: The working copy path on which to set the property.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   332
    """
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   333
    assert self.exists()
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   334
    util.run(['svn', 'propset', prop_name, prop_value, self.path(path)])
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   335
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   336
  def add(self, paths):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   337
    """Schedule working copy paths for addition.
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   338
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   339
    The paths are only scheduled for addition, not committed.
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
    Args:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   342
      paths: The list of working copy paths to add.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   343
    """
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   344
    assert self.exists()
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   345
    paths = [self.path(p) for p in paths]
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   346
    util.run(['svn', 'add'] + paths)
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   347
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   348
  def remove(self, paths):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   349
    """Schedule working copy paths for deletion.
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   350
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   351
    The paths are only scheduled for deletion, not committed.
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   352
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   353
    Args:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   354
      paths: The list of working copy paths to delete.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   355
    """
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   356
    assert self.exists()
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   357
    paths = [self.path(p) for p in paths]
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   358
    util.run(['svn', 'rm'] + paths)
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
  def status(self, path=''):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   361
    """Return the status of a working copy path.
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   362
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   363
    The status returned is the verbatim output of 'svn status' on
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   364
    the path.
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   365
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   366
    Args:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   367
      path: The path to examine.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   368
    """
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   369
    assert self.exists()
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   370
    return util.run(['svn', 'status', self.path(path)], capture=True)
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   371
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   372
  def addRemove(self, path=''):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   373
    """Perform an "addremove" operation a working copy path.
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   374
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   375
    An "addremove" runs 'svn status' and schedules all the unknown
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   376
    paths (listed as '?') for addition, and all the missing paths
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   377
    (listed as '!') for deletion. Its main use is to synchronize
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   378
    working copy state after applying a patch in unified diff
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   379
    format.
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   380
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   381
    Args:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   382
      path: The path under which unknown/missing files should be
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   383
        added/removed.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   384
    """
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   385
    assert self.exists()
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   386
    unknown, missing = self._unknownAndMissing(path)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   387
    if unknown:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   388
      self.add(unknown)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   389
    if missing:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   390
      self.remove(missing)
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   391
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   392
  def commit(self, message, path=''):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   393
    """Commit scheduled changes to the source repository.
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   394
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   395
    Args:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   396
      message: The commit message to use.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   397
      path: The path to commit.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   398
    """
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   399
    assert self.exists()
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   400
    util.run(['svn', 'commit', '-m', message, self.path(path)])
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   401
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   402
  @staticmethod
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   403
  def export(url, revision, dest_path):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   404
    """Export the contents of a repository to a local path.
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   405
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   406
    Note that while the underlying 'svn export' only requires a
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   407
    URL, we require that both a URL and a revision be specified,
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   408
    to fully qualify the data to export.
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   409
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   410
    Args:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   411
      url: The repository URL to export.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   412
      revision: The revision to export.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   413
      dest_path: The destination directory for the export. Note
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   414
           that this is an absolute path, NOT a working copy
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   415
           relative path.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   416
    """
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   417
    assert os.path.isabs(dest_path)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   418
    if os.path.exists(dest_path):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   419
      raise ObstructionError('Cannot export to obstructed path %s' %
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   420
                   dest_path)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   421
    util.run(['svn', 'export', '-r', str(revision), url, dest_path])
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   422
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   423
  @staticmethod
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   424
  def find_tag_rev(url):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   425
    """Return the revision at which a remote tag was created.
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   426
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   427
    Since tags are immutable by convention, usually the HEAD of a
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   428
    tag should be the tag creation revision. However, mistakes can
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   429
    happen, so this function will walk the history of the given
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   430
    tag URL, stopping on the first revision that was created by
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   431
    copy.
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   432
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   433
    This detection is not foolproof. For example: it will be
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   434
    fooled by a tag that was created, deleted, and recreated by
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   435
    copy at a different revision. It is not clear what the desired
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   436
    behavior in these edge cases are, and no attempt is made to
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   437
    handle them. You should request user confirmation before using
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   438
    the result of this function.
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   439
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   440
    Args:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   441
      url: The repository URL of the tag to examine.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   442
    """
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   443
    try:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   444
      output = util.run(['svn', 'log', '-q', '--stop-on-copy', url],
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   445
                capture=True)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   446
    except util.SubprocessFailed:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   447
      raise ExpectationFailed('No tag at URL ' + url)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   448
    first_rev_line = output[-2]
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   449
    first_rev = int(first_rev_line.split()[0][1:])
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   450
    return first_rev
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   451
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   452
  @staticmethod
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   453
  def diff(url, revision):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   454
    """Retrieve a revision from a remote repository as a unified diff.
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   455
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   456
    Args:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   457
      url: The repository URL on which to perform the diff.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   458
      revision: The revision to extract at the given url.
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   459
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   460
    Returns:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   461
      A string containing the changes extracted from the remote
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   462
      repository, in unified diff format suitable for application
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   463
      using 'patch'.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   464
    """
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   465
    try:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   466
      return util.run(['svn', 'diff', '-c', str(revision), url],
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   467
              capture=True, split_capture=False)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   468
    except util.SubprocessFailed:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   469
      raise ExpectationFailed('Could not get diff for r%d '
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   470
                  'from remote repository' % revision)
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   471
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   472
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   473
#
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   474
# 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
   475
#
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   476
def pristine_wc(f):
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   477
  """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
   478
  @functools.wraps(f)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   479
  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
   480
    self.wc.revert()
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   481
    return f(self, *args, **kwargs)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   482
  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
   483
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   484
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   485
def requires_branch(f):
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   486
  """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
   487
  @functools.wraps(f)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   488
  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
   489
    if self.branch is None:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   490
      raise ExpectationFailed(
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   491
        '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
   492
    return f(self, *args, **kwargs)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   493
  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
   494
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   495
1825
a610a2df83d2 Move the Paths class to the util module.
David Anderson <david.jc.anderson@gmail.com>
parents: 1824
diff changeset
   496
class ReleaseEnvironment(util.Paths):
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   497
  """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
   498
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   499
  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
   500
  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
   501
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   502
  Attributes:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   503
    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
   504
    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
   505
    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
   506
  """
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   507
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   508
  BRANCH_FILE = 'BRANCH'
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   509
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   510
  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
   511
    """Initializer.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   512
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   513
    Args:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   514
      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
   515
      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
   516
      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
   517
    """
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   518
    util.Paths.__init__(self, root)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   519
    self.wc = Subversion(self.path('google-soc'))
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   520
    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
   521
    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
   522
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   523
    if not self.wc.exists():
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   524
      self._InitializeWC()
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   525
    else:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   526
      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
   527
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   528
      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
   529
        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
   530
        self._switchBranch(branch)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   531
      else:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   532
        self._switchBranch(None)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   533
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   534
  def _InitializeWC(self):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   535
    """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
   536
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   537
    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
   538
    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
   539
    environment.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   540
    """
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   541
    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
   542
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   543
    # 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
   544
    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
   545
    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
   546
    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
   547
    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
   548
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   549
    # 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
   550
    # the release environment to it.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   551
    branches = self._listBranches()
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   552
    if not branches:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   553
      self._switchBranch(None)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   554
    else:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   555
      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
   556
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   557
  def _listBranches(self):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   558
    """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
   559
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   560
    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
   561
    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
   562
    """
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   563
    assert self.wc.exists('branches')
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   564
    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
   565
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   566
    # 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
   567
    # 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
   568
    # 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
   569
    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
   570
          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
   571
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   572
    return sorted(branches)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   573
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   574
  def _switchBranch(self, release):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   575
    """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
   576
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   577
    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
   578
    operations.
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   579
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   580
    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
   581
    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
   582
    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
   583
    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
   584
    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
   585
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   586
    Args:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   587
      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
   588
           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
   589
           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
   590
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   591
    """
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   592
    if release is None:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   593
      self.branch = None
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   594
      self.branch_dir = None
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   595
      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
   596
    else:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   597
      self.wc.update()
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   598
      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
   599
      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
   600
      self.branch = release
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   601
      self.branch_dir = 'branches/' + release
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   602
      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
   603
      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
   604
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   605
  def _branchPath(self, path):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   606
    """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
   607
    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
   608
    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
   609
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   610
  #
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   611
  # 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
   612
  # integration into a commandline interface.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   613
  #
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   614
  @pristine_wc
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   615
  def update(self):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   616
    """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
   617
    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
   618
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   619
  @pristine_wc
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   620
  def switchToBranch(self):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   621
    """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
   622
    branches = self._listBranches()
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   623
    if not branches:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   624
      raise ExpectationFailed(
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   625
        '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
   626
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   627
    choice = getChoice('Available release branches:',
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   628
               'Your choice?',
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   629
               branches,
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   630
               suggest=len(branches)-1)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   631
    self._switchBranch(branches[choice])
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   632
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   633
  def _addAppYaml(self):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   634
    """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
   635
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   636
    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
   637
    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
   638
    Engine instance, and committed.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   639
    """
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   640
    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
   641
      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
   642
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   643
    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
   644
    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
   645
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   646
    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
   647
    out = []
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   648
    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
   649
      stripped_line = line.strip()
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   650
      if 'TODO' in stripped_line:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   651
        continue
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   652
      elif stripped_line == '# application: FIXME':
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   653
        out.append('application: socghop')
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   654
      elif stripped_line.startswith('version:'):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   655
        out.append(line.lstrip() + 'g0')
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   656
        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
   657
               self.branch)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   658
      else:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   659
        out.append(line)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   660
    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
   661
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   662
    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
   663
             'in branch ' + self.branch)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   664
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   665
  def _applyGooglePatches(self):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   666
    """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
   667
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   668
    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
   669
    """
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   670
    # 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
   671
    # 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
   672
    tmpl_file = self.wc.path(
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   673
      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
   674
    tmpl = fileToLines(tmpl_file)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   675
    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
   676
      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
   677
        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
   678
        break
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   679
    else:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   680
      raise ExpectationFailed(
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   681
        '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
   682
    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
   683
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   684
    self.wc.commit(
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   685
      '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
   686
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   687
  @pristine_wc
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   688
  def importTag(self):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   689
    """Import a new Melange release"""
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   690
    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
   691
    if not release:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   692
      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
   693
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   694
    branch_dir = 'branches/' + release
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   695
    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
   696
      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
   697
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   698
    tag_url = '%s/tags/%s' % (self.upstream_repos, release)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   699
    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
   700
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   701
    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
   702
           (release, release_rev)):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   703
      # 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
   704
      # release.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   705
      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
   706
      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
   707
      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
   708
      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
   709
               '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
   710
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   711
      # Export the tag into the release repository's branches
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   712
      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
   713
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   714
      # 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
   715
      self.wc.add([branch_dir])
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   716
      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
   717
               branch_dir)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   718
      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
   719
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   720
      # 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
   721
      # google-specific patches.
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   722
      self._addAppYaml()
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   723
      self._applyGooglePatches()
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   724
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   725
      # All done!
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   726
      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
   727
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   728
  @requires_branch
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   729
  @pristine_wc
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   730
  def cherryPickChange(self):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   731
    """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
   732
    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
   733
    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
   734
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   735
    diff = self.wc.diff(self.upstream_repos + '/trunk', rev)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   736
    if not diff.strip():
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   737
      raise ExpectationFailed(
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   738
        'Retrieved diff is empty. '
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   739
        '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
   740
    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
   741
         stdin=diff)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   742
    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
   743
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   744
    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
   745
    out = []
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   746
    updated_patchlevel = False
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   747
    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
   748
      if line.strip().startswith('version: '):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   749
        version = line.strip().split()[-1]
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   750
        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
   751
        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
   752
        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
   753
               (rev, bug))
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   754
        out.append('version: ' + new_version)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   755
        out.append('# * ' + message)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   756
        updated_patchlevel = True
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   757
      else:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   758
        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
   759
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   760
    if not updated_patchlevel:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   761
      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
   762
      log.error('Cherry-picking failed')
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   763
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   764
    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
   765
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   766
    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
   767
    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
   768
    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
   769
      raise AbortedByUser('Cherry-pick aborted')
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   770
    self.wc.commit(message)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   771
    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
   772
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   773
  MENU_ORDER = [
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   774
    update,
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   775
    switchToBranch,
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   776
    importTag,
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   777
    cherryPickChange,
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   778
    ]
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   779
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   780
  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
   781
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   782
  MENU_SUGGESTIONS = {
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   783
    None: update,
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   784
    update: cherryPickChange,
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   785
    switchToBranch: cherryPickChange,
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   786
    importTag: cherryPickChange,
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   787
    cherryPickChange: None,
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   788
    }
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   789
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   790
  def interactiveMenu(self):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   791
    done = []
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   792
    last_choice = None
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   793
    while True:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   794
      # 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
   795
      # 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
   796
      # 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
   797
      # 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
   798
      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
   799
        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
   800
      else:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   801
        last_command = None
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   802
      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
   803
        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
   804
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   805
      try:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   806
        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
   807
                   self.MENU_STRINGS, done=done,
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   808
                   suggest=suggested_next)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   809
      except (KeyboardInterrupt, AbortedByUser):
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   810
        log.info('Exiting.')
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   811
        return
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   812
      try:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   813
        self.MENU_ORDER[choice](self)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   814
      except Error, e:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   815
        log.error(str(e))
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   816
      else:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   817
        done.append(choice)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   818
        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
   819
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   820
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   821
def main(argv):
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   822
  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
   823
    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
   824
           '[upstream repos root URL]')
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   825
    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
   826
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   827
  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
   828
  if len(argv) >= 2:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   829
    release_repos = argv[1]
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   830
  if len(argv) == 3:
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   831
    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
   832
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   833
  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
   834
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   835
  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
   836
  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
   837
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   838
  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
   839
                         release_repos,
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   840
                         upstream_repos)
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   841
  r.interactiveMenu()
1816
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   842
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   843
07743b5295d3 Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   844
if __name__ == '__main__':
1835
3f30b7b14c57 Fix indentation to match Melange/Google style.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   845
  main(sys.argv)