Example #1
0
    def process(self):
        progress = Progress('hashing')

        __LOG__.debug(
            'hashing %d files (%s)',
            len(self._queue),
            sizeof_fmt(self.bytes_to_hash)
        )
        progress.start(self, maxval=self.bytes_to_hash)
        for (file_path, file_size, dest) in self._queue:
            __LOG__.debug(
                'hashing %s (%s)...',
                quote(file_path),
                sizeof_fmt(file_size)
            )
            try:
                hash_values = hashfile(file_path)
            except Exception as err:
                __LOG__.exception('hashing of %s failed: ', file_path)
                self.errors.append(err)
            else:
                dest.update(hash_values)
                self.processed.append(dest)
            self.bytes_processed = self.bytes_processed + file_size
            progress.update(self, val=self.bytes_processed)
        progress.finish(self)
        __LOG__.debug('%d files hashed', len(self.processed))
        return self.processed
Example #2
0
 def test_should_format_bytes_correctly(self):
     self.assertEqual(sizeof_fmt(0), '0.0B')
     self.assertEqual(sizeof_fmt(5), '5.0B')
Example #3
0
 def test_should_format_yotabytes_correctly(self):
     self.assertEqual(sizeof_fmt(42 * 1024 ** 8), '42.0YiB')
Example #4
0
 def test_should_format_gigabytes_correctly(self):
     self.assertEqual(sizeof_fmt(7.8 * 1024 ** 3), '7.8GiB')