Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(859)

Side by Side Diff: tools/push-to-trunk/auto_roll.py

Issue 173983002: Refactoring: Redesign option parsing in push and merge scripts. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tools/push-to-trunk/common_includes.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2013 the V8 project authors. All rights reserved. 2 # Copyright 2013 the V8 project authors. All rights reserved.
3 # Redistribution and use in source and binary forms, with or without 3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are 4 # modification, are permitted provided that the following conditions are
5 # met: 5 # met:
6 # 6 #
7 # * Redistributions of source code must retain the above copyright 7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer. 8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above 9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following 10 # copyright notice, this list of conditions and the following
11 # disclaimer in the documentation and/or other materials provided 11 # disclaimer in the documentation and/or other materials provided
12 # with the distribution. 12 # with the distribution.
13 # * Neither the name of Google Inc. nor the names of its 13 # * Neither the name of Google Inc. nor the names of its
14 # contributors may be used to endorse or promote products derived 14 # contributors may be used to endorse or promote products derived
15 # from this software without specific prior written permission. 15 # from this software without specific prior written permission.
16 # 16 #
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 28
29 import json 29 import json
30 import optparse 30 import argparse
31 import os 31 import os
32 import re 32 import re
33 import sys 33 import sys
34 import urllib 34 import urllib
35 35
36 from common_includes import * 36 from common_includes import *
37 import push_to_trunk 37 import push_to_trunk
38 from push_to_trunk import PushToTrunkOptions
39 from push_to_trunk import RunPushToTrunk
40 38
41 SETTINGS_LOCATION = "SETTINGS_LOCATION" 39 SETTINGS_LOCATION = "SETTINGS_LOCATION"
42 40
43 CONFIG = { 41 CONFIG = {
44 PERSISTFILE_BASENAME: "/tmp/v8-auto-roll-tempfile", 42 PERSISTFILE_BASENAME: "/tmp/v8-auto-roll-tempfile",
45 DOT_GIT_LOCATION: ".git", 43 DOT_GIT_LOCATION: ".git",
46 SETTINGS_LOCATION: "~/.auto-roll", 44 SETTINGS_LOCATION: "~/.auto-roll",
47 } 45 }
48 46
49 47
50 class AutoRollOptions(CommonOptions):
51 def __init__(self, options):
52 super(AutoRollOptions, self).__init__(options)
53 self.requires_editor = False
54 self.status_password = options.status_password
55 self.c = options.c
56 self.push = getattr(options, 'push', False)
57 self.author = getattr(options, 'a', None)
58
59
60 class Preparation(Step): 48 class Preparation(Step):
61 MESSAGE = "Preparation." 49 MESSAGE = "Preparation."
62 50
63 def RunStep(self): 51 def RunStep(self):
64 self.InitialEnvironmentChecks() 52 self.InitialEnvironmentChecks()
65 self.CommonPrepare() 53 self.CommonPrepare()
66 54
67 55
68 class CheckAutoRollSettings(Step): 56 class CheckAutoRollSettings(Step):
69 MESSAGE = "Checking settings file." 57 MESSAGE = "Checking settings file."
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 latest = int(self["latest"]) 132 latest = int(self["latest"])
145 lkgr = int(self["lkgr"]) 133 lkgr = int(self["lkgr"])
146 if latest == lkgr: 134 if latest == lkgr:
147 print "ToT (r%d) is clean. Pushing to trunk." % latest 135 print "ToT (r%d) is clean. Pushing to trunk." % latest
148 self.PushTreeStatus("Tree is closed (preparing to push)") 136 self.PushTreeStatus("Tree is closed (preparing to push)")
149 137
150 # TODO(machenbach): Update the script before calling it. 138 # TODO(machenbach): Update the script before calling it.
151 try: 139 try:
152 if self._options.push: 140 if self._options.push:
153 self._side_effect_handler.Call( 141 self._side_effect_handler.Call(
154 RunPushToTrunk, 142 PushToTrunk(push_to_trunk.CONFIG, self._side_effect_handler).Run,
155 push_to_trunk.CONFIG, 143 ["-a", self._options.author,
156 PushToTrunkOptions.MakeForcedOptions(self._options.author, 144 "-c", self._options.chromium,
157 self._options.reviewer, 145 "-r", self._options.reviewer,
158 self._options.c), 146 "-f"])
159 self._side_effect_handler)
160 finally: 147 finally:
161 self.PushTreeStatus(self["tree_message"]) 148 self.PushTreeStatus(self["tree_message"])
162 else: 149 else:
163 print("ToT (r%d) is ahead of the LKGR (r%d). Skipping push to trunk." 150 print("ToT (r%d) is ahead of the LKGR (r%d). Skipping push to trunk."
164 % (latest, lkgr)) 151 % (latest, lkgr))
165 152
166 153
167 def RunAutoRoll(config, 154 class AutoRoll(ScriptsBase):
168 options, 155 def _PrepareOptions(self, parser):
169 side_effect_handler=DEFAULT_SIDE_EFFECT_HANDLER): 156 parser.add_argument("-c", "--chromium", required=True,
170 step_classes = [ 157 help=("The path to your Chromium src/ "
171 Preparation, 158 "directory to automate the V8 roll."))
172 CheckAutoRollSettings, 159 parser.add_argument("-p", "--push",
173 CheckTreeStatus, 160 help="Push to trunk. Dry run if unspecified.",
174 FetchLatestRevision, 161 default=False, action="store_true")
175 CheckLastPush, 162 parser.add_argument("--status-password",
176 FetchLKGR, 163 help="A file with the password to the status app.")
177 PushToTrunk, 164
178 ] 165 def _ProcessOptions(self, options):
179 RunScript(step_classes, config, options, side_effect_handler) 166 if not options.author or not options.reviewer:
167 print "You need to specify author and reviewer."
168 return False
169 options.requires_editor = False
170 return True
171
172 def _Steps(self):
173 return [
174 Preparation,
175 CheckAutoRollSettings,
176 CheckTreeStatus,
177 FetchLatestRevision,
178 CheckLastPush,
179 FetchLKGR,
180 PushToTrunk,
181 ]
180 182
181 183
182 def BuildOptions():
183 result = optparse.OptionParser()
184 result.add_option("-a", "--author", dest="a",
185 help=("Specify the author email used for rietveld."))
186 result.add_option("-c", "--chromium", dest="c",
187 help=("Specify the path to your Chromium src/ "
188 "directory to automate the V8 roll."))
189 result.add_option("-p", "--push",
190 help="Push to trunk if possible. Dry run if unspecified.",
191 default=False, action="store_true")
192 result.add_option("-r", "--reviewer",
193 help=("Specify the account name to be used for reviews."))
194 result.add_option("-s", "--step", dest="s",
195 help="Specify the step where to start work. Default: 0.",
196 default=0, type="int")
197 result.add_option("--status-password",
198 help="A file with the password to the status app.")
199 return result
200
201
202 def Main():
203 parser = BuildOptions()
204 (options, args) = parser.parse_args()
205 if not options.a or not options.c or not options.reviewer:
206 print "You need to specify author, chromium src location and reviewer."
207 parser.print_help()
208 return 1
209 RunAutoRoll(CONFIG, AutoRollOptions(options))
210
211 if __name__ == "__main__": 184 if __name__ == "__main__":
212 sys.exit(Main()) 185 sys.exit(AutoRoll(CONFIG).Run())
OLDNEW
« no previous file with comments | « no previous file | tools/push-to-trunk/common_includes.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698