def quetz_harvest(package_version: dict, config, pkgstore: PackageStore, dao: Dao): filename: str = package_version["filename"] channel: str = package_version["channel_name"] platform = package_version["platform"] print(f"Harvesting: {filename}, {channel}, {platform}") # TODO figure out how to handle properly either .conda or .tar.bz2 if not filename.endswith('.tar.bz2'): return fh = pkgstore.serve_path(channel, Path(platform) / filename) print("Harvesting ... ") try: result = harvest(fh) except Exception as e: print(f"Exception caught in harvesting: {str(e)}") return print(f"Uploading harvest result for {channel}/{platform}/{filename}") pkgstore.add_file( json.dumps(result, indent=4, sort_keys=True), channel, Path("metadata") / platform / filename.replace('.tar.bz2', '.json'), )
def test_validate_packages( config, user, package_files, channel, channel_name, db, dao, pkgstore: PackageStore, package_filenames, ): user_id = user.id reindex_packages_from_store(dao, config, channel.name, user_id) db.refresh(channel) assert channel.packages assert channel.packages[0].name == "test-package" assert channel.packages[0].members[0].user.username == user.username assert (channel.packages[0].package_versions[0].version == '0.1' or channel.packages[0].package_versions[0].version == '0.2') assert (channel.packages[0].package_versions[1].version == '0.1' or channel.packages[0].package_versions[1].version == '0.2') repodata = pkgstore.serve_path(channel.name, "linux-64/repodata.json") repodata = json.load(repodata) assert repodata assert len(repodata['packages']) == 2 assert set(repodata["packages"].keys()) == set(package_filenames) remaining_pkg = channel.packages[0].package_versions[1].filename pkgstore.delete_file( channel.name, f'linux-64/{channel.packages[0].package_versions[0].filename}') validate_packages(dao, pkgstore, channel_name) db.refresh(channel) repodata = pkgstore.serve_path(channel.name, "linux-64/repodata.json") repodata = json.load(repodata) assert repodata assert len(repodata['packages']) == 1 assert set(repodata["packages"].keys()) == set([remaining_pkg]) assert len(channel.packages[0].package_versions) == 1 pkgstore.add_file(b"wrong_size", channel_name, f"linux-64/{remaining_pkg}") validate_packages(dao, pkgstore, channel_name) db.refresh(channel) repodata = pkgstore.serve_path(channel.name, "linux-64/repodata.json") repodata = json.load(repodata) assert repodata assert len(repodata['packages']) == 0 assert set(repodata["packages"].keys()) == set([]) assert len(channel.packages[0].package_versions) == 0
def package_files(pkgstore: PackageStore, channel_name, package_filenames): pkgstore.create_channel(channel_name) for filename in package_filenames: with open(filename, 'rb') as fid: content = fid.read() pkgstore.add_file(content, channel_name, f"linux-64/{filename}")