devserver: remove temp directory for storing devserver codes.

Currently, when devserver tries to transfer devserver package, it first copies
the codes without some unneccesary files to a temp directory, then transfer the
whole package to device. This procedure will leave a temp directory on
devserver and won't be deleted after the provision succeeds or fails.

This CL helps the devserver to pass the temp directory to the auto_updater, and
then delete the directory after provision is finished.

BUG=chromium:654953
TEST=run repair with local autotest and devserver.

Change-Id: I4d0bd4516923a3bd41c455175ca36093e24266c1
Reviewed-on: https://chromium-review.googlesource.com/399989
Commit-Ready: Xixuan Wu <xixuan@chromium.org>
Tested-by: Xixuan Wu <xixuan@chromium.org>
Reviewed-by: Allen Li <ayatane@chromium.org>
diff --git a/cros_update_progress.py b/cros_update_progress.py
index 9c69352..f7c6b8e 100644
--- a/cros_update_progress.py
+++ b/cros_update_progress.py
@@ -20,6 +20,7 @@
 
 from __future__ import print_function
 
+import glob
 import logging
 import os
 
@@ -32,10 +33,14 @@
   osutils = None
 
 # Path for status tracking log.
-TRACK_LOG_FILE_PATH = '/tmp/auto-update/tracking_log/%s_%s.log'
+_TRACK_LOG_FILE_PATH = '/tmp/auto-update/tracking_log/%s_%s.log'
 
 # Path for executing log.
-EXECUTE_LOG_FILE_PATH = '/tmp/auto-update/executing_log/%s_%s.log'
+_EXECUTE_LOG_FILE_PATH = '/tmp/auto-update/executing_log/%s_%s.log'
+
+# Path and files for temporarily saving devserver codes, devserver and
+# update engine log.
+_CROS_UPDATE_TEMP_PATH = '/tmp/cros-update_%s_%s'
 
 # The string for update process finished
 FINISHED = 'Completed'
@@ -71,18 +76,32 @@
 
 def GetExecuteLogFile(host_name, pid):
   """Return the whole path of execute log file."""
-  if not os.path.exists(os.path.dirname(EXECUTE_LOG_FILE_PATH)):
-    osutils.SafeMakedirs(os.path.dirname(EXECUTE_LOG_FILE_PATH))
+  if not os.path.exists(os.path.dirname(_EXECUTE_LOG_FILE_PATH)):
+    osutils.SafeMakedirs(os.path.dirname(_EXECUTE_LOG_FILE_PATH))
 
-  return EXECUTE_LOG_FILE_PATH % (host_name, pid)
+  return _EXECUTE_LOG_FILE_PATH % (host_name, pid)
 
 
 def GetTrackStatusFile(host_name, pid):
   """Return the whole path of track status file."""
-  if not os.path.exists(os.path.dirname(TRACK_LOG_FILE_PATH)):
-    osutils.SafeMakedirs(os.path.dirname(TRACK_LOG_FILE_PATH))
+  if not os.path.exists(os.path.dirname(_TRACK_LOG_FILE_PATH)):
+    osutils.SafeMakedirs(os.path.dirname(_TRACK_LOG_FILE_PATH))
 
-  return TRACK_LOG_FILE_PATH % (host_name, pid)
+  return _TRACK_LOG_FILE_PATH % (host_name, pid)
+
+
+def GetAllTrackStatusFileByHostName(host_name):
+  """Return a list of existing track status files generated for a host."""
+  return glob.glob(_TRACK_LOG_FILE_PATH % (host_name, '*'))
+
+
+def GetAUTempDirectory(host_name, pid):
+  """Return the temp dir for storing codes and logs during auto-update."""
+  au_tempdir = _CROS_UPDATE_TEMP_PATH % (host_name, pid)
+  if not os.path.exists(au_tempdir):
+    osutils.SafeMakedirs(au_tempdir)
+
+  return au_tempdir
 
 
 def ReadExecuteLogFile(host_name, pid):
@@ -100,6 +119,11 @@
   osutils.SafeUnlink(GetExecuteLogFile(host_name, pid))
 
 
+def DelAUTempDirectory(host_name, pid):
+  """Delete the directory including auto-update-related logs."""
+  osutils.RmDir(GetAUTempDirectory(host_name, pid))
+
+
 class AUProgress(object):
   """Used for tracking the CrOS auto-update progress."""