Fixing up error handling in workers.
Fix regex to support multiple gsutil versions.

BUG=None
TEST=None

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/gsd_generate_index@77691 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/gsd_generate_index.py b/gsd_generate_index.py
index 28584ff..6d0dc4d 100755
--- a/gsd_generate_index.py
+++ b/gsd_generate_index.py
@@ -58,7 +58,7 @@
   fields = {}
   fields['size'] = FixupSize(re.search('\tObject size:\t([0-9]+)\n',
                                        p_stdout).group(1))
-  fields['md5'] = re.search('\tMD5:\t([^\n]+)\n', p_stdout).group(1)
+  fields['md5'] = re.search('\t(MD5|Etag):\t([^\n]+)\n', p_stdout).group(2)
   fields['date'] = re.search('\tLast mod:\t([^\n]+)\n', p_stdout).group(1)
   return fields
 
@@ -140,11 +140,11 @@
   print '%s -- updated index' % path
 
 
-def IndexWorker(index_list, mutex, directories, objects, options):
+def IndexWorker(index_list, errors, mutex, directories, objects, options):
   while True:
     # Pluck out one index to work on, or quit if no more work left.
     mutex.acquire()
-    if not len(index_list):
+    if not index_list:
       mutex.release()
       return
     d = index_list.pop(0)
@@ -152,7 +152,13 @@
     # Find just this directories children.
     children = [o for o in objects if posixpath.dirname(o) == d]
     # Generate it.
-    GenerateIndex(d, children, directories, options)
+    try:
+      GenerateIndex(d, children, directories, options)
+    except Exception, e:
+      mutex.acquire()
+      errors.push(e)
+      print str(e)
+      mutex.release()
 
 
 def GenerateIndexes(path, options):
@@ -177,8 +183,9 @@
                 if not options.path or options.path.startswith(i)]
   # Spawn workers
   mutex = threading.Lock()
+  errors = []
   workers = [threading.Thread(target=IndexWorker,
-                              args=(index_list, mutex,
+                              args=(index_list, errors, mutex,
                                     directories, objects, options))
              for _ in range(0, NUM_THREADS)]
   # Start threads.
@@ -187,6 +194,8 @@
   # Wait for them to finish.
   for w in workers:
     w.join()
+  if errors:
+    return 2
   return 0