From 4c56e9dbe794778469f6488133624f8cf0c4233d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Louis-Francis=20Ratt=C3=A9-Boulianne?= <lfrb@collabora.com>
Date: Tue, 8 Nov 2016 15:44:06 -0500
Subject: [PATCH] Add LatestURL key to sysroot latest command
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

It returns the remote URL from where the sysroot can be downloaded
so that application integrating the tool can use their own
download manager.

Signed-off-by: Louis-Francis Ratté-Boulianne <lfrb@collabora.com>
Reviewed-by: Guillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Differential Revision: https://phabricator.apertis.org/D5207
---
 tests/test-latest  | 11 ++++++-----
 tests/test_util.py |  4 ++++
 tools/ade          |  2 ++
 3 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/tests/test-latest b/tests/test-latest
index 878ef3e..57f7df8 100755
--- a/tests/test-latest
+++ b/tests/test-latest
@@ -18,15 +18,16 @@ from test_util import BASE_TAG, BASE_ARCHIVE, BASE_CONFIG, \
                       SYSROOTS, LATEST_SYSROOTS, \
                       CONFIG_FILES, BAD_VERSION_URLS
 
-# Utility functions
-def check_version(result, sysroot):
-    expected = BASE_TAG.format(*sysroot)
-    return result['LatestVersion'] == expected
-
 # Setup
 server = SysrootServer()
 server.start()
 
+# Utility functions
+def check_version(result, sysroot):
+    expected_tag = BASE_TAG.format(*sysroot)
+    expected_url = server.base_archive_url().format(*sysroot)
+    return result['LatestVersion'] == expected_tag and result['LatestURL'] == expected_url
+
 # Test "ade sysroot latest --url" usage
 for sysroot in SYSROOTS:
     params = ['--url', server.base_url().format(*sysroot), '--distro', sysroot[0],
diff --git a/tests/test_util.py b/tests/test_util.py
index 76dafcc..a1f8fba 100644
--- a/tests/test_util.py
+++ b/tests/test_util.py
@@ -184,6 +184,10 @@ class SysrootServer(http.server.HTTPServer):
         url = "http://{}/versions/{}"
         return url.format(self.host(), BASE_TAG)
 
+    def base_archive_url(self):
+        url = "http://{}/archives/{}.tar.gz"
+        return url.format(self.host(), BASE_TAG)
+
 @contextmanager
 def templatedconfig(server, config_file):
     config = os.path.join(os.getcwd(), "configs", config_file)
diff --git a/tools/ade b/tools/ade
index 09ee6d7..91b5e55 100755
--- a/tools/ade
+++ b/tools/ade
@@ -377,6 +377,7 @@ class Ade:
 
             self.info("* Retrieved latest version: {0}{1}{2}" \
                   .format(Colors.OKGREEN, version, Colors.ENDC))
+            self.info("* Download URL: {0}".format(version.url))
 
             return version
         except URLError as e:
@@ -510,6 +511,7 @@ class Ade:
         version = self.get_latest_version()
         if self.format == 'parseable':
             print('LatestVersion:' + version.get_tag())
+            print('LatestURL:' + version.url)
 
     def do_sysroot_download(self):
         self.validate_sysroot_id()
-- 
GitLab