diff --git a/boottest.py b/boottest.py index 1631080..63e2eb6 100644 --- a/boottest.py +++ b/boottest.py @@ -12,6 +12,7 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. import os +import urllib from consts import BINARIES @@ -36,9 +37,25 @@ class TouchManifest(object): """ + def __fetch_manifest(self, distribution, series): + url = "http://cdimage.ubuntu.com/{}/daily-preinstalled/" \ + "pending/{}-preinstalled-touch-armhf.manifest".format( + distribution, series + ) + response = urllib.urlopen(url) + # Only [re]create the manifest file if one was successfully downloaded + # this allows for an existing image to be used if the download fails. + if response.code == 200: + os.makedirs(os.path.dirname(self.path)) + with open(self.path, 'w') as fp: + fp.write(response.read()) + def __init__(self, distribution, series): - self.path = 'boottest/images/{}/{}/manifest'.format( + self.path = "boottest/images/{}/{}/manifest".format( distribution, series) + + self.__fetch_manifest(distribution, series) + self._manifest = self._load() def _load(self): @@ -49,6 +66,9 @@ class TouchManifest(object): with open(self.path) as fd: for line in fd.readlines(): + # skip headers and metadata + if 'DOCTYPE' in line: + continue name, version = line.split() name = name.split(':')[0] if name == 'click': diff --git a/tests/test_boottest.py b/tests/test_boottest.py index 0b9815c..97e64aa 100644 --- a/tests/test_boottest.py +++ b/tests/test_boottest.py @@ -46,6 +46,23 @@ class TestTouchManifest(unittest.TestCase): self.assertEqual([], manifest._manifest) self.assertNotIn('foo', manifest) + def test_fetch(self): + # Missing manifest file is fetched dynamically + manifest = TouchManifest('ubuntu-touch', 'vivid') + self.assertNotEqual([], manifest._manifest) + + def test_fetch_fails(self): + distribution = 'fake' + series = 'fake' + manifest_dir = os.path.join(self.imagesdir, distribution, series) + manifest_lines = [ + 'foo:armhf 1~beta1', + ] + create_manifest(manifest_dir, manifest_lines) + manifest = TouchManifest(distribution, series) + self.assertEqual(1, len(manifest._manifest)) + self.assertIn('foo', manifest) + def test_simple(self): # Existing manifest file allows callsites to properly check presence. manifest_dir = os.path.join(self.imagesdir, 'ubuntu/vivid')