Add PresubmitPromptOrNotify helper.

PresubmitPromptOrNotify prints the message and prompts the user only
if the presubmit is on upload, not commit.

This is useful to provide upload-time sanity checks without blocking
the CL from being landed via the commit-queue.


Review URL: https://chromiumcodereview.appspot.com/12676031

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@190711 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/presubmit_support.py b/presubmit_support.py
index 3239d7b..814d3fc 100755
--- a/presubmit_support.py
+++ b/presubmit_support.py
@@ -104,9 +104,12 @@
 
 
 class OutputApi(object):
-  """This class (more like a module) gets passed to presubmit scripts so that
-  they can specify various types of results.
+  """An instance of OutputApi gets passed to presubmit scripts so that they
+  can output various types of results.
   """
+  def __init__(self, is_committing):
+    self.is_committing = is_committing
+
   class PresubmitResult(object):
     """Base class for result objects."""
     fatal = False
@@ -163,6 +166,12 @@
     """Just print something to the screen -- but it's not even a warning."""
     pass
 
+  def PresubmitPromptOrNotify(self, *args, **kwargs):
+    """Warn the user when uploading, but only notify if committing."""
+    if self.is_committing:
+      return self.PresubmitNotifyResult(*args, **kwargs)
+    return self.PresubmitPromptWarning(*args, **kwargs)
+
   class MailTextResult(PresubmitResult):
     """A warning that should be included in the review request email."""
     def __init__(self, *args, **kwargs):
@@ -1020,7 +1029,7 @@
     else:
       function_name = 'CheckChangeOnUpload'
     if function_name in context:
-      context['__args'] = (input_api, OutputApi())
+      context['__args'] = (input_api, OutputApi(self.committing))
       logging.debug('Running %s in %s' % (function_name, presubmit_path))
       result = eval(function_name + '(*__args)', context)
       logging.debug('Running %s done.' % function_name)