Index: presubmit_support.py |
diff --git a/presubmit_support.py b/presubmit_support.py |
index b386524068c1ceddc44fc4e10edc4c596d6f577c..8028ba5367fd44b0a8e24c6961340d881634a2fc 100755 |
--- a/presubmit_support.py |
+++ b/presubmit_support.py |
@@ -1143,6 +1143,37 @@ class GetTryMastersExecuter(object): |
return get_preferred_try_masters(project, change) |
+class GetPostUploadExecuter(object): |
+ @staticmethod |
+ def ExecPresubmitScript(script_text, presubmit_path, cl, change): |
+ """Executes PostUploadHook() from a single presubmit script. |
+ |
+ Args: |
+ script_text: The text of the presubmit script. |
+ presubmit_path: Project script to run. |
+ cl: The Changelist object. |
+ change: The Change object. |
+ |
+ Return: |
+ A list of results objects. |
+ """ |
+ context = {} |
+ try: |
+ exec script_text in context |
iannucci
2015/02/25 22:31:04
:(
Though I guess since it's already PRESUBMIT.py
rmistry
2015/02/26 13:28:26
Right, this also follows the same design as GetTry
|
+ except Exception, e: |
+ raise PresubmitFailure('"%s" had an exception.\n%s' |
+ % (presubmit_path, e)) |
+ |
+ function_name = 'PostUploadHook' |
+ if function_name not in context: |
+ return {} |
+ post_upload_hook = context[function_name] |
+ if not len(inspect.getargspec(post_upload_hook)[0]) == 3: |
+ raise PresubmitFailure( |
+ 'Expected function "PostUploadHook" to take three arguments.') |
+ return post_upload_hook(cl, change, OutputApi(False)) |
+ |
+ |
def DoGetTrySlaves(change, |
changed_files, |
repository_root, |
@@ -1263,6 +1294,45 @@ def DoGetTryMasters(change, |
return results |
+def DoPostUploadExecuter(change, |
+ cl, |
+ repository_root, |
+ verbose, |
+ output_stream): |
+ """Execute the post upload hook. |
+ |
+ Args: |
+ change: The Change object. |
+ cl: The Changelist object. |
+ repository_root: The repository root. |
+ verbose: Prints debug info. |
+ output_stream: A stream to write debug output to. |
+ """ |
+ presubmit_files = ListRelevantPresubmitFiles( |
+ change.LocalPaths(), repository_root) |
+ if not presubmit_files and verbose: |
+ output_stream.write("Warning, no PRESUBMIT.py found.\n") |
+ results = [] |
+ executer = GetPostUploadExecuter() |
+ |
+ for filename in presubmit_files: |
iannucci
2015/02/25 22:31:04
is this in general -> specific, or specific -> gen
rmistry
2015/02/26 13:28:26
Thats a good point. It was 1->2. Changed it to 2->
|
+ filename = os.path.abspath(filename) |
+ if verbose: |
+ output_stream.write("Running %s\n" % filename) |
+ # Accept CRLF presubmit script. |
+ presubmit_script = gclient_utils.FileRead(filename, 'rU') |
+ results.extend(executer.ExecPresubmitScript( |
+ presubmit_script, filename, cl, change)) |
+ output_stream.write('\n') |
+ if results: |
+ output_stream.write('** Post Upload Hook Messages **\n') |
+ for result in results: |
+ result.handle(output_stream) |
+ output_stream.write('\n') |
+ |
+ return results |
+ |
+ |
class PresubmitExecuter(object): |
def __init__(self, change, committing, rietveld_obj, verbose): |
""" |