Don't re-generate packages if packages have already been generated.

By relying on the buildbot to generate packages for us, we save
roughly 13 minutes (22->9 minutes) in autotest staging time. In
order to remain backwards compatible, we check for the existence
of packages.checksum as it is not present until packages have been
generated.

BUG=chromium-os:27285
TEST=Unittests + pyflakes + pylint

Change-Id: I72c031920be6467a4d2941c1181c1abcb05551b2
Reviewed-on: https://gerrit.chromium.org/gerrit/17900
Tested-by: Chris Sosa <sosa@chromium.org>
Reviewed-by: Chris Masone <cmasone@chromium.org>
Commit-Ready: Chris Sosa <sosa@chromium.org>
diff --git a/devserver_util.py b/devserver_util.py
index 0791d06..256e0f9 100644
--- a/devserver_util.py
+++ b/devserver_util.py
@@ -10,9 +10,6 @@
 import os
 import shutil
 import subprocess
-import sys
-
-import constants
 
 
 GSUTIL_ATTEMPTS = 5
@@ -191,13 +188,17 @@
   autotest_pkgs_dir = os.path.join(staging_dir, 'autotest', 'packages')
   if not os.path.exists(autotest_pkgs_dir):
     os.makedirs(autotest_pkgs_dir)
-  cmd_list = ['autotest/utils/packager.py',
-              'upload', '--repository', autotest_pkgs_dir, '--all']
-  msg = 'Failed to create autotest packages!'
-  try:
-    subprocess.check_call(' '.join(cmd_list), cwd=staging_dir, shell=True)
-  except subprocess.CalledProcessError, e:
-    raise DevServerUtilError('%s %s' % (msg, e))
+
+  if not os.path.exists(os.path.join(autotest_pkgs_dir, 'packages.checksum')):
+    cmd_list = ['autotest/utils/packager.py',
+                'upload', '--repository', autotest_pkgs_dir, '--all']
+    msg = 'Failed to create autotest packages!'
+    try:
+      subprocess.check_call(' '.join(cmd_list), cwd=staging_dir, shell=True)
+    except subprocess.CalledProcessError, e:
+      raise DevServerUtilError('%s %s' % (msg, e))
+  else:
+    cherrypy.log('Using pre-generated packages from autotest', 'DEVSERVER_UTIL')
 
 
 def SafeSandboxAccess(static_dir, path):