devserver: Add functionality to stage artifacts from a local directory.
This change updates the devserver so that local build and
test artifacts can be staged onto the devserver.
The devserver stage function will now also accept a local_path
as an argument. local_path specifies a subdirectory of the
devserver's static directory that contains build artifacts we
want to stage. It's restricted to a subdirectory of the static
directory in order to not allow callers access to the whole
file system of the devserver.
This functionality will be used in supporting custom image
staging for the new 'cros stage-on-moblab' command.
BUG=chromium:370909
TEST=devserver_integration_test, unittests, & local moblab test run.
Change-Id: I617a61066e644657cdbfddee9762691c495d26b5
Reviewed-on: https://chromium-review.googlesource.com/239321
Reviewed-by: Simran Basi <sbasi@chromium.org>
Tested-by: Simran Basi <sbasi@chromium.org>
Commit-Queue: Simran Basi <sbasi@chromium.org>
diff --git a/downloader.py b/downloader.py
index 9174f10..2a319d6 100755
--- a/downloader.py
+++ b/downloader.py
@@ -60,8 +60,22 @@
self._build_dir = Downloader.GetBuildDir(static_dir, archive_url)
@staticmethod
- def ParseUrl(archive_url):
- """Parses archive_url into rel_path and build.
+ def ParseUrl(path_or_url):
+ """Parses |path_or_url| into build relative path and the shorter build name.
+
+ Args:
+ path_or_url: a local path or URL at which build artifacts are archived.
+
+ Returns:
+ A tuple of (build relative path, short build name)
+ """
+ if path_or_url.startswith('gs://'):
+ return Downloader.ParseGSUrl(path_or_url)
+ return Downloader.ParseLocalPath(path_or_url)
+
+ @staticmethod
+ def ParseGSUrl(archive_url):
+ """Parses |path_or_url| into build relative path and the shorter build name.
Parses archive_url into rel_path and build e.g.
gs://chromeos-image-archive/{rel_path}/{build}.
@@ -82,6 +96,24 @@
return rel_path, build
@staticmethod
+ def ParseLocalPath(local_path):
+ """Parses local_path into rel_path and build.
+
+ Parses a local path into rel_path and build e.g.
+ /{path to static dir}/{rel_path}/{build}.
+
+ Args:
+ local_path: a local path that the build artifacts are stored. Must be a
+ subpath of the static directory.
+
+ Returns:
+ A tuple of (build relative path, short build name)
+ """
+ rel_path = os.path.basename(os.path.dirname(local_path))
+ build = os.path.basename(local_path)
+ return rel_path, build
+
+ @staticmethod
def GetBuildDir(static_dir, archive_url):
"""Returns the path to where the artifacts will be staged.