def __init__(self, text="", requires=None):
self._text = text
self._number = -1
+ self._options = None
self._requires = requires
self._side_effect_handler = DEFAULT_SIDE_EFFECT_HANDLER
def RunStep(self):
raise NotImplementedError
- def ReadLine(self):
- return self._side_effect_handler.ReadLine()
+ def ReadLine(self, default=None):
+ # Don't prompt in forced mode.
+ if self._options and self._options.f and default is not None:
+ print "%s (forced)" % default
+ return default
+ else:
+ return self._side_effect_handler.ReadLine()
def Git(self, args="", prefix="", pipe=True):
return self._side_effect_handler.Command("git", args, prefix, pipe)
print "Exiting"
raise Exception(msg)
+ def DieInForcedMode(self, msg=""):
+ if self._options and self._options.f:
+ msg = msg or "Not implemented in forced mode."
+ self.Die(msg)
+
def Confirm(self, msg):
print "%s [Y/n] " % msg,
- answer = self.ReadLine()
+ answer = self.ReadLine(default="Y")
return answer == "" or answer == "Y" or answer == "y"
def DeleteBranch(self, name):
if not os.path.exists(self._config[DOT_GIT_LOCATION]):
self.Die("This is not a git checkout, this script won't work for you.")
+ # TODO(machenbach): Don't use EDITOR in forced mode as soon as script is
+ # well tested.
# Cancel if EDITOR is unset or not executable.
if (not os.environ.get("EDITOR") or
Command("which", os.environ["EDITOR"]) is None):
answer = ""
while answer != "LGTM":
print "> ",
+ # TODO(machenbach): Add default="LGTM" to avoid prompt when script is
+ # well tested and when prepare push cl has TBR flag.
answer = self.ReadLine()
if answer != "LGTM":
print "That was not 'LGTM'."
print("Applying the patch \"%s\" failed. Either type \"ABORT<Return>\", "
"or resolve the conflicts, stage *all* touched files with "
"'git add', and type \"RESOLVED<Return>\"")
+ self.DieInForcedMode()
answer = ""
while answer != "RESOLVED":
if answer == "ABORT":
Step.__init__(self, "Upload for code review.")
def RunStep(self):
- print "Please enter the email address of a V8 reviewer for your patch: ",
- reviewer = self.ReadLine()
+ if self._options and self._options.r:
+ print "Using account %s for review." % self._options.r
+ reviewer = self._options.r
+ else:
+ print "Please enter the email address of a V8 reviewer for your patch: ",
+ self.DieInForcedMode("A reviewer must be specified in forced mode.")
+ reviewer = self.ReadLine()
args = "cl upload -r \"%s\" --send-mail" % reviewer
if self.Git(args,pipe=False) is None:
self.Die("'git cl upload' failed, please try again.")
print ("Please press <Return> to have your EDITOR open the ChangeLog "
"entry, then edit its contents to your liking. When you're done, "
"save the file and exit your EDITOR. ")
- self.ReadLine()
+ self.ReadLine(default="")
+ # TODO(machenbach): Don't use EDITOR in forced mode as soon as script is
+ # well tested.
self.Editor(self.Config(CHANGELOG_ENTRY_FILE))
handle, new_changelog = tempfile.mkstemp()
os.close(handle)
print("Sorry, grepping for the SVN revision failed. Please look for it "
"in the last command's output above and provide it manually (just "
"the number, without the leading \"r\").")
+ self.DieInForcedMode("Can't prompt in forced mode.")
while not trunk_revision:
print "> ",
trunk_revision = self.ReadLine()
def Run(self):
chrome_path = self._options.c
if not chrome_path:
+ self.DieInForcedMode("Please specify the path to a Chromium checkout in "
+ "forced mode.")
print ("Do you have a \"NewGit\" Chromium checkout and want "
"this script to automate creation of the roll CL? If yes, enter the "
"path to (and including) the \"src\" directory here, otherwise just "
ver = "%s.%s.%s" % (self._state["major"],
self._state["minor"],
self._state["build"])
- print "Please enter the email address of a reviewer for the roll CL: ",
- rev = self.ReadLine()
+ if self._options and self._options.r:
+ print "Using account %s for review." % self._options.r
+ rev = self._options.r
+ else:
+ print "Please enter the email address of a reviewer for the roll CL: ",
+ self.DieInForcedMode("A reviewer must be specified in forced mode.")
+ rev = self.ReadLine()
args = "commit -am \"Update V8 to version %s.\n\nTBR=%s\"" % (ver, rev)
if self.Git(args) is None:
self.Die("'git commit' failed.")
def BuildOptions():
result = optparse.OptionParser()
- result.add_option("-s", "--step", dest="s",
- help="Specify the step where to start work. Default: 0.",
- default=0, type="int")
- result.add_option("-l", "--last-push", dest="l",
- help=("Manually specify the git commit ID "
- "of the last push to trunk."))
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("-r", "--reviewer", dest="r",
+ 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
patch = FileToText(TEST_CONFIG[ PATCH_FILE])
self.assertTrue(re.search(r"patch content", patch))
- def testPushToTrunk(self):
+ def _PushToTrunk(self, force=False):
TEST_CONFIG[DOT_GIT_LOCATION] = self.MakeEmptyTempFile()
TEST_CONFIG[VERSION_FILE] = self.MakeTempVersionFile()
TEST_CONFIG[CHANGELOG_ENTRY_FILE] = self.MakeEmptyTempFile()
"Y", # Sanity check.
"reviewer@chromium.org", # Chromium reviewer.
]
+ if force:
+ # TODO(machenbach): The lgtm for the prepare push is just temporary.
+ # There should be no user input in "force" mode.
+ self._rl_recipe = [
+ "LGTM", # Enter LGTM for V8 CL.
+ ]
class Options( object ):
pass
options = Options()
options.s = 0
options.l = None
+ options.f = force
+ options.r = "reviewer@chromium.org" if force else None
options.c = TEST_CONFIG[CHROMIUM]
RunPushToTrunk(TEST_CONFIG, options, self)
# Note: The version file is on build number 5 again in the end of this test
# since the git command that merges to the bleeding edge branch is mocked
# out.
+
+ def testPushToTrunk(self):
+ self._PushToTrunk()
+
+ def testPushToTrunkForced(self):
+ self._PushToTrunk(force=True)