import os
import re
import sys
+import urllib
from common_includes import *
def __init__(self, options):
super(AutoRollOptions, self).__init__(options)
self.requires_editor = False
+ self.status_password = options.status_password
class Preparation(Step):
message = json.loads(status_json)["message"]
if re.search(r"nopush|no push", message, flags=re.I):
self.Die("Push to trunk disabled by tree state: %s" % message)
+ self.Persist("tree_message", message)
class FetchLatestRevision(Step):
class PushToTrunk(Step):
MESSAGE = "Pushing to trunk if possible."
+ def PushTreeStatus(self, message):
+ if not self._options.status_password:
+ print "Skipping tree status update without password file."
+ return
+ params = {
+ "message": message,
+ "username": "v8-auto-roll@chromium.org",
+ "password": FileToText(self._options.status_password).strip(),
+ }
+ params = urllib.urlencode(params)
+ print "Pushing tree status: '%s'" % message
+ self.ReadURL("https://v8-status.appspot.com/status", params,
+ wait_plan=[5, 20])
+
def RunStep(self):
self.RestoreIfUnset("latest")
self.RestoreIfUnset("lkgr")
+ self.RestoreIfUnset("tree_message")
latest = int(self._state["latest"])
lkgr = int(self._state["lkgr"])
if latest == lkgr:
print "ToT (r%d) is clean. Pushing to trunk." % latest
+ self.PushTreeStatus("Tree is closed (preparing to push)")
+
# TODO(machenbach): Call push to trunk script.
# TODO(machenbach): Update the script before calling it.
# self._side_effect_handler.Command(
# "tools/push-to-trunk/push-to-trunk.py",
# "-f -c %s -r %s" % (self._options.c, self._options.r))
+ self.PushTreeStatus(self._state["tree_message"])
else:
print("ToT (r%d) is ahead of the LKGR (r%d). Skipping push to trunk."
% (latest, lkgr))
result.add_option("-s", "--step", dest="s",
help="Specify the step where to start work. Default: 0.",
default=0, type="int")
+ result.add_option("--status-password",
+ help="A file with the password to the status app.")
return result
def ReadLine(self):
return sys.stdin.readline().strip()
- def ReadURL(self, url):
+ def ReadURL(self, url, params=None):
# pylint: disable=E1121
- url_fh = urllib2.urlopen(url, None, 60)
+ url_fh = urllib2.urlopen(url, params, 60)
try:
return url_fh.read()
finally:
return self._side_effect_handler.Command(os.environ["EDITOR"], args,
pipe=False)
- def ReadURL(self, url, retry_on=None, wait_plan=None):
+ def ReadURL(self, url, params=None, retry_on=None, wait_plan=None):
wait_plan = wait_plan or [3, 60, 600]
- cmd = lambda: self._side_effect_handler.ReadURL(url)
+ cmd = lambda: self._side_effect_handler.ReadURL(url, params)
return self.Retry(cmd, retry_on, wait_plan)
def GetDate(self):
}
-def MakeOptions(s=0, l=None, f=False, m=True, r=None, c=None):
+def MakeOptions(s=0, l=None, f=False, m=True, r=None, c=None,
+ status_password=None):
"""Convenience wrapper."""
class Options(object):
pass
options.m = m
options.r = r
options.c = c
+ options.status_password = status_password
return options
def ReadLine(self):
return self._rl_mock.Call()
- def ReadURL(self, url):
- return self._url_mock.Call(url)
+ def ReadURL(self, url, params):
+ if params is not None:
+ return self._url_mock.Call(url, params)
+ else:
+ return self._url_mock.Call(url)
def Sleep(self, seconds):
pass
self.assertRaises(Exception, self.MakeStep(CheckLastPush, state=state).Run)
def testAutoRoll(self):
+ status_password = self.MakeEmptyTempFile()
+ TextToFile("PW", status_password)
TEST_CONFIG[DOT_GIT_LOCATION] = self.MakeEmptyTempFile()
TEST_CONFIG[SETTINGS_LOCATION] = "~/.doesnotexist"
"{\"message\": \"Tree is throttled\"}"],
["https://v8-status.appspot.com/lkgr", Exception("Network problem")],
["https://v8-status.appspot.com/lkgr", "100"],
+ ["https://v8-status.appspot.com/status",
+ ("username=v8-auto-roll%40chromium.org&"
+ "message=Tree+is+closed+%28preparing+to+push%29&password=PW"),
+ ""],
+ ["https://v8-status.appspot.com/status",
+ ("username=v8-auto-roll%40chromium.org&"
+ "message=Tree+is+throttled&password=PW"), ""],
])
self.ExpectGit([
["status -s -uno", ""],
["status -s -b -uno", "## some_branch\n"],
["svn fetch", ""],
- ["svn log -1 --oneline", "r101 | Text"],
+ ["svn log -1 --oneline", "r100 | Text"],
["svn log -1 --oneline ChangeLog", "r65 | Prepare push to trunk..."],
])
- auto_roll.RunAutoRoll(TEST_CONFIG, AutoRollOptions(MakeOptions()), self)
+ auto_roll.RunAutoRoll(TEST_CONFIG, AutoRollOptions(
+ MakeOptions(status_password=status_password)), self)
self.assertEquals("100", self.MakeStep().Restore("lkgr"))
- self.assertEquals("101", self.MakeStep().Restore("latest"))
+ self.assertEquals("100", self.MakeStep().Restore("latest"))
def testAutoRollStoppedBySettings(self):
TEST_CONFIG[DOT_GIT_LOCATION] = self.MakeEmptyTempFile()