pre-upload: add simple progress output

When configured hooks take a while to run, devs can get a bit confused
as to what's happening (since the output is silent by default).  Add a
simple progress output so they know what exactly is happening.

The form is basically:
PRESUBMT.cfg: [1/2]: 235ac803cacc33e52f9b38c2ff9eec9ce2b3d5a1: Running hook0
The count field tracks the commits.

BUG=None
TEST=ran `repo upload` in a few repos (with & w/out errors) and checked output

Change-Id: Icaab68c245045c5ea33f3cc1d63df94f3a5291f5
Reviewed-on: https://chromium-review.googlesource.com/788332
Commit-Ready: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
diff --git a/PRESUBMIT.cfg b/PRESUBMIT.cfg
index b1b1d78..b2050c4 100644
--- a/PRESUBMIT.cfg
+++ b/PRESUBMIT.cfg
@@ -1,6 +1,6 @@
 [Hook Scripts]
-hook0 = ../../chromite/bin/cros lint ${PRESUBMIT_FILES}
-hook1 = ./pre-upload_unittest.py
+cros lint = ../../chromite/bin/cros lint ${PRESUBMIT_FILES}
+pre-upload_unittest = ./pre-upload_unittest.py
 
 [Hook Overrides]
 cros_license_check: true
diff --git a/pre-upload.py b/pre-upload.py
index e733982..de65305 100755
--- a/pre-upload.py
+++ b/pre-upload.py
@@ -1,4 +1,5 @@
 #!/usr/bin/env python2
+# -*- coding: utf-8 -*-
 # Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
@@ -1561,6 +1562,7 @@
       try:
         options = config.get(SECTION_OPTIONS, flag)
         hooks[flag] = functools.partial(hooks[flag], options=options.split())
+        hooks[flag].__name__ = flag
       except (ConfigParser.NoOptionError, ConfigParser.NoSectionError):
         pass
 
@@ -1579,9 +1581,7 @@
   if not config.has_section(SECTION):
     return []
 
-  hook_names_values = config.items(SECTION)
-  hook_names_values.sort(key=lambda x: x[0])
-  return [x[1] for x in hook_names_values]
+  return config.items(SECTION)
 
 
 def _get_project_hooks(project, presubmit):
@@ -1621,8 +1621,10 @@
     hooks.extend(hook for hook in _PROJECT_SPECIFIC_HOOKS[project]
                  if hook not in disabled_hooks)
 
-  for script in _get_project_hook_scripts(config):
-    hooks.append(functools.partial(_run_project_hook_script, script))
+  for name, script in _get_project_hook_scripts(config):
+    func = functools.partial(_run_project_hook_script, script)
+    func.__name__ = name
+    hooks.append(func)
 
   return hooks
 
@@ -1681,10 +1683,17 @@
 
   hooks = _get_project_hooks(project.name, presubmit)
   error_found = False
-  for commit in commit_list:
+  commit_count = len(commit_list)
+  for i, commit in enumerate(commit_list):
     error_list = []
     for hook in hooks:
+      output = ('PRESUBMIT.cfg: [%i/%i]: %s: Running %s' %
+                (i + 1, commit_count, commit, hook.__name__))
+      print(output, end='\r')
+      sys.stdout.flush()
       hook_error = hook(project, commit)
+      print(' ' * len(output), end='\r')
+      sys.stdout.flush()
       if hook_error:
         error_list.append(hook_error)
         error_found = True