Index: tools/push-to-trunk/push_to_trunk.py |
diff --git a/tools/push-to-trunk/push_to_trunk.py b/tools/push-to-trunk/push_to_trunk.py |
index 0dc1a077d282cf4bfe24ac31192b8ceb94df3bde..ef04b33eeb8e771dd6f15b5af7c8f36bb51076ec 100755 |
--- a/tools/push-to-trunk/push_to_trunk.py |
+++ b/tools/push-to-trunk/push_to_trunk.py |
@@ -26,7 +26,7 @@ |
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
-import optparse |
+import argparse |
import sys |
import tempfile |
import urllib2 |
@@ -55,35 +55,6 @@ PUSH_MESSAGE_SUFFIX = " (based on bleeding_edge revision r%d)" |
PUSH_MESSAGE_RE = re.compile(r".* \(based on bleeding_edge revision r(\d+)\)$") |
-class PushToTrunkOptions(CommonOptions): |
- @staticmethod |
- def MakeForcedOptions(author, reviewer, chrome_path): |
- """Convenience wrapper.""" |
- class Options(object): |
- pass |
- options = Options() |
- options.s = 0 |
- options.l = None |
- options.b = None |
- options.f = True |
- options.m = False |
- options.c = chrome_path |
- options.reviewer = reviewer |
- options.a = author |
- return PushToTrunkOptions(options) |
- |
- def __init__(self, options): |
- super(PushToTrunkOptions, self).__init__(options, options.m) |
- self.requires_editor = not options.f |
- self.wait_for_lgtm = not options.f |
- self.tbr_commit = not options.m |
- self.l = options.l |
- self.reviewer = options.reviewer |
- self.c = options.c |
- self.b = getattr(options, 'b', None) |
- self.author = getattr(options, 'a', None) |
- |
- |
class Preparation(Step): |
MESSAGE = "Preparation." |
@@ -105,7 +76,7 @@ class DetectLastPush(Step): |
MESSAGE = "Detect commit ID of last push to trunk." |
def RunStep(self): |
- last_push = self._options.l or self.FindLastTrunkPush() |
+ last_push = self._options.last_push or self.FindLastTrunkPush() |
while True: |
# Print assumed commit, circumventing git's pager. |
print self.GitLog(n=1, git_hash=last_push) |
@@ -113,10 +84,10 @@ class DetectLastPush(Step): |
break |
last_push = self.FindLastTrunkPush(parent_hash=last_push) |
- if self._options.b: |
+ if self._options.last_bleeding_edge: |
# Read the bleeding edge revision of the last push from a command-line |
# option. |
- last_push_bleeding_edge = self._options.b |
+ last_push_bleeding_edge = self._options.last_bleeding_edge |
else: |
# Retrieve the bleeding edge revision of the last push from the text in |
# the push commit message. |
@@ -415,7 +386,7 @@ class CheckChromium(Step): |
MESSAGE = "Ask for chromium checkout." |
def Run(self): |
- self["chrome_path"] = self._options.c |
+ self["chrome_path"] = self._options.chromium |
if not self["chrome_path"]: |
self.DieNoManualMode("Please specify the path to a Chromium checkout in " |
"forced mode.") |
@@ -511,94 +482,69 @@ class CleanUp(Step): |
self.GitDeleteBranch(self.Config(TRUNKBRANCH)) |
-def RunPushToTrunk(config, |
- options, |
- side_effect_handler=DEFAULT_SIDE_EFFECT_HANDLER): |
- step_classes = [ |
- Preparation, |
- FreshBranch, |
- DetectLastPush, |
- PrepareChangeLog, |
- EditChangeLog, |
- IncrementVersion, |
- CommitLocal, |
- UploadStep, |
- CommitRepository, |
- StragglerCommits, |
- SquashCommits, |
- NewBranch, |
- ApplyChanges, |
- SetVersion, |
- CommitTrunk, |
- SanityCheck, |
- CommitSVN, |
- TagRevision, |
- CheckChromium, |
- SwitchChromium, |
- UpdateChromiumCheckout, |
- UploadCL, |
- SwitchV8, |
- CleanUp, |
- ] |
- |
- RunScript(step_classes, config, options, side_effect_handler) |
- |
- |
-def BuildOptions(): |
- result = optparse.OptionParser() |
- result.add_option("-a", "--author", dest="a", |
- help=("Specify the author email used for rietveld.")) |
- result.add_option("-b", "--last-bleeding-edge", dest="b", |
- help=("Manually specify the git commit ID of the last " |
- "bleeding edge revision that was pushed to trunk. " |
- "This is used for the auto-generated ChangeLog " |
- "entry.")) |
- result.add_option("-c", "--chromium", dest="c", |
- help=("Specify the path to your Chromium src/ " |
- "directory to automate the V8 roll.")) |
- result.add_option("-f", "--force", dest="f", |
- help="Don't prompt the user.", |
- default=False, action="store_true") |
- result.add_option("-l", "--last-push", dest="l", |
- help=("Manually specify the git commit ID " |
- "of the last push to trunk.")) |
- result.add_option("-m", "--manual", dest="m", |
- help="Prompt the user at every important step.", |
- default=False, action="store_true") |
- result.add_option("-r", "--reviewer", |
- help=("Specify the account name to be used for reviews.")) |
- result.add_option("-s", "--step", dest="s", |
- help="Specify the step where to start work. Default: 0.", |
- default=0, type="int") |
- return result |
- |
- |
-def ProcessOptions(options): |
- if options.s < 0: |
- print "Bad step number %d" % options.s |
- return False |
- if not options.m and not options.reviewer: |
- print "A reviewer (-r) is required in (semi-)automatic mode." |
- return False |
- if options.f and options.m: |
- print "Manual and forced mode cannot be combined." |
- return False |
- if not options.m and not options.c: |
- print "A chromium checkout (-c) is required in (semi-)automatic mode." |
- return False |
- if not options.m and not options.a: |
- print "Specify your chromium.org email with -a in (semi-)automatic mode." |
- return False |
- return True |
- |
- |
-def Main(): |
- parser = BuildOptions() |
- (options, args) = parser.parse_args() |
- if not ProcessOptions(options): |
- parser.print_help() |
- return 1 |
- RunPushToTrunk(CONFIG, PushToTrunkOptions(options)) |
+class PushToTrunk(ScriptsBase): |
+ def _PrepareOptions(self, parser): |
+ group = parser.add_mutually_exclusive_group() |
+ group.add_argument("-f", "--force", |
+ help="Don't prompt the user.", |
+ default=False, action="store_true") |
+ group.add_argument("-m", "--manual", |
+ help="Prompt the user at every important step.", |
+ default=False, action="store_true") |
+ parser.add_argument("-b", "--last-bleeding-edge", |
+ help=("The git commit ID of the last bleeding edge " |
+ "revision that was pushed to trunk. This is " |
+ "used for the auto-generated ChangeLog entry.")) |
+ parser.add_argument("-c", "--chromium", |
+ help=("The path to your Chromium src/ " |
+ "directory to automate the V8 roll.")) |
+ parser.add_argument("-l", "--last-push", |
+ help="The git commit ID of the last push to trunk.") |
+ |
+ def _ProcessOptions(self, options): |
+ if not options.manual and not options.reviewer: |
+ print "A reviewer (-r) is required in (semi-)automatic mode." |
+ return False |
+ if not options.manual and not options.chromium: |
+ print "A chromium checkout (-c) is required in (semi-)automatic mode." |
+ return False |
+ if not options.manual and not options.author: |
+ print "Specify your chromium.org email with -a in (semi-)automatic mode." |
+ return False |
+ |
+ options.requires_editor = not options.force |
+ options.wait_for_lgtm = not options.force |
+ options.tbr_commit = not options.manual |
+ return True |
+ |
+ def _Steps(self): |
+ return [ |
+ Preparation, |
+ FreshBranch, |
+ DetectLastPush, |
+ PrepareChangeLog, |
+ EditChangeLog, |
+ IncrementVersion, |
+ CommitLocal, |
+ UploadStep, |
+ CommitRepository, |
+ StragglerCommits, |
+ SquashCommits, |
+ NewBranch, |
+ ApplyChanges, |
+ SetVersion, |
+ CommitTrunk, |
+ SanityCheck, |
+ CommitSVN, |
+ TagRevision, |
+ CheckChromium, |
+ SwitchChromium, |
+ UpdateChromiumCheckout, |
+ UploadCL, |
+ SwitchV8, |
+ CleanUp, |
+ ] |
+ |
if __name__ == "__main__": |
- sys.exit(Main()) |
+ sys.exit(PushToTrunk(CONFIG).Run()) |