def on_chunk_complete(info): self._on_file_complete(info) if info['status'] == 'done': if cryptotool.calculate_md5_sum(info['result']) != info['md5_sum']: raise MD5SumError('md5 sum mismatch', info) priority = int(os.path.basename(info['src'])[-3:]) results[priority] = os.path.join(info['dst'], os.path.basename(info['src']))
def __init__(self, path, md5_sum=None, size=None): self.path = path self.name = os.path.basename(self.path) self.md5_sum = md5_sum self.size = size if not _is_remote_path(path): assert os.path.isfile(path), path if self.size is None: self.size = os.path.getsize(path) if self.md5_sum is None: self.md5_sum = cryptotool.calculate_md5_sum(path)
def make_file(name=None, size=None): name = name or uuid.uuid4().hex file_path = os.path.join(tmp_dir, name) if size is None: size = random.randint(2, 20) size_bytes = size * 1024 * 1024 subprocess.call([ "dd", "if=/dev/urandom", "of=%s" % file_path, "bs=1M", "count=%s" % size ], stdout=open('/dev/null', 'w'), stderr=subprocess.STDOUT, close_fds=True) md5_sum = cryptotool.calculate_md5_sum(file_path) gotten_size = os.path.getsize(file_path) assert gotten_size == size_bytes, gotten_size LOG.debug('create file %s with size %sMB, md5sum %s' % (file_path, size, md5_sum)) return file_path, size_bytes, md5_sum
def __init__(self, path): self.src = open(path, 'rb') self.md5 = cryptotool.calculate_md5_sum(path)
def __init__(self, path): self.src = path self.name = os.path.basename(path) self.md5 = cryptotool.calculate_md5_sum(path)
def i_expect_original_items_downloaded(context): sources_md5_sum = [source.md5 for source in context.sources] for f in context.downloaded_files: assert_msg = 'md5(%s) not in %s' % (f, sources_md5_sum) assert cryptotool.calculate_md5_sum(f) in sources_md5_sum, assert_msg