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

Unified Diff: trychange.py

Issue 126020: Revert 18198 because the root chromium codereview.settings has wrong try serv... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools/
Patch Set: Created 11 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tests/trychange_unittest.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: trychange.py
===================================================================
--- trychange.py (revision 18230)
+++ trychange.py (working copy)
@@ -14,7 +14,6 @@
import optparse
import os
import shutil
-import socket
import sys
import tempfile
import traceback
@@ -29,6 +28,7 @@
# Constants
HELP_STRING = "Sorry, Tryserver is not available."
+SCRIPT_PATH = os.path.join('tools', 'tryserver', 'tryserver.py')
USAGE = r"""%prog [options]
Client-side script to send a try job to the try server. It communicates to
@@ -75,31 +75,29 @@
def GetSourceRoot():
"""Returns the absolute directory one level up from the repository root."""
- # TODO(maruel): This is odd to assume that '..' is the source root.
return os.path.abspath(os.path.join(gcl.GetRepositoryRoot(), '..'))
-def GetTryServerSettings():
- """Grab try server settings local to the repository."""
- def _SafeResolve(host):
+def ExecuteTryServerScript():
+ """Locates the tryserver script, executes it and returns its dictionary.
+
+ The try server script contains the repository-specific try server commands."""
+ script_locals = {}
+ try:
+ # gcl.GetRepositoryRoot() may throw an exception.
+ script_path = os.path.join(gcl.GetRepositoryRoot(), SCRIPT_PATH)
+ except Exception:
+ return script_locals
+ if os.path.exists(script_path):
try:
- return socket.getaddrinfo(host, None)
- except socket.gaierror:
- return None
+ exec(gcl.ReadFile(script_path), script_locals)
+ except Exception, e:
+ # TODO(maruel): Need to specialize the exception trapper.
+ traceback.print_exc()
+ raise InvalidScript('%s is invalid.' % script_path)
+ return script_locals
- settings = {}
- settings['http_port'] = gcl.GetCodeReviewSetting('TRYSERVER_HTTP_PORT')
- settings['http_host'] = gcl.GetCodeReviewSetting('TRYSERVER_HTTP_HOST')
- settings['svn_repo'] = gcl.GetCodeReviewSetting('TRYSERVER_SVN_URL')
- # Use http is the http_host name resolve, fallback to svn otherwise.
- if (settings['http_port'] and settings['http_host'] and
- _SafeResolve(settings['http_host'])):
- settings['default_transport'] = 'http'
- elif settings.get('svn_repo'):
- settings['default_transport'] = 'svn'
- return settings
-
def EscapeDot(name):
return name.replace('.', '-')
@@ -258,12 +256,18 @@
def _SendChangeHTTP(options):
"""Send a change to the try server using the HTTP protocol."""
+ script_locals = ExecuteTryServerScript()
+
if not options.host:
- raise NoTryServerAccess('Please use the --host option to specify the try '
- 'server host to connect to.')
+ options.host = script_locals.get('try_server_http_host', None)
+ if not options.host:
+ raise NoTryServerAccess('Please use the --host option to specify the try '
+ 'server host to connect to.')
if not options.port:
- raise NoTryServerAccess('Please use the --port option to specify the try '
- 'server port to connect to.')
+ options.port = script_locals.get('try_server_http_port', None)
+ if not options.port:
+ raise NoTryServerAccess('Please use the --port option to specify the try '
+ 'server port to connect to.')
values = _ParseSendChangeOptions(options)
values['patch'] = options.diff
@@ -294,9 +298,12 @@
def _SendChangeSVN(options):
"""Send a change to the try server by committing a diff file on a subversion
server."""
+ script_locals = ExecuteTryServerScript()
if not options.svn_repo:
- raise NoTryServerAccess('Please use the --svn_repo option to specify the'
- ' try server svn repository to connect to.')
+ options.svn_repo = script_locals.get('try_server_svn', None)
+ if not options.svn_repo:
+ raise NoTryServerAccess('Please use the --svn_repo option to specify the'
+ ' try server svn repository to connect to.')
values = _ParseSendChangeOptions(options)
description = ''
@@ -308,9 +315,7 @@
temp_file = tempfile.NamedTemporaryFile()
temp_file_name = temp_file.name
try:
- # Don't use '--non-interactive', since we want it to prompt for
- # crendentials if necessary.
- RunCommand(['svn', 'checkout', '--depth', 'empty',
+ RunCommand(['svn', 'checkout', '--depth', 'empty', '--non-interactive',
options.svn_repo, temp_dir])
# TODO(maruel): Use a subdirectory per user?
current_time = str(datetime.datetime.now()).replace(':', '.')
@@ -386,11 +391,6 @@
file_list,
swallow_exception,
prog=None):
- default_settings = GetTryServerSettings()
- transport_functions = { 'http': _SendChangeHTTP, 'svn': _SendChangeSVN }
- default_transport = transport_functions.get(
- default_settings.get('default_transport'))
-
# Parse argv
parser = optparse.OptionParser(usage=USAGE,
version=__version__,
@@ -446,44 +446,31 @@
parser.add_option_group(group)
group = optparse.OptionGroup(parser, "Access the try server by HTTP")
- group.add_option("--use_http",
- action="store_const",
- const=_SendChangeHTTP,
- dest="send_patch",
- default=default_transport,
+ group.add_option("--use_http", action="store_const", const=_SendChangeHTTP,
+ dest="send_patch", default=_SendChangeHTTP,
help="Use HTTP to talk to the try server [default]")
group.add_option("--host",
- default=default_settings['http_host'],
help="Host address")
group.add_option("--port",
- default=default_settings['http_port'],
help="HTTP port")
group.add_option("--proxy",
help="HTTP proxy")
parser.add_option_group(group)
group = optparse.OptionGroup(parser, "Access the try server with SVN")
- group.add_option("--use_svn",
- action="store_const",
- const=_SendChangeSVN,
+ group.add_option("--use_svn", action="store_const", const=_SendChangeSVN,
dest="send_patch",
help="Use SVN to talk to the try server")
- group.add_option("--svn_repo",
- metavar="SVN_URL",
- default=default_settings['svn_repo'],
+ group.add_option("--svn_repo", metavar="SVN_URL",
help="SVN url to use to write the changes in; --use_svn is "
"implied when using --svn_repo")
parser.add_option_group(group)
options, args = parser.parse_args(argv)
+ # Switch the default accordingly.
+ if options.svn_repo:
+ options.send_patch = _SendChangeSVN
- # Switch the default accordingly if there was no default send_patch.
- if not options.send_patch:
- if options.http_port and options.http_host:
- options.send_patch = _SendChangeHTTP
- elif options.svn_repo:
- options.send_patch = _SendChangeSVN
-
if len(args) == 1 and args[0] == 'help':
parser.print_help()
if (not options.files and (not options.issue and options.patchset) and
« no previous file with comments | « tests/trychange_unittest.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698