Commit 3ccbf7e6 authored by maruel@chromium.org's avatar maruel@chromium.org

Factor out PathDifference into gclient_utils for a later reuse.

Make lack of email address an error.

TEST=none
BUG=none

Review URL: http://codereview.chromium.org/507072

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@35167 0039d316-1c4b-4281-b951-d872f2087c98
parent 6f6a801e
...@@ -819,18 +819,6 @@ def TryChange(change_info, args, swallow_exception): ...@@ -819,18 +819,6 @@ def TryChange(change_info, args, swallow_exception):
return return
ErrorExit("You need to install trychange.py to use the try server.") ErrorExit("You need to install trychange.py to use the try server.")
def PathDifference(root, subpath):
"""Returns the difference subpath minus root."""
root = os.path.realpath(root)
subpath = os.path.realpath(subpath)
if not subpath.startswith(root):
return None
# If the root does not have a trailing \ or /, we add it so the returned
# path starts immediately after the seperator regardless of whether it is
# provided.
root = os.path.join(root, '')
return subpath[len(root):]
trychange_args = [] trychange_args = []
settings = { settings = {
'port': GetCodeReviewSetting('TRYSERVER_HTTP_PORT'), 'port': GetCodeReviewSetting('TRYSERVER_HTTP_PORT'),
...@@ -846,8 +834,9 @@ def TryChange(change_info, args, swallow_exception): ...@@ -846,8 +834,9 @@ def TryChange(change_info, args, swallow_exception):
gclient_root = gclient_utils.FindGclientRoot(GetRepositoryRoot()) gclient_root = gclient_utils.FindGclientRoot(GetRepositoryRoot())
if gclient_root: if gclient_root:
trychange_args.extend(['--root', PathDifference(gclient_root, trychange_args.extend(['--root',
GetRepositoryRoot())]) gclient_utils.PathDifference(gclient_root,
GetRepositoryRoot())])
if change_info: if change_info:
trychange_args.extend(['--name', change_info.name]) trychange_args.extend(['--name', change_info.name])
if change_info.issue: if change_info.issue:
......
...@@ -317,3 +317,15 @@ def FindGclientRoot(from_dir): ...@@ -317,3 +317,15 @@ def FindGclientRoot(from_dir):
return None return None
path = next[0] path = next[0]
return path return path
def PathDifference(root, subpath):
"""Returns the difference subpath minus root."""
root = os.path.realpath(root)
subpath = os.path.realpath(subpath)
if not subpath.startswith(root):
return None
# If the root does not have a trailing \ or /, we add it so the returned
# path starts immediately after the seperator regardless of whether it is
# provided.
root = os.path.join(root, '')
return subpath[len(root):]
...@@ -17,8 +17,8 @@ class GclientUtilsUnittest(SuperMoxTestBase): ...@@ -17,8 +17,8 @@ class GclientUtilsUnittest(SuperMoxTestBase):
'CheckCall', 'CheckCallError', 'Error', 'FileRead', 'FileWrite', 'CheckCall', 'CheckCallError', 'Error', 'FileRead', 'FileWrite',
'FindGclientRoot', 'FindGclientRoot',
'FullUrlFromRelative', 'FullUrlFromRelative2', 'GetNamedNodeText', 'FullUrlFromRelative', 'FullUrlFromRelative2', 'GetNamedNodeText',
'GetNodeNamedAttributeText', 'IsUsingGit', 'ParseXML', 'GetNodeNamedAttributeText', 'IsUsingGit', 'PathDifference',
'PrintableObject', 'RemoveDirectory', 'SplitUrlRevision', 'ParseXML', 'PrintableObject', 'RemoveDirectory', 'SplitUrlRevision',
'SubprocessCall', 'SubprocessCallAndFilter', 'errno', 'os', 're', 'SubprocessCall', 'SubprocessCallAndFilter', 'errno', 'os', 're',
'stat', 'subprocess', 'sys', 'time', 'xml', 'stat', 'subprocess', 'sys', 'time', 'xml',
] ]
......
...@@ -427,6 +427,8 @@ def TryChange(argv, ...@@ -427,6 +427,8 @@ def TryChange(argv,
parser.add_option_group(group) parser.add_option_group(group)
options, args = parser.parse_args(argv) options, args = parser.parse_args(argv)
if len(args) == 1 and args[0] == 'help':
parser.print_help()
# Switch the default accordingly if there was no default send_patch. # Switch the default accordingly if there was no default send_patch.
if not options.send_patch: if not options.send_patch:
...@@ -437,19 +439,15 @@ def TryChange(argv, ...@@ -437,19 +439,15 @@ def TryChange(argv,
else: else:
parser.error('Please specify an access method.') parser.error('Please specify an access method.')
if len(args) == 1 and args[0] == 'help':
parser.print_help()
if (not options.files and (not options.issue and options.patchset) and
not options.diff and not options.url):
# TODO(maruel): It should just try the modified files showing up in a
# svn status.
parser.error('Nothing to try, changelist is empty.')
try: try:
# Convert options.diff into the content of the diff. # Convert options.diff into the content of the diff.
if options.url: if options.url:
if options.files:
parser.error('You cannot specify files and --url at the same time.')
options.diff = urllib.urlopen(options.url).read() options.diff = urllib.urlopen(options.url).read()
elif options.diff: elif options.diff:
if options.files:
parser.error('You cannot specify files and --diff at the same time.')
options.diff = gclient_utils.FileRead(options.diff, 'rb') options.diff = gclient_utils.FileRead(options.diff, 'rb')
# Process the VCS in any case at least to retrieve the email address. # Process the VCS in any case at least to retrieve the email address.
try: try:
...@@ -486,8 +484,8 @@ def TryChange(argv, ...@@ -486,8 +484,8 @@ def TryChange(argv,
options.name = 'Unnamed' options.name = 'Unnamed'
print('Note: use --name NAME to change the try job name.') print('Note: use --name NAME to change the try job name.')
if not options.email: if not options.email:
print('Warning: TRYBOT_RESULTS_EMAIL_ADDRESS is not set. Try server ' parser.error('Using an anonymous checkout. Please use --email or set '
'results might\ngo to: %s@google.com.\n' % options.user) 'the TRYBOT_RESULTS_EMAIL_ADDRESS environment variable.')
else: else:
print('Results will be emailed to: ' + options.email) print('Results will be emailed to: ' + options.email)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment