def test_already_downloaded(self, stdout, get): stdout_data = [] stdout.write = lambda text: stdout_data.append(text) self.data = """ hello, this is a response. """ * (1024 * 16) def iter_content(chunk_size=1): rest = self.data while rest: chunk = rest[:chunk_size] rest = rest[chunk_size:] yield chunk response = Mock(headers={'Content-length': str(len(self.data))}, iter_content=iter_content) get.return_value = response fname = os.path.join(self.tempdir, 'some.content') utils.download_url('http://toto', fname) self.assertEquals(self.data, open(fname).read()) self.assertIn("Downloading build from: http://toto", ''.join(stdout_data))
def test_already_downloaded(self, stdout): stdout_data = [] stdout.write = lambda text: stdout_data.append(text) fname = os.path.join(self.tempdir, 'something') with open(fname, 'w') as f: f.write("1") utils.download_url('', fname) self.assertIn("Using local file", "".join(stdout_data))
def download(self, date=datetime.date.today(), dest=None): url = self.get_build_url(date) if url: if not dest: dest = self.get_destination(url, date) if not self.persist: self.remove_lastdest() download_url(url, dest) self.dest = self.lastdest = dest return True else: return False
def download(self, date=datetime.date.today(), dest=None): url = self.get_build_url(date) if url: if not dest: dest = self.get_destination(url, date) if not self.persist: self.remove_lastdest() self.dest = self.lastdest = dest download_url(url, dest) return True else: return False
def download(self, date=datetime.date.today(), dest=None): url = self.get_build_url(date) if url: if not dest: dest = self.get_destination(url, date) if not self.persist: self.remove_lastdest() if os.path.exists(dest): print "Using local file: %s" % dest else: download_url(url, dest) self.dest = self.lastdest = dest return True else: return False
def download_tests(self, installdir='downloadedtests'): self.testinstalldir = os.path.abspath(installdir) testsName = os.path.basename(self.testurl) pathToTests = os.path.join(os.path.dirname(os.path.abspath(__file__)), testsName) # delete tests if they already exist if os.access(pathToTests, os.F_OK): os.remove(pathToTests) # download the tests print "downloading tests from %s" % self.testurl download_url(self.testurl, pathToTests) print "extracting test files to %s" % pathToTests tempZipFile = zipfile.ZipFile(pathToTests) tempZipFile.extractall(path=self.testinstalldir) print "finished downloading test files" return self.testinstalldir
def test_download(self, get): self.data = """ hello, this is a response. """ * (1024 * 16) def iter_content(chunk_size=1): rest = self.data while rest: chunk = rest[:chunk_size] rest = rest[chunk_size:] yield chunk response = Mock(headers={'Content-length': str(len(self.data))}, iter_content=iter_content) get.return_value = response fname = os.path.join(self.tempdir, 'some.content') utils.download_url('http://toto', fname) self.assertEquals(self.data, open(fname).read())
def download_build(self, installdir='downloadedbuild', appname='firefox', macAppName='Minefield.app'): self.installdir = os.path.abspath(installdir) buildName = os.path.basename(self.url) pathToBuild = os.path.join(os.path.dirname(os.path.abspath(__file__)), buildName) # delete the build if it already exists if os.access(pathToBuild, os.F_OK): os.remove(pathToBuild) # download the build print "downloading build" download_url(self.url, pathToBuild) # install the build print "installing %s" % pathToBuild shutil.rmtree(self.installdir, True) MozInstaller(src=pathToBuild, dest=self.installdir, dest_app=macAppName) # remove the downloaded archive os.remove(pathToBuild) # calculate path to binary platform = get_platform() if platform['name'] == 'Mac': binary = '%s/%s/Contents/MacOS/%s-bin' % (installdir, macAppName, appname) else: binary = '%s/%s/%s%s' % (installdir, appname, appname, '.exe' if platform['name'] == 'Windows' else '') return binary
def download_build(self, installdir='downloadedbuild', appname='firefox', macAppName='Minefield.app'): self.installdir = os.path.abspath(installdir) buildName = os.path.basename(self.url) pathToBuild = os.path.join(os.path.dirname(os.path.abspath(__file__)), buildName) # delete the build if it already exists if os.access(pathToBuild, os.F_OK): os.remove(pathToBuild) # download the build print "downloading build" download_url(self.url, pathToBuild) # install the build print "installing %s" % pathToBuild shutil.rmtree(self.installdir, True) MozInstaller(src=pathToBuild, dest=self.installdir, dest_app=macAppName) # remove the downloaded archive os.remove(pathToBuild) # calculate path to binary platform = get_platform() if platform['name'] == 'Mac': binary = '%s/%s/Contents/MacOS/%s-bin' % (installdir, macAppName, appname) else: binary = '%s/%s/%s%s' % (installdir, appname, appname, '.exe' if platform['name'] == 'Windows' else '') return os.path.abspath(binary)
def _download(self, url, dest): self._logger.info("Downloading build from: %s" % url) download_url(url, dest)