def iter_package_info(self): '''Iterate over ghost_package, blob_id, locator for this section. The directory is visited recursively and in a repeatable order. ''' for root, dirnames, files in os.walk(self.full_path, topdown = True): dirnames.sort() files.sort() for candidate in files: full_path = pjoin(root, candidate) try: package_type = get_package_type(filename = candidate) except UnknownPackageTypeError: # if we don't know the the file is, we skip it. continue control = package_type.extract_header(full_path) iterator = gen_file_fragments(full_path) md51_digest = md5() for block in iterator: md51_digest.update(block) size = get_size(full_path) blob_id = 'md5:' + md51_digest.hexdigest() url = 'file://' + cpath(root) locator = FileLocator(url, candidate, blob_id, size, self.loader_factory) package = package_type.parse(control, blob_id) yield package, control, blob_id, locator for extra_blob_id, extra_size, extra_filename \ in package.extra_files: make_extra = locator.make_extra_file_locator extra_locator = make_extra(extra_filename, extra_blob_id, extra_size) yield None, None, extra_blob_id, extra_locator
def iter_package_info(self): '''Iterate over ghost_package, blob_id, locator for this section. The directory is visited recursively and in a repeatable order. ''' for root, dirnames, files in os.walk(self.full_path, topdown=True): dirnames.sort() files.sort() for candidate in files: full_path = pjoin(root, candidate) try: package_type = get_package_type(filename=candidate) except UnknownPackageTypeError: # if we don't know the the file is, we skip it. continue control = package_type.extract_header(full_path) iterator = gen_file_fragments(full_path) md51_digest = md5() for block in iterator: md51_digest.update(block) size = get_size(full_path) blob_id = 'md5:' + md51_digest.hexdigest() url = 'file://' + cpath(root) locator = FileLocator(url, candidate, blob_id, size, self.loader_factory) package = package_type.parse(control, blob_id) yield package, control, blob_id, locator for extra_blob_id, extra_size, extra_filename \ in package.extra_files: make_extra = locator.make_extra_file_locator extra_locator = make_extra(extra_filename, extra_blob_id, extra_size) yield None, None, extra_blob_id, extra_locator
def test_create_directories(self): all_dirs = self.repo.get_all_dirs() assert cpath('repo', 'dists', 'happy', 'main', 'binary-i386') \ in all_dirs assert cpath('repo', 'dists', 'happy', 'main', 'binary-sparc') \ in all_dirs assert cpath('repo', 'dists', 'happy', 'main', 'source') \ in all_dirs assert cpath('repo', 'dists', 'happy', 'contrib', 'binary-i386') \ in all_dirs assert cpath('repo', 'dists', 'happy', 'contrib', 'binary-sparc') \ in all_dirs assert cpath('repo', 'dists', 'happy', 'contrib', 'source') \ in all_dirs self.assert_equals(6, len(all_dirs)) self.repo.make_all_dirs() for expected_dir in all_dirs: assert os.path.isdir(expected_dir)