author | David Anderson <david.jc.anderson@gmail.com> |
Fri, 13 Mar 2009 02:56:35 +0000 | |
changeset 1826 | 12de6d73a908 |
parent 1825 | a610a2df83d2 |
child 1827 | c03995a6a88e |
permissions | -rwxr-xr-x |
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 |
1824
c54c304e3c0e
Refactor ANSI colorization into a new utility module.
David Anderson <david.jc.anderson@gmail.com>
parents:
1823
diff
changeset
|
51 |
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
|
52 |
|
1816
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
53 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
54 |
# 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
|
55 |
# repository. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
56 |
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
|
57 |
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
|
58 |
|
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 |
# 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
|
61 |
# 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
|
62 |
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
|
63 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
64 |
|
1822
c6bb25fa7f7b
Create an error module containing the top-level error class.
David Anderson <david.jc.anderson@gmail.com>
parents:
1816
diff
changeset
|
65 |
class Error(error.Error): |
1816
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
66 |
pass |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
67 |
|
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 |
class SubprocessFailed(Error): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
70 |
"""A subprocess returned a non-zero error code.""" |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
71 |
|
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 |
class AbortedByUser(Error): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
74 |
"""The operation was aborted by the user.""" |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
75 |
|
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 |
class ObstructionError(Error): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
78 |
"""An operation was obstructed by existing data.""" |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
79 |
|
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 |
class ExpectationFailed(Error): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
82 |
"""An unexpected state was encountered by an automated step.""" |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
83 |
|
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 |
class FileAccessError(Error): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
86 |
"""An error occured while accessing a file.""" |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
87 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
88 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
89 |
def run(argv, cwd=None, capture=False, split_capture=True, stdin=''): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
90 |
"""Run the given command and optionally return its output. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
91 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
92 |
Note that if you set capture=True, the command's output is |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
93 |
buffered in memory. Output capture should only be used with |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
94 |
commands that output small amounts of data. O(kB) is fine, O(MB) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
95 |
is starting to push it a little. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
96 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
97 |
Args: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
98 |
argv: A list containing the name of the program to run, followed |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
99 |
by its argument vector. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
100 |
cwd: Run the program from this directory. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
101 |
capture: If True, capture the program's stdout stream. If False, |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
102 |
stdout will output to sys.stdout. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
103 |
split_capture: If True, return the captured output as a list of |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
104 |
lines. Else, return as a single unaltered string. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
105 |
stdin: The string to feed to the program's stdin stream. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
106 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
107 |
Returns: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
108 |
If capture is True, a string containing the combined |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
109 |
stdout/stderr output of the program. If capture is False, |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
110 |
nothing is returned. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
111 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
112 |
Raises: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
113 |
SubprocessFailed: The subprocess exited with a non-zero exit |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
114 |
code. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
115 |
""" |
1824
c54c304e3c0e
Refactor ANSI colorization into a new utility module.
David Anderson <david.jc.anderson@gmail.com>
parents:
1823
diff
changeset
|
116 |
print util.colorize('# ' + ' '.join(argv), util.WHITE, bold=True) |
1816
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
117 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
118 |
process = subprocess.Popen(argv, |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
119 |
shell=False, |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
120 |
cwd=cwd, |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
121 |
stdin=subprocess.PIPE, |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
122 |
stdout=(subprocess.PIPE if capture else None), |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
123 |
stderr=None) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
124 |
output, _ = process.communicate(input=stdin) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
125 |
if process.returncode != 0: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
126 |
raise SubprocessFailed('Process %s failed with output: %s' % |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
127 |
(argv[0], output)) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
128 |
if output is not None and split_capture: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
129 |
return output.strip().split('\n') |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
130 |
else: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
131 |
return output |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
132 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
133 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
134 |
def error(msg): |
1824
c54c304e3c0e
Refactor ANSI colorization into a new utility module.
David Anderson <david.jc.anderson@gmail.com>
parents:
1823
diff
changeset
|
135 |
"""Log an error message.""" |
c54c304e3c0e
Refactor ANSI colorization into a new utility module.
David Anderson <david.jc.anderson@gmail.com>
parents:
1823
diff
changeset
|
136 |
print util.colorize(msg, util.RED, bold=True) |
1816
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
137 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
138 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
139 |
def info(msg): |
1824
c54c304e3c0e
Refactor ANSI colorization into a new utility module.
David Anderson <david.jc.anderson@gmail.com>
parents:
1823
diff
changeset
|
140 |
"""Log an informational message.""" |
c54c304e3c0e
Refactor ANSI colorization into a new utility module.
David Anderson <david.jc.anderson@gmail.com>
parents:
1823
diff
changeset
|
141 |
print util.colorize(msg, util.GREEN) |
1816
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
142 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
143 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
144 |
def confirm(prompt, default=False): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
145 |
"""Ask a yes/no question and return the answer. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
146 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
147 |
Will reprompt the user until one of "yes", "no", "y" or "n" is |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
148 |
entered. The input is case insensitive. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
149 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
150 |
Args: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
151 |
prompt: The question to ask the user. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
152 |
default: The answer to return if the user just hits enter. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
153 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
154 |
Returns: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
155 |
True if the user answered affirmatively, False otherwise. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
156 |
""" |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
157 |
if default: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
158 |
question = prompt + ' [Yn] ' |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
159 |
else: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
160 |
question = prompt + ' [yN] ' |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
161 |
while True: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
162 |
try: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
163 |
answer = raw_input(question).strip().lower() |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
164 |
except EOFError: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
165 |
raise AbortedByUser('Aborted by ctrl+D') |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
166 |
if not answer: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
167 |
return default |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
168 |
elif answer in ('y', 'yes'): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
169 |
return True |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
170 |
elif answer in ('n', 'no'): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
171 |
return False |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
172 |
else: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
173 |
error('Please answer yes or no.') |
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 getString(prompt): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
177 |
"""Prompt for and return a string.""" |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
178 |
try: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
179 |
return raw_input(prompt + ' ').strip() |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
180 |
except EOFError: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
181 |
raise AbortedByUser('Aborted by ctrl+D') |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
182 |
|
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 |
def getNumber(prompt): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
185 |
"""Prompt for and return a number. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
186 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
187 |
Will reprompt the user until a number is entered. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
188 |
""" |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
189 |
while True: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
190 |
value_str = getString(prompt) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
191 |
try: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
192 |
return int(value_str) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
193 |
except ValueError: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
194 |
error('Please enter a number. You entered "%s".' % value_str) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
195 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
196 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
197 |
def getChoice(intro, prompt, choices, done=None, suggest=None): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
198 |
"""Prompt for and return a choice from a menu. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
199 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
200 |
Will reprompt the user until a valid menu entry is chosen. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
201 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
202 |
Args: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
203 |
intro: Text to print verbatim before the choice menu. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
204 |
prompt: The prompt to print right before accepting input. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
205 |
choices: The list of string choices to display. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
206 |
done: If not None, the list of indices of previously |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
207 |
selected/completed choices. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
208 |
suggest: If not None, the index of the choice to highlight as |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
209 |
the suggested choice. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
210 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
211 |
Returns: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
212 |
The index in the choices list of the selection the user made. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
213 |
""" |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
214 |
done = set(done or []) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
215 |
while True: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
216 |
print intro |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
217 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
218 |
for i, entry in enumerate(choices): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
219 |
done_text = ' (done)' if i in done else '' |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
220 |
indent = '--> ' if i == suggest else ' ' |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
221 |
print '%s%2d. %s%s' % (indent, i+1, entry, done_text) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
222 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
223 |
choice = getNumber(prompt) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
224 |
if 0 < choice <= len(choices): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
225 |
return choice-1 |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
226 |
error('%d is not a valid choice between %d and %d' % |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
227 |
(choice, 1, len(choices))) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
228 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
229 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
230 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
231 |
def fileToLines(path): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
232 |
"""Read a file and return it as a list of lines.""" |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
233 |
try: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
234 |
with file(path) as f: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
235 |
return f.read().split('\n') |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
236 |
except (IOError, OSError), e: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
237 |
raise FileAccessError(str(e)) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
238 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
239 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
240 |
def linesToFile(path, lines): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
241 |
"""Write a list of lines to a file.""" |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
242 |
try: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
243 |
with file(path, 'w') as f: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
244 |
f.write('\n'.join(lines)) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
245 |
except (IOError, OSError), e: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
246 |
raise FileAccessError(str(e)) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
247 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
248 |
|
1825
a610a2df83d2
Move the Paths class to the util module.
David Anderson <david.jc.anderson@gmail.com>
parents:
1824
diff
changeset
|
249 |
class Subversion(util.Paths): |
1816
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
250 |
"""Wrapper for operations on a Subversion working copy. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
251 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
252 |
An instance of this class is bound to a specific working copy |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
253 |
directory, and provides an API to perform various Subversion |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
254 |
operations on this working copy. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
255 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
256 |
Some methods take a 'depth' argument. Depth in Subversion is a |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
257 |
feature that allows the creation of arbitrarily shallow or deep |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
258 |
working copies on a per-directory basis. Possible values are |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
259 |
'none' (no files or directories), 'files' (only files in .), |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
260 |
'immediates' (files and directories in ., directories checked out |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
261 |
at depth 'none') or 'infinity' (a normal working copy with |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
262 |
everything). |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
263 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
264 |
This class also provides a few static functions that run the 'svn' |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
265 |
tool against remote repositories to gather information or retrieve |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
266 |
data. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
267 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
268 |
Note that this wrapper also doubles as a Paths object, offering an |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
269 |
easy way to get or check the existence of paths in the working |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
270 |
copy. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
271 |
""" |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
272 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
273 |
def __init__(self, wc_dir): |
1826
12de6d73a908
Followup to r2496. Fix obvious errors.
David Anderson <david.jc.anderson@gmail.com>
parents:
1825
diff
changeset
|
274 |
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
|
275 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
276 |
def _unknownAndMissing(self, path): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
277 |
"""Returns lists of unknown and missing files in the working copy. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
278 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
279 |
Args: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
280 |
path: The working copy path to scan. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
281 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
282 |
Returns: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
283 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
284 |
Two lists. The first is a list of all unknown paths |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
285 |
(subversion has no knowledge of them), the second is a list |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
286 |
of missing paths (subversion knows about them, but can't |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
287 |
find them). Paths in either list are relative to the input |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
288 |
path. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
289 |
""" |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
290 |
assert self.exists() |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
291 |
unknown = [] |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
292 |
missing = [] |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
293 |
for line in self.status(path): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
294 |
if not line.strip(): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
295 |
continue |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
296 |
if line[0] == '?': |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
297 |
unknown.append(line[7:]) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
298 |
elif line[0] == '!': |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
299 |
missing.append(line[7:]) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
300 |
return unknown, missing |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
301 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
302 |
def checkout(self, url, depth='infinity'): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
303 |
"""Check out a working copy from the given URL. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
304 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
305 |
Args: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
306 |
url: The Subversion repository URL to check out. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
307 |
depth: The depth of the working copy root. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
308 |
""" |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
309 |
assert not self.exists() |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
310 |
run(['svn', 'checkout', '--depth=' + depth, url, self.path()]) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
311 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
312 |
def update(self, path='', depth=None): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
313 |
"""Update a working copy path, optionally changing depth. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
314 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
315 |
Args: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
316 |
path: The working copy path to update. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
317 |
depth: If set, change the depth of the path before updating. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
318 |
""" |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
319 |
assert self.exists() |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
320 |
if depth is None: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
321 |
run(['svn', 'update', self.path(path)]) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
322 |
else: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
323 |
run(['svn', 'update', '--set-depth=' + depth, self.path(path)]) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
324 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
325 |
def revert(self, path=''): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
326 |
"""Recursively revert a working copy path. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
327 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
328 |
Note that this command is more zealous than the 'svn revert' |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
329 |
command, as it will also delete any files which subversion |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
330 |
does not know about. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
331 |
""" |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
332 |
run(['svn', 'revert', '-R', self.path(path)]) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
333 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
334 |
unknown, missing = self._unknownAndMissing(path) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
335 |
unknown = [os.path.join(self.path(path), p) for p in unknown] |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
336 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
337 |
if unknown: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
338 |
# rm -rf makes me uneasy. Verify that all paths to be deleted |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
339 |
# are within the release working copy. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
340 |
for p in unknown: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
341 |
assert p.startswith(self.path()) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
342 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
343 |
run(['rm', '-rf', '--'] + unknown) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
344 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
345 |
def ls(self, dir=''): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
346 |
"""List the contents of a working copy directory. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
347 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
348 |
Note that this returns the contents of the directory as seen |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
349 |
by the server, not constrained by the depth settings of the |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
350 |
local path. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
351 |
""" |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
352 |
assert self.exists() |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
353 |
return run(['svn', 'ls', self.path(dir)], capture=True) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
354 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
355 |
def copy(self, src, dest): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
356 |
"""Copy a working copy path. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
357 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
358 |
The copy is only scheduled for commit, not committed. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
359 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
360 |
Args: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
361 |
src: The source working copy path. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
362 |
dst: The destination working copy path. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
363 |
""" |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
364 |
assert self.exists() |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
365 |
run(['svn', 'cp', self.path(src), self.path(dest)]) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
366 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
367 |
def propget(self, prop_name, path): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
368 |
"""Get the value of a property on a working copy path. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
369 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
370 |
Args: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
371 |
prop_name: The property name, eg. 'svn:externals'. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
372 |
path: The working copy path on which the property is set. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
373 |
""" |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
374 |
assert self.exists() |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
375 |
return run(['svn', 'propget', prop_name, self.path(path)], capture=True) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
376 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
377 |
def propset(self, prop_name, prop_value, path): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
378 |
"""Set the value of a property on a working copy path. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
379 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
380 |
The property change is only scheduled for commit, not committed. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
381 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
382 |
Args: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
383 |
prop_name: The property name, eg. 'svn:externals'. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
384 |
prop_value: The value that should be set. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
385 |
path: The working copy path on which to set the property. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
386 |
""" |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
387 |
assert self.exists() |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
388 |
run(['svn', 'propset', prop_name, prop_value, self.path(path)]) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
389 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
390 |
def add(self, paths): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
391 |
"""Schedule working copy paths for addition. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
392 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
393 |
The paths are only scheduled for addition, not committed. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
394 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
395 |
Args: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
396 |
paths: The list of working copy paths to add. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
397 |
""" |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
398 |
assert self.exists() |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
399 |
paths = [self.path(p) for p in paths] |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
400 |
run(['svn', 'add'] + paths) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
401 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
402 |
def remove(self, paths): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
403 |
"""Schedule working copy paths for deletion. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
404 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
405 |
The paths are only scheduled for deletion, not committed. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
406 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
407 |
Args: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
408 |
paths: The list of working copy paths to delete. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
409 |
""" |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
410 |
assert self.exists() |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
411 |
paths = [self.path(p) for p in paths] |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
412 |
run(['svn', 'rm'] + paths) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
413 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
414 |
def status(self, path=''): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
415 |
"""Return the status of a working copy path. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
416 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
417 |
The status returned is the verbatim output of 'svn status' on |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
418 |
the path. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
419 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
420 |
Args: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
421 |
path: The path to examine. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
422 |
""" |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
423 |
assert self.exists() |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
424 |
return run(['svn', 'status', self.path(path)], capture=True) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
425 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
426 |
def addRemove(self, path=''): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
427 |
"""Perform an "addremove" operation a working copy path. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
428 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
429 |
An "addremove" runs 'svn status' and schedules all the unknown |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
430 |
paths (listed as '?') for addition, and all the missing paths |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
431 |
(listed as '!') for deletion. Its main use is to synchronize |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
432 |
working copy state after applying a patch in unified diff |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
433 |
format. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
434 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
435 |
Args: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
436 |
path: The path under which unknown/missing files should be |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
437 |
added/removed. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
438 |
""" |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
439 |
assert self.exists() |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
440 |
unknown, missing = self._unknownAndMissing(path) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
441 |
if unknown: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
442 |
self.add(unknown) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
443 |
if missing: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
444 |
self.remove(missing) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
445 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
446 |
def commit(self, message, path=''): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
447 |
"""Commit scheduled changes to the source repository. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
448 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
449 |
Args: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
450 |
message: The commit message to use. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
451 |
path: The path to commit. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
452 |
""" |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
453 |
assert self.exists() |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
454 |
run(['svn', 'commit', '-m', message, self.path(path)]) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
455 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
456 |
@staticmethod |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
457 |
def export(url, revision, dest_path): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
458 |
"""Export the contents of a repository to a local path. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
459 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
460 |
Note that while the underlying 'svn export' only requires a |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
461 |
URL, we require that both a URL and a revision be specified, |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
462 |
to fully qualify the data to export. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
463 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
464 |
Args: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
465 |
url: The repository URL to export. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
466 |
revision: The revision to export. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
467 |
dest_path: The destination directory for the export. Note |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
468 |
that this is an absolute path, NOT a working copy |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
469 |
relative path. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
470 |
""" |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
471 |
assert os.path.isabs(dest_path) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
472 |
if os.path.exists(dest_path): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
473 |
raise ObstructionError('Cannot export to obstructed path %s' % |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
474 |
dest_path) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
475 |
run(['svn', 'export', '-r', str(revision), url, dest_path]) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
476 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
477 |
@staticmethod |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
478 |
def find_tag_rev(url): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
479 |
"""Return the revision at which a remote tag was created. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
480 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
481 |
Since tags are immutable by convention, usually the HEAD of a |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
482 |
tag should be the tag creation revision. However, mistakes can |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
483 |
happen, so this function will walk the history of the given |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
484 |
tag URL, stopping on the first revision that was created by |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
485 |
copy. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
486 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
487 |
This detection is not foolproof. For example: it will be |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
488 |
fooled by a tag that was created, deleted, and recreated by |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
489 |
copy at a different revision. It is not clear what the desired |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
490 |
behavior in these edge cases are, and no attempt is made to |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
491 |
handle them. You should request user confirmation before using |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
492 |
the result of this function. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
493 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
494 |
Args: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
495 |
url: The repository URL of the tag to examine. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
496 |
""" |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
497 |
try: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
498 |
output = run(['svn', 'log', '-q', '--stop-on-copy', url], |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
499 |
capture=True) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
500 |
except SubprocessFailed: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
501 |
raise ExpectationFailed('No tag at URL ' + url) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
502 |
first_rev_line = output[-2] |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
503 |
first_rev = int(first_rev_line.split()[0][1:]) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
504 |
return first_rev |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
505 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
506 |
@staticmethod |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
507 |
def diff(url, revision): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
508 |
"""Retrieve a revision from a remote repository as a unified diff. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
509 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
510 |
Args: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
511 |
url: The repository URL on which to perform the diff. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
512 |
revision: The revision to extract at the given url. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
513 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
514 |
Returns: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
515 |
A string containing the changes extracted from the remote |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
516 |
repository, in unified diff format suitable for application |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
517 |
using 'patch'. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
518 |
""" |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
519 |
try: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
520 |
return run(['svn', 'diff', '-c', str(revision), url], |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
521 |
capture=True, split_capture=False) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
522 |
except SubprocessFailed: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
523 |
raise ExpectationFailed('Could not get diff for r%d ' |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
524 |
'from remote repository' % revision) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
525 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
526 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
527 |
# |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
528 |
# 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
|
529 |
# |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
530 |
def pristine_wc(f): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
531 |
"""A decorator that cleans up the release repository.""" |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
532 |
@functools.wraps(f) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
533 |
def revert_wc(self, *args, **kwargs): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
534 |
self.wc.revert() |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
535 |
return f(self, *args, **kwargs) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
536 |
return revert_wc |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
537 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
538 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
539 |
def requires_branch(f): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
540 |
"""A decorator that checks that a release branch is active.""" |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
541 |
@functools.wraps(f) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
542 |
def check_branch(self, *args, **kwargs): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
543 |
if self.branch is None: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
544 |
raise ExpectationFailed( |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
545 |
'This operation requires an active release branch') |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
546 |
return f(self, *args, **kwargs) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
547 |
return check_branch |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
548 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
549 |
|
1825
a610a2df83d2
Move the Paths class to the util module.
David Anderson <david.jc.anderson@gmail.com>
parents:
1824
diff
changeset
|
550 |
class ReleaseEnvironment(util.Paths): |
1816
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
551 |
"""Encapsulates the state of a Melange release rolling environment. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
552 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
553 |
This class contains the actual releasing logic, and makes use of |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
554 |
the previously defined utility classes to carry out user commands. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
555 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
556 |
Attributes: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
557 |
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
|
558 |
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
|
559 |
wc: A Subversion object encapsulating a Google SoC working copy. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
560 |
""" |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
561 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
562 |
BRANCH_FILE = 'BRANCH' |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
563 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
564 |
def __init__(self, root, release_repos, upstream_repos): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
565 |
"""Initializer. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
566 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
567 |
Args: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
568 |
root: The root of the release environment. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
569 |
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
|
570 |
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
|
571 |
""" |
1826
12de6d73a908
Followup to r2496. Fix obvious errors.
David Anderson <david.jc.anderson@gmail.com>
parents:
1825
diff
changeset
|
572 |
util.Paths.__init__(self, root) |
1816
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
573 |
self.wc = Subversion(self.path('google-soc')) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
574 |
self.release_repos = release_repos.strip('/') |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
575 |
self.upstream_repos = upstream_repos.strip('/') |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
576 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
577 |
if not self.wc.exists(): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
578 |
self._InitializeWC() |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
579 |
else: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
580 |
self.wc.revert() |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
581 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
582 |
if self.exists(self.BRANCH_FILE): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
583 |
branch = fileToLines(self.path(self.BRANCH_FILE))[0] |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
584 |
self._switchBranch(branch) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
585 |
else: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
586 |
self._switchBranch(None) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
587 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
588 |
def _InitializeWC(self): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
589 |
"""Check out the initial release repository. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
590 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
591 |
Will also select the latest release branch, if any, so that |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
592 |
the end state is a fully ready to function release |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
593 |
environment. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
594 |
""" |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
595 |
info('Checking out the release repository') |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
596 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
597 |
# Check out a sparse view of the relevant repository paths. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
598 |
self.wc.checkout(self.release_repos, depth='immediates') |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
599 |
self.wc.update('vendor', depth='immediates') |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
600 |
self.wc.update('branches', depth='immediates') |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
601 |
self.wc.update('tags', depth='immediates') |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
602 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
603 |
# Locate the most recent release branch, if any, and switch |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
604 |
# the release environment to it. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
605 |
branches = self._listBranches() |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
606 |
if not branches: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
607 |
self._switchBranch(None) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
608 |
else: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
609 |
self._switchBranch(branches[-1]) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
610 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
611 |
def _listBranches(self): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
612 |
"""Return a list of available Melange release branches. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
613 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
614 |
Branches are returned in sorted order, from least recent to |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
615 |
most recent in release number ordering. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
616 |
""" |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
617 |
assert self.wc.exists('branches') |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
618 |
branches = self.wc.ls('branches') |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
619 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
620 |
# Some early release branches used a different naming scheme |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
621 |
# that doesn't sort properly with new-style release names. We |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
622 |
# filter those out here, along with empty lines. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
623 |
branches = [b.strip('/') for b in branches |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
624 |
if MELANGE_RELEASE_RE.match(b.strip('/'))] |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
625 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
626 |
return sorted(branches) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
627 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
628 |
def _switchBranch(self, release): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
629 |
"""Activate the branch matching the given release. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
630 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
631 |
Once activated, this branch is the target of future release |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
632 |
operations. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
633 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
634 |
None can be passed as the release. The result is that no |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
635 |
branch is active, and all operations that require an active |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
636 |
branch will fail until a branch is activated again. This is |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
637 |
used only at initialization, when it is detected that there |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
638 |
are no available release branches to activate. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
639 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
640 |
Args: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
641 |
release: The version number of a Melange release already |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
642 |
imported in the release repository, or None to |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
643 |
activate no branch. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
644 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
645 |
""" |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
646 |
if release is None: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
647 |
self.branch = None |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
648 |
self.branch_dir = None |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
649 |
info('No release branch available') |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
650 |
else: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
651 |
self.wc.update() |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
652 |
assert self.wc.exists('branches/' + release) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
653 |
linesToFile(self.path(self.BRANCH_FILE), [release]) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
654 |
self.branch = release |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
655 |
self.branch_dir = 'branches/' + release |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
656 |
self.wc.update(self.branch_dir, depth='infinity') |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
657 |
info('Working on branch ' + self.branch) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
658 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
659 |
def _branchPath(self, path): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
660 |
"""Return the given path with the release branch path prepended.""" |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
661 |
assert self.branch_dir is not None |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
662 |
return os.path.join(self.branch_dir, path) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
663 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
664 |
# |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
665 |
# Release engineering commands. See further down for their |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
666 |
# integration into a commandline interface. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
667 |
# |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
668 |
@pristine_wc |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
669 |
def update(self): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
670 |
"""Update and clean the release repository""" |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
671 |
self.wc.update() |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
672 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
673 |
@pristine_wc |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
674 |
def switchToBranch(self): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
675 |
"""Switch to another Melange release branch""" |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
676 |
branches = self._listBranches() |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
677 |
if not branches: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
678 |
raise ExpectationFailed( |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
679 |
'No branches available. Please import one.') |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
680 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
681 |
choice = getChoice('Available release branches:', |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
682 |
'Your choice?', |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
683 |
branches, |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
684 |
suggest=len(branches)-1) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
685 |
self._switchBranch(branches[choice]) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
686 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
687 |
def _addAppYaml(self): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
688 |
"""Create a Google production app.yaml configuration. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
689 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
690 |
The file is copied and modified from the upstream |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
691 |
app.yaml.template, configure for Google's Summer of Code App |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
692 |
Engine instance, and committed. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
693 |
""" |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
694 |
if self.wc.exists(self._branchPath('app/app.yaml')): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
695 |
raise ObstructionError('app/app.yaml exists already') |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
696 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
697 |
yaml_path = self._branchPath('app/app.yaml') |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
698 |
self.wc.copy(yaml_path + '.template', yaml_path) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
699 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
700 |
yaml = fileToLines(self.wc.path(yaml_path)) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
701 |
out = [] |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
702 |
for i, line in enumerate(yaml): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
703 |
stripped_line = line.strip() |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
704 |
if 'TODO' in stripped_line: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
705 |
continue |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
706 |
elif stripped_line == '# application: FIXME': |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
707 |
out.append('application: socghop') |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
708 |
elif stripped_line.startswith('version:'): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
709 |
out.append(line.lstrip() + 'g0') |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
710 |
out.append('# * initial Google fork of Melange ' + |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
711 |
self.branch) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
712 |
else: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
713 |
out.append(line) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
714 |
linesToFile(self.wc.path(yaml_path), out) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
715 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
716 |
self.wc.commit('Create app.yaml with Google patch version g0 ' |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
717 |
'in branch ' + self.branch) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
718 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
719 |
def _applyGooglePatches(self): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
720 |
"""Apply Google-specific patches to a vanilla Melange release. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
721 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
722 |
Each patch is applied and committed in turn. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
723 |
""" |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
724 |
# Edit the base template to point users to the Google fork |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
725 |
# of the Melange codebase instead of the vanilla release. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
726 |
tmpl_file = self.wc.path( |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
727 |
self._branchPath('app/soc/templates/soc/base.html')) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
728 |
tmpl = fileToLines(tmpl_file) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
729 |
for i, line in enumerate(tmpl): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
730 |
if 'http://code.google.com/p/soc/source/browse/tags/' in line: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
731 |
tmpl[i] = line.replace('/p/soc/', '/p/soc-google/') |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
732 |
break |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
733 |
else: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
734 |
raise ExpectationFailed( |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
735 |
'No source code link found in base.html') |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
736 |
linesToFile(tmpl_file, tmpl) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
737 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
738 |
self.wc.commit( |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
739 |
'Customize the Melange release link in the sidebar menu') |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
740 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
741 |
@pristine_wc |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
742 |
def importTag(self): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
743 |
"""Import a new Melange release""" |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
744 |
release = getString('Enter the Melange release to import:') |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
745 |
if not release: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
746 |
AbortedByUser('No release provided, import aborted') |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
747 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
748 |
branch_dir = 'branches/' + release |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
749 |
if self.wc.exists(branch_dir): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
750 |
raise ObstructionError('Release %s already imported' % release) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
751 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
752 |
tag_url = '%s/tags/%s' % (self.upstream_repos, release) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
753 |
release_rev = Subversion.find_tag_rev(tag_url) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
754 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
755 |
if confirm('Confirm import of release %s, tagged at r%d?' % |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
756 |
(release, release_rev)): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
757 |
# Add an entry to the vendor externals for the Melange |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
758 |
# release. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
759 |
externals = self.wc.propget('svn:externals', 'vendor/soc') |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
760 |
externals.append('%s -r %d %s' % (release, release_rev, tag_url)) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
761 |
self.wc.propset('svn:externals', '\n'.join(externals), 'vendor/soc') |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
762 |
self.wc.commit('Add svn:externals entry to pull in Melange ' |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
763 |
'release %s at r%d.' % (release, release_rev)) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
764 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
765 |
# Export the tag into the release repository's branches |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
766 |
Subversion.export(tag_url, release_rev, self.wc.path(branch_dir)) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
767 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
768 |
# Add and commit the branch add (very long operation!) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
769 |
self.wc.add([branch_dir]) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
770 |
self.wc.commit('Branch of Melange release %s' % release, |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
771 |
branch_dir) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
772 |
self._switchBranch(release) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
773 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
774 |
# Commit the production GSoC configuration and |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
775 |
# google-specific patches. |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
776 |
self._addAppYaml() |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
777 |
self._applyGooglePatches() |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
778 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
779 |
# All done! |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
780 |
info('Melange release %s imported and googlified' % self.branch) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
781 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
782 |
@requires_branch |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
783 |
@pristine_wc |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
784 |
def cherryPickChange(self): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
785 |
"""Cherry-pick a change from the Melange trunk""" |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
786 |
rev = getNumber('Revision number to cherry-pick:') |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
787 |
bug = getNumber('Issue fixed by this change:') |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
788 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
789 |
diff = self.wc.diff(self.upstream_repos + '/trunk', rev) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
790 |
if not diff.strip(): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
791 |
raise ExpectationFailed( |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
792 |
'Retrieved diff is empty. ' |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
793 |
'Did you accidentally cherry-pick a branch change?') |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
794 |
run(['patch', '-p0'], cwd=self.wc.path(self.branch_dir), stdin=diff) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
795 |
self.wc.addRemove(self.branch_dir) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
796 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
797 |
yaml_path = self.wc.path(self._branchPath('app/app.yaml')) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
798 |
out = [] |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
799 |
updated_patchlevel = False |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
800 |
for line in fileToLines(yaml_path): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
801 |
if line.strip().startswith('version: '): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
802 |
version = line.strip().split()[-1] |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
803 |
base, patch = line.rsplit('g', 1) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
804 |
new_version = '%sg%d' % (base, int(patch) + 1) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
805 |
message = ('Cherry-picked r%d from /p/soc/ to fix issue %d' % |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
806 |
(rev, bug)) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
807 |
out.append('version: ' + new_version) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
808 |
out.append('# * ' + message) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
809 |
updated_patchlevel = True |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
810 |
else: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
811 |
out.append(line) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
812 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
813 |
if not updated_patchlevel: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
814 |
error('Failed to update Google patch revision') |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
815 |
error('Cherry-picking failed') |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
816 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
817 |
linesToFile(yaml_path, out) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
818 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
819 |
info('Check the diff about to be committed with:') |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
820 |
info('svn diff ' + self.wc.path(self.branch_dir)) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
821 |
if not confirm('Commit this change?'): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
822 |
raise AbortedByUser('Cherry-pick aborted') |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
823 |
self.wc.commit(message) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
824 |
info('Cherry-picked r%d from the Melange trunk.' % rev) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
825 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
826 |
MENU_ORDER = [ |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
827 |
update, |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
828 |
switchToBranch, |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
829 |
importTag, |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
830 |
cherryPickChange, |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
831 |
] |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
832 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
833 |
MENU_STRINGS = [d.__doc__ for d in MENU_ORDER] |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
834 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
835 |
MENU_SUGGESTIONS = { |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
836 |
None: update, |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
837 |
update: cherryPickChange, |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
838 |
switchToBranch: cherryPickChange, |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
839 |
importTag: cherryPickChange, |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
840 |
cherryPickChange: None, |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
841 |
} |
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 |
def interactiveMenu(self): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
844 |
done = [] |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
845 |
last_choice = None |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
846 |
while True: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
847 |
# Show the user their previously completed operations and |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
848 |
# a suggested next op, to remind them where they are in |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
849 |
# the release process (useful after long operations that |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
850 |
# may have caused lunch or an extended context switch). |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
851 |
if last_choice is not None: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
852 |
last_command = self.MENU_ORDER[last_choice] |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
853 |
else: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
854 |
last_command = None |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
855 |
suggested_next = self.MENU_ORDER.index( |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
856 |
self.MENU_SUGGESTIONS[last_command]) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
857 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
858 |
try: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
859 |
choice = getChoice('Main menu:', 'Your choice?', |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
860 |
self.MENU_STRINGS, done=done, |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
861 |
suggest=suggested_next) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
862 |
except (KeyboardInterrupt, AbortedByUser): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
863 |
info('Exiting.') |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
864 |
return |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
865 |
try: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
866 |
self.MENU_ORDER[choice](self) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
867 |
except Error, e: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
868 |
error(str(e)) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
869 |
else: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
870 |
done.append(choice) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
871 |
last_choice = choice |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
872 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
873 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
874 |
def main(argv): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
875 |
if not (1 <= len(argv) <= 3): |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
876 |
print ('Usage: gsoc-release.py [release repos root URL] ' |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
877 |
'[upstream repos root URL]') |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
878 |
sys.exit(1) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
879 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
880 |
release_repos, upstream_repos = GOOGLE_SOC_REPOS, MELANGE_REPOS |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
881 |
if len(argv) >= 2: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
882 |
release_repos = argv[1] |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
883 |
if len(argv) == 3: |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
884 |
upstream_repos = argv[2] |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
885 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
886 |
info('Release repository: ' + release_repos) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
887 |
info('Upstream repository: ' + upstream_repos) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
888 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
889 |
r = ReleaseEnvironment(os.path.abspath('_release_'), |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
890 |
release_repos, |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
891 |
upstream_repos) |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
892 |
r.interactiveMenu() |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
893 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
894 |
|
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
895 |
if __name__ == '__main__': |
07743b5295d3
Add the Google SoC release script to the Melange repository.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff
changeset
|
896 |
main(sys.argv) |