author | Sverre Rabbelier <srabbelier@gmail.com> |
Sun, 01 Mar 2009 15:33:52 +0000 | |
changeset 1578 | 0ffb9a3dfbdf |
parent 146 | 1849dc2e4638 |
permissions | -rwxr-xr-x |
145
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/python |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
2 |
# Wrapper script around Rietveld's upload.py that groups files into |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
3 |
# changelists. |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
4 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
5 |
import getpass |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
6 |
import linecache |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
7 |
import os |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
8 |
import random |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
9 |
import re |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
10 |
import string |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
11 |
import subprocess |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
12 |
import sys |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
13 |
import tempfile |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
14 |
import upload |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
15 |
import urllib2 |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
16 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
17 |
CODEREVIEW_SETTINGS = { |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
18 |
# Default values. |
146
1849dc2e4638
gcl.py customized to work with codereviews.googleopensourceprograms.com and the
Todd Larsen <tlarsen@google.com>
parents:
145
diff
changeset
|
19 |
"CODE_REVIEW_SERVER": "codereviews.googleopensourceprograms.com", |
1849dc2e4638
gcl.py customized to work with codereviews.googleopensourceprograms.com and the
Todd Larsen <tlarsen@google.com>
parents:
145
diff
changeset
|
20 |
"CC_LIST": "melange-soc-dev@googlegroups.com", |
1849dc2e4638
gcl.py customized to work with codereviews.googleopensourceprograms.com and the
Todd Larsen <tlarsen@google.com>
parents:
145
diff
changeset
|
21 |
"VIEW_VC": "http://code.google.com/p/soc/source/detail?r=", |
145
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
22 |
} |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
23 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
24 |
# Use a shell for subcommands on Windows to get a PATH search, and because svn |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
25 |
# may be a batch file. |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
26 |
use_shell = sys.platform.startswith("win") |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
27 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
28 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
29 |
# globals that store the root of the current repositary and the directory where |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
30 |
# we store information about changelists. |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
31 |
repository_root = "" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
32 |
gcl_info_dir = "" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
33 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
34 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
35 |
def GetSVNFileInfo(file, field): |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
36 |
"""Returns a field from the svn info output for the given file.""" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
37 |
output = RunShell(["svn", "info", file]) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
38 |
for line in output.splitlines(): |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
39 |
search = field + ": " |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
40 |
if line.startswith(search): |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
41 |
return line[len(search):] |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
42 |
return "" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
43 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
44 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
45 |
def GetRepositoryRoot(): |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
46 |
"""Returns the top level directory of the current repository.""" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
47 |
global repository_root |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
48 |
if not repository_root: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
49 |
cur_dir_repo_root = GetSVNFileInfo(os.getcwd(), "Repository Root") |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
50 |
if not cur_dir_repo_root: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
51 |
ErrorExit("gcl run outside of repository") |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
52 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
53 |
repository_root = os.getcwd() |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
54 |
while True: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
55 |
parent = os.path.dirname(repository_root) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
56 |
if GetSVNFileInfo(parent, "Repository Root") != cur_dir_repo_root: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
57 |
break |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
58 |
repository_root = parent |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
59 |
# Now read the code review settings for this repository. |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
60 |
settings_file = os.path.join(repository_root, "codereview.settings") |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
61 |
if os.path.exists(settings_file): |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
62 |
output = ReadFile(settings_file) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
63 |
for line in output.splitlines(): |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
64 |
if not line or line.startswith("#"): |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
65 |
continue |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
66 |
key, value = line.split(": ", 1) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
67 |
CODEREVIEW_SETTINGS[key] = value |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
68 |
return repository_root |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
69 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
70 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
71 |
def GetCodeReviewSetting(key): |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
72 |
"""Returns a value for the given key for this repository.""" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
73 |
return CODEREVIEW_SETTINGS.get(key, "") |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
74 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
75 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
76 |
def GetInfoDir(): |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
77 |
"""Returns the directory where gcl info files are stored.""" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
78 |
global gcl_info_dir |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
79 |
if not gcl_info_dir: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
80 |
gcl_info_dir = os.path.join(GetRepositoryRoot(), '.svn', 'gcl_info') |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
81 |
return gcl_info_dir |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
82 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
83 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
84 |
def ErrorExit(msg): |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
85 |
"""Print an error message to stderr and exit.""" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
86 |
print >>sys.stderr, msg |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
87 |
sys.exit(1) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
88 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
89 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
90 |
def RunShell(command, print_output=False): |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
91 |
"""Executes a command and returns the output.""" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
92 |
p = subprocess.Popen(command, stdout = subprocess.PIPE, |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
93 |
stderr = subprocess.STDOUT, shell = use_shell, |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
94 |
universal_newlines=True) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
95 |
if print_output: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
96 |
output_array = [] |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
97 |
while True: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
98 |
line = p.stdout.readline() |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
99 |
if not line: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
100 |
break |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
101 |
if print_output: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
102 |
print line.strip('\n') |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
103 |
output_array.append(line) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
104 |
output = "".join(output_array) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
105 |
else: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
106 |
output = p.stdout.read() |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
107 |
p.wait() |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
108 |
p.stdout.close() |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
109 |
return output |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
110 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
111 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
112 |
def ReadFile(filename): |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
113 |
"""Returns the contents of a file.""" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
114 |
file = open(filename, 'r') |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
115 |
result = file.read() |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
116 |
file.close() |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
117 |
return result |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
118 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
119 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
120 |
def WriteFile(filename, contents): |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
121 |
"""Overwrites the file with the given contents.""" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
122 |
file = open(filename, 'w') |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
123 |
file.write(contents) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
124 |
file.close() |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
125 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
126 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
127 |
class ChangeInfo: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
128 |
"""Holds information about a changelist. |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
129 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
130 |
issue: the Rietveld issue number, of "" if it hasn't been uploaded yet. |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
131 |
description: the description. |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
132 |
files: a list of 2 tuple containing (status, filename) of changed files, |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
133 |
with paths being relative to the top repository directory. |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
134 |
""" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
135 |
def __init__(self, name="", issue="", description="", files=[]): |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
136 |
self.name = name |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
137 |
self.issue = issue |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
138 |
self.description = description |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
139 |
self.files = files |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
140 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
141 |
def FileList(self): |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
142 |
"""Returns a list of files.""" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
143 |
return [file[1] for file in self.files] |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
144 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
145 |
def Save(self): |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
146 |
"""Writes the changelist information to disk.""" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
147 |
data = SEPARATOR.join([self.issue, |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
148 |
"\n".join([f[0] + f[1] for f in self.files]), |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
149 |
self.description]) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
150 |
WriteFile(GetChangelistInfoFile(self.name), data) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
151 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
152 |
def Delete(self): |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
153 |
"""Removes the changelist information from disk.""" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
154 |
os.remove(GetChangelistInfoFile(self.name)) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
155 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
156 |
def CloseIssue(self): |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
157 |
"""Closes the Rietveld issue for this changelist.""" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
158 |
data = [("description", self.description),] |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
159 |
ctype, body = upload.EncodeMultipartFormData(data, []) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
160 |
SendToRietveld("/" + self.issue + "/close", body, ctype) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
161 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
162 |
def UpdateRietveldDescription(self): |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
163 |
"""Sets the description for an issue on Rietveld.""" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
164 |
data = [("description", self.description),] |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
165 |
ctype, body = upload.EncodeMultipartFormData(data, []) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
166 |
SendToRietveld("/" + self.issue + "/description", body, ctype) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
167 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
168 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
169 |
SEPARATOR = "\n-----\n" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
170 |
# The info files have the following format: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
171 |
# issue_id\n |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
172 |
# SEPARATOR\n |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
173 |
# filepath1\n |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
174 |
# filepath2\n |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
175 |
# . |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
176 |
# . |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
177 |
# filepathn\n |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
178 |
# SEPARATOR\n |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
179 |
# description |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
180 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
181 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
182 |
def GetChangelistInfoFile(changename): |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
183 |
"""Returns the file that stores information about a changelist.""" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
184 |
if not changename or re.search(r'\W', changename): |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
185 |
ErrorExit("Invalid changelist name: " + changename) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
186 |
return os.path.join(GetInfoDir(), changename) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
187 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
188 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
189 |
def LoadChangelistInfo(changename, fail_on_not_found=True, |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
190 |
update_status=False): |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
191 |
"""Gets information about a changelist. |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
192 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
193 |
Args: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
194 |
fail_on_not_found: if True, this function will quit the program if the |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
195 |
changelist doesn't exist. |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
196 |
update_status: if True, the svn status will be updated for all the files |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
197 |
and unchanged files will be removed. |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
198 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
199 |
Returns: a ChangeInfo object. |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
200 |
""" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
201 |
info_file = GetChangelistInfoFile(changename) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
202 |
if not os.path.exists(info_file): |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
203 |
if fail_on_not_found: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
204 |
ErrorExit("Changelist " + changename + " not found.") |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
205 |
return ChangeInfo(changename) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
206 |
data = ReadFile(info_file) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
207 |
split_data = data.split(SEPARATOR, 2) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
208 |
if len(split_data) != 3: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
209 |
os.remove(info_file) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
210 |
ErrorExit("Changelist file %s was corrupt and deleted" % info_file) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
211 |
issue = split_data[0] |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
212 |
files = [] |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
213 |
for line in split_data[1].splitlines(): |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
214 |
status = line[:7] |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
215 |
file = line[7:] |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
216 |
files.append((status, file)) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
217 |
description = split_data[2] |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
218 |
save = False |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
219 |
if update_status: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
220 |
for file in files: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
221 |
filename = os.path.join(GetRepositoryRoot(), file[1]) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
222 |
status = RunShell(["svn", "status", filename])[:7] |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
223 |
if not status: # File has been reverted. |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
224 |
save = True |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
225 |
files.remove(file) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
226 |
elif status != file[0]: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
227 |
save = True |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
228 |
files[files.index(file)] = (status, file[1]) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
229 |
change_info = ChangeInfo(changename, issue, description, files) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
230 |
if save: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
231 |
change_info.Save() |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
232 |
return change_info |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
233 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
234 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
235 |
def GetCLs(): |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
236 |
"""Returns a list of all the changelists in this repository.""" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
237 |
return os.listdir(GetInfoDir()) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
238 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
239 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
240 |
def GenerateChangeName(): |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
241 |
"""Generate a random changelist name.""" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
242 |
random.seed() |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
243 |
current_cl_names = GetCLs() |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
244 |
while True: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
245 |
cl_name = (random.choice(string.ascii_lowercase) + |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
246 |
random.choice(string.digits) + |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
247 |
random.choice(string.ascii_lowercase) + |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
248 |
random.choice(string.digits)) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
249 |
if cl_name not in current_cl_names: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
250 |
return cl_name |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
251 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
252 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
253 |
def GetModifiedFiles(): |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
254 |
"""Returns a set that maps from changelist name to (status,filename) tuples. |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
255 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
256 |
Files not in a changelist have an empty changelist name. Filenames are in |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
257 |
relation to the top level directory of the current repositary. Note that |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
258 |
only the current directory and subdirectories are scanned, in order to |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
259 |
improve performance while still being flexible. |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
260 |
""" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
261 |
files = {} |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
262 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
263 |
# Since the files are normalized to the root folder of the repositary, figure |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
264 |
# out what we need to add to the paths. |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
265 |
dir_prefix = os.getcwd()[len(GetRepositoryRoot()):].strip(os.sep) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
266 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
267 |
# Get a list of all files in changelists. |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
268 |
files_in_cl = {} |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
269 |
for cl in GetCLs(): |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
270 |
change_info = LoadChangelistInfo(cl) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
271 |
for status, filename in change_info.files: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
272 |
files_in_cl[filename] = change_info.name |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
273 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
274 |
# Get all the modified files. |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
275 |
status = RunShell(["svn", "status"]) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
276 |
for line in status.splitlines(): |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
277 |
if not len(line) or line[0] == "?": |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
278 |
continue |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
279 |
status = line[:7] |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
280 |
filename = line[7:] |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
281 |
if dir_prefix: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
282 |
filename = os.path.join(dir_prefix, filename) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
283 |
change_list_name = "" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
284 |
if filename in files_in_cl: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
285 |
change_list_name = files_in_cl[filename] |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
286 |
files.setdefault(change_list_name, []).append((status, filename)) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
287 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
288 |
return files |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
289 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
290 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
291 |
def GetFilesNotInCL(): |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
292 |
"""Returns a list of tuples (status,filename) that aren't in any changelists. |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
293 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
294 |
See docstring of GetModifiedFiles for information about path of files and |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
295 |
which directories are scanned. |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
296 |
""" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
297 |
modified_files = GetModifiedFiles() |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
298 |
if "" not in modified_files: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
299 |
return [] |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
300 |
return modified_files[""] |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
301 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
302 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
303 |
def SendToRietveld(request_path, payload=None, |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
304 |
content_type="application/octet-stream"): |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
305 |
"""Send a POST/GET to Rietveld. Returns the response body.""" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
306 |
def GetUserCredentials(): |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
307 |
"""Prompts the user for a username and password.""" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
308 |
email = raw_input("Email: ").strip() |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
309 |
password = getpass.getpass("Password for %s: " % email) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
310 |
return email, password |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
311 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
312 |
server = GetCodeReviewSetting("CODE_REVIEW_SERVER") |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
313 |
rpc_server = upload.HttpRpcServer(server, |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
314 |
GetUserCredentials, |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
315 |
host_override=server, |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
316 |
save_cookies=True) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
317 |
return rpc_server.Send(request_path, payload, content_type) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
318 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
319 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
320 |
def GetIssueDescription(issue): |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
321 |
"""Returns the issue description from Rietveld.""" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
322 |
return SendToRietveld("/" + issue + "/description") |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
323 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
324 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
325 |
def UnknownFiles(extra_args): |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
326 |
"""Runs svn status and prints unknown files. |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
327 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
328 |
Any args in |extra_args| are passed to the tool to support giving alternate |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
329 |
code locations. |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
330 |
""" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
331 |
args = ["svn", "status"] |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
332 |
args += extra_args |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
333 |
p = subprocess.Popen(args, stdout = subprocess.PIPE, |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
334 |
stderr = subprocess.STDOUT, shell = use_shell) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
335 |
while 1: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
336 |
line = p.stdout.readline() |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
337 |
if not line: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
338 |
break |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
339 |
if line[0] != '?': |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
340 |
continue # Not an unknown file to svn. |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
341 |
# The lines look like this: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
342 |
# "? foo.txt" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
343 |
# and we want just "foo.txt" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
344 |
print line[7:].strip() |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
345 |
p.wait() |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
346 |
p.stdout.close() |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
347 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
348 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
349 |
def Opened(): |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
350 |
"""Prints a list of modified files in the current directory down.""" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
351 |
files = GetModifiedFiles() |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
352 |
cl_keys = files.keys() |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
353 |
cl_keys.sort() |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
354 |
for cl_name in cl_keys: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
355 |
if cl_name: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
356 |
note = "" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
357 |
if len(LoadChangelistInfo(cl_name).files) != len(files[cl_name]): |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
358 |
note = " (Note: this changelist contains files outside this directory)" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
359 |
print "\n--- Changelist " + cl_name + note + ":" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
360 |
for file in files[cl_name]: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
361 |
print "".join(file) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
362 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
363 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
364 |
def Help(): |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
365 |
print ("GCL is a wrapper for Subversion that simplifies working with groups " |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
366 |
"of files.\n") |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
367 |
print "Basic commands:" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
368 |
print "-----------------------------------------" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
369 |
print " gcl change change_name" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
370 |
print (" Add/remove files to a changelist. Only scans the current " |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
371 |
"directory and subdirectories.\n") |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
372 |
print (" gcl upload change_name [-r reviewer1@gmail.com," |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
373 |
"reviewer2@gmail.com,...] [--send_mail]") |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
374 |
print " Uploads the changelist to the server for review.\n" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
375 |
print " gcl commit change_name" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
376 |
print " Commits the changelist to the repository.\n" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
377 |
print "Advanced commands:" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
378 |
print "-----------------------------------------" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
379 |
print " gcl delete change_name" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
380 |
print " Deletes a changelist.\n" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
381 |
print " gcl diff change_name" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
382 |
print " Diffs all files in the changelist.\n" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
383 |
print " gcl diff" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
384 |
print (" Diffs all files in the current directory and subdirectories " |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
385 |
"that aren't in a changelist.\n") |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
386 |
print " gcl changes" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
387 |
print " Lists all the the changelists and the files in them.\n" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
388 |
print " gcl nothave [optional directory]" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
389 |
print " Lists files unknown to Subversion.\n" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
390 |
print " gcl opened" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
391 |
print (" Lists modified files in the current directory and " |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
392 |
"subdirectories.\n") |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
393 |
print " gcl try change_name" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
394 |
print (" Sends the change to the tryserver so a trybot can do a test" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
395 |
" run on your code.\n") |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
396 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
397 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
398 |
def GetEditor(): |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
399 |
editor = os.environ.get("SVN_EDITOR") |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
400 |
if not editor: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
401 |
editor = os.environ.get("EDITOR") |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
402 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
403 |
if not editor: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
404 |
if sys.platform.startswith("win"): |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
405 |
editor = "notepad" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
406 |
else: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
407 |
editor = "vi" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
408 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
409 |
return editor |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
410 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
411 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
412 |
def GenerateDiff(files): |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
413 |
"""Returns a string containing the diff for the given file list.""" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
414 |
diff = [] |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
415 |
for file in files: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
416 |
# Use svn info output instead of os.path.isdir because the latter fails |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
417 |
# when the file is deleted. |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
418 |
if GetSVNFileInfo(file, "Node Kind") == "directory": |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
419 |
continue |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
420 |
# If the user specified a custom diff command in their svn config file, |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
421 |
# then it'll be used when we do svn diff, which we don't want to happen |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
422 |
# since we want the unified diff. Using --diff-cmd=diff doesn't always |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
423 |
# work, since they can have another diff executable in their path that |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
424 |
# gives different line endings. So we use a bogus temp directory as the |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
425 |
# config directory, which gets around these problems. |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
426 |
if sys.platform.startswith("win"): |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
427 |
parent_dir = tempfile.gettempdir() |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
428 |
else: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
429 |
parent_dir = sys.path[0] # tempdir is not secure. |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
430 |
bogus_dir = os.path.join(parent_dir, "temp_svn_config") |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
431 |
if not os.path.exists(bogus_dir): |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
432 |
os.mkdir(bogus_dir) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
433 |
diff.append(RunShell(["svn", "diff", "--config-dir", bogus_dir, file])) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
434 |
return "".join(diff) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
435 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
436 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
437 |
def UploadCL(change_info, args): |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
438 |
if not change_info.FileList(): |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
439 |
print "Nothing to upload, changelist is empty." |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
440 |
return |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
441 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
442 |
upload_arg = ["upload.py", "-y", "-l"] |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
443 |
upload_arg.append("--server=" + GetCodeReviewSetting("CODE_REVIEW_SERVER")) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
444 |
upload_arg.extend(args) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
445 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
446 |
desc_file = "" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
447 |
if change_info.issue: # Uploading a new patchset. |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
448 |
upload_arg.append("--message=''") |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
449 |
upload_arg.append("--issue=" + change_info.issue) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
450 |
else: # First time we upload. |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
451 |
handle, desc_file = tempfile.mkstemp(text=True) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
452 |
os.write(handle, change_info.description) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
453 |
os.close(handle) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
454 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
455 |
upload_arg.append("--cc=" + GetCodeReviewSetting("CC_LIST")) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
456 |
upload_arg.append("--description_file=" + desc_file + "") |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
457 |
if change_info.description: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
458 |
subject = change_info.description[:77] |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
459 |
if subject.find("\r\n") != -1: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
460 |
subject = subject[:subject.find("\r\n")] |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
461 |
if subject.find("\n") != -1: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
462 |
subject = subject[:subject.find("\n")] |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
463 |
if len(change_info.description) > 77: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
464 |
subject = subject + "..." |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
465 |
upload_arg.append("--message=" + subject) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
466 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
467 |
# Change the current working directory before calling upload.py so that it |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
468 |
# shows the correct base. |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
469 |
os.chdir(GetRepositoryRoot()) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
470 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
471 |
# If we have a lot of files with long paths, then we won't be able to fit |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
472 |
# the command to "svn diff". Instead, we generate the diff manually for |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
473 |
# each file and concatenate them before passing it to upload.py. |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
474 |
issue = upload.RealMain(upload_arg, GenerateDiff(change_info.FileList())) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
475 |
if issue and issue != change_info.issue: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
476 |
change_info.issue = issue |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
477 |
change_info.Save() |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
478 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
479 |
if desc_file: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
480 |
os.remove(desc_file) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
481 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
482 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
483 |
def TryChange(change_info, args): |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
484 |
"""Create a diff file of change_info and send it to the try server.""" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
485 |
try: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
486 |
import trychange |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
487 |
except ImportError: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
488 |
ErrorExit("You need to install trychange.py to use the try server.") |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
489 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
490 |
trychange.TryChange(args, change_info.name, change_info.FileList()) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
491 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
492 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
493 |
def Commit(change_info): |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
494 |
if not change_info.FileList(): |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
495 |
print "Nothing to commit, changelist is empty." |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
496 |
return |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
497 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
498 |
commit_cmd = ["svn", "commit"] |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
499 |
filename = '' |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
500 |
if change_info.issue: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
501 |
# Get the latest description from Rietveld. |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
502 |
change_info.description = GetIssueDescription(change_info.issue) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
503 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
504 |
commit_message = change_info.description.replace('\r\n', '\n') |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
505 |
if change_info.issue: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
506 |
commit_message += ('\nReview URL: http://%s/%s' % |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
507 |
(GetCodeReviewSetting("CODE_REVIEW_SERVER"), |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
508 |
change_info.issue)) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
509 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
510 |
handle, commit_filename = tempfile.mkstemp(text=True) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
511 |
os.write(handle, commit_message) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
512 |
os.close(handle) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
513 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
514 |
handle, targets_filename = tempfile.mkstemp(text=True) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
515 |
os.write(handle, "\n".join(change_info.FileList())) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
516 |
os.close(handle) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
517 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
518 |
commit_cmd += ['--file=' + commit_filename] |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
519 |
commit_cmd += ['--targets=' + targets_filename] |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
520 |
# Change the current working directory before calling commit. |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
521 |
os.chdir(GetRepositoryRoot()) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
522 |
output = RunShell(commit_cmd, True) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
523 |
os.remove(commit_filename) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
524 |
os.remove(targets_filename) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
525 |
if output.find("Committed revision") != -1: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
526 |
change_info.Delete() |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
527 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
528 |
if change_info.issue: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
529 |
revision = re.compile(".*?\nCommitted revision (\d+)", |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
530 |
re.DOTALL).match(output).group(1) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
531 |
viewvc_url = GetCodeReviewSetting("VIEW_VC") |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
532 |
change_info.description = (change_info.description + |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
533 |
"\n\nCommitted: " + viewvc_url + revision) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
534 |
change_info.CloseIssue() |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
535 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
536 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
537 |
def Change(change_info): |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
538 |
"""Creates/edits a changelist.""" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
539 |
if change_info.issue: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
540 |
try: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
541 |
description = GetIssueDescription(change_info.issue) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
542 |
except urllib2.HTTPError, err: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
543 |
if err.code == 404: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
544 |
# The user deleted the issue in Rietveld, so forget the old issue id. |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
545 |
description = change_info.description |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
546 |
change_info.issue = "" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
547 |
change_info.Save() |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
548 |
else: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
549 |
ErrorExit("Error getting the description from Rietveld: " + err) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
550 |
else: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
551 |
description = change_info.description |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
552 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
553 |
other_files = GetFilesNotInCL() |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
554 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
555 |
separator1 = ("\n---All lines above this line become the description.\n" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
556 |
"---Repository Root: " + GetRepositoryRoot() + "\n" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
557 |
"---Paths in this changelist (" + change_info.name + "):\n") |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
558 |
separator2 = "\n\n---Paths modified but not in any changelist:\n\n" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
559 |
text = (description + separator1 + '\n' + |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
560 |
'\n'.join([f[0] + f[1] for f in change_info.files]) + separator2 + |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
561 |
'\n'.join([f[0] + f[1] for f in other_files]) + '\n') |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
562 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
563 |
handle, filename = tempfile.mkstemp(text=True) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
564 |
os.write(handle, text) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
565 |
os.close(handle) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
566 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
567 |
command = GetEditor() + " " + filename |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
568 |
os.system(command) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
569 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
570 |
result = ReadFile(filename) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
571 |
os.remove(filename) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
572 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
573 |
if not result: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
574 |
return |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
575 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
576 |
split_result = result.split(separator1, 1) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
577 |
if len(split_result) != 2: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
578 |
ErrorExit("Don't modify the text starting with ---!\n\n" + result) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
579 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
580 |
new_description = split_result[0] |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
581 |
cl_files_text = split_result[1] |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
582 |
if new_description != description: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
583 |
change_info.description = new_description |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
584 |
if change_info.issue: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
585 |
# Update the Rietveld issue with the new description. |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
586 |
change_info.UpdateRietveldDescription() |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
587 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
588 |
new_cl_files = [] |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
589 |
for line in cl_files_text.splitlines(): |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
590 |
if not len(line): |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
591 |
continue |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
592 |
if line.startswith("---"): |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
593 |
break |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
594 |
status = line[:7] |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
595 |
file = line[7:] |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
596 |
new_cl_files.append((status, file)) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
597 |
change_info.files = new_cl_files |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
598 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
599 |
change_info.Save() |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
600 |
print change_info.name + " changelist saved." |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
601 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
602 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
603 |
def Changes(): |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
604 |
"""Print all the changlists and their files.""" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
605 |
for cl in GetCLs(): |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
606 |
change_info = LoadChangelistInfo(cl, True, True) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
607 |
print "\n--- Changelist " + change_info.name + ":" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
608 |
for file in change_info.files: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
609 |
print "".join(file) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
610 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
611 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
612 |
def main(argv=None): |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
613 |
if argv is None: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
614 |
argv = sys.argv |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
615 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
616 |
if len(argv) == 1: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
617 |
Help() |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
618 |
return 0; |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
619 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
620 |
# Create the directory where we store information about changelists if it |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
621 |
# doesn't exist. |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
622 |
if not os.path.exists(GetInfoDir()): |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
623 |
os.mkdir(GetInfoDir()) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
624 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
625 |
command = argv[1] |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
626 |
if command == "opened": |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
627 |
Opened() |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
628 |
return 0 |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
629 |
if command == "nothave": |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
630 |
UnknownFiles(argv[2:]) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
631 |
return 0 |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
632 |
if command == "changes": |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
633 |
Changes() |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
634 |
return 0 |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
635 |
if command == "diff" and len(argv) == 2: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
636 |
files = GetFilesNotInCL() |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
637 |
print GenerateDiff([os.path.join(GetRepositoryRoot(), x[1]) for x in files]) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
638 |
return 0 |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
639 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
640 |
if len(argv) == 2: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
641 |
if command == "change": |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
642 |
# Generate a random changelist name. |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
643 |
changename = GenerateChangeName() |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
644 |
elif command == "help": |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
645 |
Help() |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
646 |
return 0 |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
647 |
else: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
648 |
ErrorExit("Need a changelist name.") |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
649 |
else: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
650 |
changename = argv[2] |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
651 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
652 |
fail_on_not_found = command != "change" |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
653 |
change_info = LoadChangelistInfo(changename, fail_on_not_found, True) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
654 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
655 |
if command == "change": |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
656 |
Change(change_info) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
657 |
elif command == "upload": |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
658 |
UploadCL(change_info, argv[3:]) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
659 |
elif command == "commit": |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
660 |
Commit(change_info) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
661 |
elif command == "delete": |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
662 |
change_info.Delete() |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
663 |
elif command == "try": |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
664 |
TryChange(change_info, argv[3:]) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
665 |
else: |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
666 |
# Everything else that is passed into gcl we redirect to svn, after adding |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
667 |
# the files. This allows commands such as 'gcl diff xxx' to work. |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
668 |
args =["svn", command] |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
669 |
root = GetRepositoryRoot() |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
670 |
args.extend([os.path.join(root, x) for x in change_info.FileList()]) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
671 |
RunShell(args, True) |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
672 |
return 0 |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
673 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
674 |
|
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
675 |
if __name__ == "__main__": |
9626a42a225b
Pristine initial commit of gcl.py script from chromium.org.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
676 |
sys.exit(main()) |