Adds the ability to clean a build's previously staged artifacts.

This is to support developer workflows where a custom build
may need to be restaged multiple times.

BUG=chromium:570111
TEST=staged custom builds to local devserver

Reviewed-on: https://chromium-review.googlesource.com/321999
Commit-Ready: Laurence Goodby <lgoodby@chromium.org>
Tested-by: Laurence Goodby <lgoodby@chromium.org>
Reviewed-by: Simran Basi <sbasi@chromium.org>
(cherry picked from commit f5c958d2039300c1f5bd900fa17e616f02396031)
Signed-off-by: Duncan Laurie <dlaurie@chromium.org>
Change-Id: I4536d00950a7729a7e819b8083c884abafecdf8c
Reviewed-on: https://chromium-review.googlesource.com/322857
diff --git a/devserver.py b/devserver.py
index b9a6eab..dfc6307 100755
--- a/devserver.py
+++ b/devserver.py
@@ -716,6 +716,7 @@
       files: Comma separated list of files to stage. These
         will be available as is in the corresponding static directory with no
         custom post-processing.
+      clean: True to remove any previously staged artifacts first.
 
     Example:
       To download the autotest and test suites tarballs:
@@ -745,6 +746,11 @@
     with DevServerRoot._staging_thread_count_lock:
       DevServerRoot._staging_thread_count += 1
     try:
+      boolean_string = kwargs.get('clean')
+      clean = xbuddy.XBuddy.ParseBoolean(boolean_string)
+      if clean and os.path.exists(dl.GetBuildDir()):
+        _Log('Removing %s' % dl.GetBuildDir())
+        shutil.rmtree(dl.GetBuildDir())
       async = kwargs.get('async', False)
       dl.Download(factory, async=async)
     finally: