def test_checksums(self): """Test checksum functionality.""" fh, fp = tempfile.mkstemp() os.close(fh) ft.write_file(fp, "easybuild\n") known_checksums = { 'adler32': '0x379257805', 'crc32': '0x1457143216', 'md5': '7167b64b1ca062b9674ffef46f9325db', 'sha1': 'db05b79e09a4cc67e9dd30b313b5488813db3190', } # make sure checksums computation/verification is correct for checksum_type, checksum in known_checksums.items(): self.assertEqual( ft.compute_checksum(fp, checksum_type=checksum_type), checksum) self.assertTrue(ft.verify_checksum(fp, (checksum_type, checksum))) # md5 is default self.assertEqual(ft.compute_checksum(fp), known_checksums['md5']) self.assertTrue(ft.verify_checksum(fp, known_checksums['md5'])) # make sure faulty checksums are reported broken_checksums = dict([(typ, val + 'foo') for (typ, val) in known_checksums.items()]) for checksum_type, checksum in broken_checksums.items(): self.assertFalse( ft.compute_checksum(fp, checksum_type=checksum_type) == checksum) self.assertFalse(ft.verify_checksum(fp, (checksum_type, checksum))) # md5 is default self.assertFalse(ft.compute_checksum(fp) == broken_checksums['md5']) self.assertFalse(ft.verify_checksum(fp, broken_checksums['md5'])) # cleanup os.remove(fp)
def test_checksums(self): """Test checksum functionality.""" fh, fp = tempfile.mkstemp() os.close(fh) ft.write_file(fp, "easybuild\n") known_checksums = { 'adler32': '0x379257805', 'crc32': '0x1457143216', 'md5': '7167b64b1ca062b9674ffef46f9325db', 'sha1': 'db05b79e09a4cc67e9dd30b313b5488813db3190', } # make sure checksums computation/verification is correct for checksum_type, checksum in known_checksums.items(): self.assertEqual(ft.compute_checksum(fp, checksum_type=checksum_type), checksum) self.assertTrue(ft.verify_checksum(fp, (checksum_type, checksum))) # md5 is default self.assertEqual(ft.compute_checksum(fp), known_checksums['md5']) self.assertTrue(ft.verify_checksum(fp, known_checksums['md5'])) # make sure faulty checksums are reported broken_checksums = dict([(typ, val + 'foo') for (typ, val) in known_checksums.items()]) for checksum_type, checksum in broken_checksums.items(): self.assertFalse(ft.compute_checksum(fp, checksum_type=checksum_type) == checksum) self.assertFalse(ft.verify_checksum(fp, (checksum_type, checksum))) # md5 is default self.assertFalse(ft.compute_checksum(fp) == broken_checksums['md5']) self.assertFalse(ft.verify_checksum(fp, broken_checksums['md5'])) # cleanup os.remove(fp)
def prepare_step(self, *args, **kwargs): """Prepare environment for installing OpenCV.""" super(EB_OpenCV, self).prepare_step(*args, **kwargs) self.pylibdir = det_pylibdir() if get_cpu_architecture() == X86_64: # IPP are Intel's Integrated Performance Primitives - so only make sense on X86_64 ippicv_tgz = glob.glob(os.path.join(self.builddir, 'ippicv*.tgz')) if ippicv_tgz: if len(ippicv_tgz) == 1: # copy ippicv tarball in the right place # expected location is 3rdparty/ippicv/downloads/linux-<md5sum>/ ippicv_tgz = ippicv_tgz[0] ippicv_tgz_md5 = compute_checksum(ippicv_tgz, checksum_type='md5') target_subdir = os.path.join('3rdparty', 'ippicv', 'downloads', 'linux-%s' % ippicv_tgz_md5) copy([ippicv_tgz], os.path.join(self.cfg['start_dir'], target_subdir)) self.cfg.update('configopts', '-DWITH_IPP=ON') # for recent OpenCV 3.x versions (and newer), we must also specify the download location # to prevent that the ippicv tarball is re-downloaded if LooseVersion(self.version) >= LooseVersion('3.4.4'): self.cfg.update( 'configopts', '-DOPENCV_DOWNLOAD_PATH=%s' % self.builddir) else: raise EasyBuildError( "Found multiple ippicv*.tgz source tarballs in %s: %s", self.builddir, ippicv_tgz)
def prepare_step(self, *args, **kwargs): """Prepare environment for installing OpenCV.""" super(EB_OpenCV, self).prepare_step(*args, **kwargs) self.pylibdir = det_pylibdir() ippicv_tgz = glob.glob(os.path.join(self.builddir, 'ippicv*.tgz')) if ippicv_tgz: if len(ippicv_tgz) == 1: # copy ippicv tarball in the right place # expected location is 3rdparty/ippicv/downloads/linux-<md5sum>/ ippicv_tgz = ippicv_tgz[0] ippicv_tgz_md5 = compute_checksum(ippicv_tgz, checksum_type='md5') target_subdir = os.path.join('3rdparty', 'ippicv', 'downloads', 'linux-%s' % ippicv_tgz_md5) copy([ippicv_tgz], os.path.join(self.cfg['start_dir'], target_subdir)) self.cfg.update('configopts', '-DWITH_IPP=ON') else: raise EasyBuildError( "Found multiple ippicv*.tgz source tarballs in %s: %s", self.builddir, ippicv_tgz)
def check_config_guess(self): """Check timestamp & SHA256 checksum of config.guess script.""" # log version, timestamp & SHA256 checksum of config.guess that was found (if any) if self.config_guess: # config.guess includes a "timestamp='...'" indicating the version config_guess_version = None version_regex = re.compile("^timestamp='(.*)'", re.M) res = version_regex.search(read_file(self.config_guess)) if res: config_guess_version = res.group(1) config_guess_checksum = compute_checksum(self.config_guess, checksum_type=CHECKSUM_TYPE_SHA256) try: config_guess_timestamp = datetime.fromtimestamp(os.stat(self.config_guess).st_mtime).isoformat() except OSError as err: self.log.warning("Failed to determine timestamp of %s: %s", self.config_guess, err) config_guess_timestamp = None self.log.info("config.guess version: %s (last updated: %s, SHA256 checksum: %s)", config_guess_version, config_guess_timestamp, config_guess_checksum) if config_guess_version != CONFIG_GUESS_VERSION: tup = (self.config_guess, config_guess_version, CONFIG_GUESS_VERSION) print_warning("config.guess version at %s does not match expected version: %s vs %s" % tup) if config_guess_checksum != CONFIG_GUESS_SHA256: tup = (self.config_guess, config_guess_checksum, CONFIG_GUESS_SHA256) print_warning("SHA256 checksum of config.guess at %s does not match expected checksum: %s vs %s" % tup)
def check_config_guess(config_guess): """Check timestamp & SHA256 checksum of config.guess script. :param config_guess: Path to config.guess script to check :return: Whether the script is valid (matches the version and checksum) """ log = fancylogger.getLogger('check_config_guess') # config.guess includes a "timestamp='...'" indicating the version config_guess_version = None version_regex = re.compile("^timestamp='(.*)'", re.M) res = version_regex.search(read_file(config_guess)) if res: config_guess_version = res.group(1) config_guess_checksum = compute_checksum( config_guess, checksum_type=CHECKSUM_TYPE_SHA256) try: config_guess_timestamp = datetime.fromtimestamp( os.stat(config_guess).st_mtime).isoformat() except OSError as err: log.warning("Failed to determine timestamp of %s: %s", config_guess, err) config_guess_timestamp = None log.info( "config.guess version: %s (last updated: %s, SHA256 checksum: %s)", config_guess_version, config_guess_timestamp, config_guess_checksum) result = True # check version & SHA256 checksum before declaring victory if config_guess_version != CONFIG_GUESS_VERSION: result = False log.warning( "config.guess version at %s does not match expected version: %s vs %s", config_guess, config_guess_version, CONFIG_GUESS_VERSION) elif config_guess_checksum != CONFIG_GUESS_SHA256: result = False log.warning( "SHA256 checksum of config.guess at %s does not match expected checksum: %s vs %s", config_guess, config_guess_checksum, CONFIG_GUESS_SHA256) return result
def prepare_step(self, *args, **kwargs): """Prepare environment for installing OpenCV.""" super(EB_OpenCV, self).prepare_step(*args, **kwargs) self.pylibdir = det_pylibdir() ippicv_tgz = glob.glob(os.path.join(self.builddir, 'ippicv*.tgz')) if ippicv_tgz: if len(ippicv_tgz) == 1: # copy ippicv tarball in the right place # expected location is 3rdparty/ippicv/downloads/linux-<md5sum>/ ippicv_tgz = ippicv_tgz[0] ippicv_tgz_md5 = compute_checksum(ippicv_tgz, checksum_type='md5') target_subdir = os.path.join('3rdparty', 'ippicv', 'downloads', 'linux-%s' % ippicv_tgz_md5) copy([ippicv_tgz], os.path.join(self.cfg['start_dir'], target_subdir)) self.cfg.update('configopts', '-DWITH_IPP=ON') else: raise EasyBuildError("Found multiple ippicv*.tgz source tarballs in %s: %s", self.builddir, ippicv_tgz)