def Download(self, package_name, config): if not os.path.exists(PREBUILT_ROOT): util.Makedirs(PREBUILT_ROOT) info = self.packages[(package_name, config)] filename = os.path.join(PREBUILT_ROOT, os.path.basename(info['BIN_URL'])) if os.path.exists(filename): try: util.VerifyHash(filename, info['BIN_SHA1']) return filename except util.HashVerificationError: pass util.Log('Downloading prebuilt binary ...') util.DownloadFile(filename, info['BIN_URL']) util.VerifyHash(filename, info['BIN_SHA1']) return filename
def Download(self, force_mirror=None): """Download upstream sources and verify integrity.""" if self.IsGitUpstream(): self.GitCloneToMirror() return archive = self.DownloadLocation() if not archive: return if force_mirror is None: force_mirror = os.environ.get('FORCE_MIRROR', False) self.DownloadArchive(force_mirror=force_mirror) if self.SHA1 is None: raise PkgFormatError('missing SHA1 attribute: %s' % self.info) util.VerifyHash(archive, self.SHA1) Log('verified: %s' % util.RelPath(archive))
def testVerifyHash(self): util.VerifyHash('foo', 'sha1') with self.assertRaises(util.HashVerificationError): util.VerifyHash('foo', 'sha1x')