def fetch_juju_binary(bucket, revision_build, workspace): package_key, filename = find_package_key(bucket, revision_build) logging.info('Selected: %s', package_key.name) download_files([package_key], workspace) package_path = os.path.join(workspace, filename) logging.info('Extracting: %s', package_path) return acquire_binary(package_path, workspace)
def fetch_files(bucket, revision_build, job, file_pattern, workspace): file_keys = find_file_keys(bucket, revision_build, job, file_pattern) out_files = [os.path.join(workspace, k.name.split('/')[-1]) for k in file_keys] for key in file_keys: logging.info('Selected: %s', key.name) download_files(file_keys, workspace) return out_files
def fetch_files(bucket, revision_build, job, file_pattern, workspace): file_keys = find_file_keys(bucket, revision_build, job, file_pattern) out_files = [ os.path.join(workspace, k.name.split('/')[-1]) for k in file_keys ] for key in file_keys: logging.info('Selected: %s', key.name) download_files(file_keys, workspace) return out_files
def test_download_files__suffix(self): keys = [KeyStub("test.txt", "foo"), KeyStub("test2.tar", "foo2")] with temp_dir() as dst: downloaded_files = download_files(keys, dst, suffix=".tar") self.assertItemsEqual(os.listdir(dst), ['test2.tar']) self.assertEqual("foo2", get_file_content('test2.tar', dst)) self.assertItemsEqual(downloaded_files, ['test2.tar'])
def test_download_files__overwrite(self): keys = [KeyStub("test.txt", "foo"), KeyStub("test2.txt", "foo2")] with temp_dir() as dst: set_file_content("test.txt", "foo", dst) downloaded_files = download_files(keys, dst, overwrite=True) self.assertItemsEqual(os.listdir(dst), ['test.txt', 'test2.txt']) self.assertEqual("foo", get_file_content('test.txt', dst)) self.assertEqual("foo2", get_file_content('test2.txt', dst)) self.assertItemsEqual(downloaded_files, ['test.txt', 'test2.txt'])
def test_download_files__matching_file_already_exists(self): keys = [KeyStub("test.txt", "foo"), KeyStub("test2.txt", "foo2")] with temp_dir() as dst: set_file_content("test.txt", "foo", dst) downloaded_files = download_files(keys, dst) self.assertItemsEqual(os.listdir(dst), ['test.txt', 'test2.txt']) self.assertEqual("foo", get_file_content('test.txt', dst)) self.assertEqual("foo2", get_file_content('test2.txt', dst)) self.assertItemsEqual(downloaded_files, ['test2.txt'])
def test_download_files__dst_dir_none(self): keys = [KeyStub("test.txt", "foo"), KeyStub("test2.txt", "foo2")] with patch('download_juju._download', autospec=True) as dj: download_files(keys) self.assertFalse(dj.called)