(cache_dir, url, full_repodata, used_packages, info)
| 139 | return full_repodata |
| 140 | |
| 141 | def write_repodata(cache_dir, url, full_repodata, used_packages, info): |
| 142 | used_repodata = { |
| 143 | k: full_repodata[k] |
| 144 | for k in set(full_repodata.keys()) - {"packages", "packages.conda", "removed"} |
| 145 | } |
| 146 | used_repodata["packages.conda"] = {} |
| 147 | used_repodata["removed"] = [] |
| 148 | used_repodata["packages"] = { |
| 149 | k: v for k, v in full_repodata["packages"].items() if v["name"] in NAV_APPS |
| 150 | } |
| 151 | |
| 152 | # Minify the included repodata |
| 153 | for package in used_packages: |
| 154 | key = "packages.conda" if package.endswith(".conda") else "packages" |
| 155 | if package in full_repodata.get(key, {}): |
| 156 | used_repodata[key][package] = full_repodata[key][package] |
| 157 | continue |
| 158 | # If we're transcoding packages, fix-up the metadata |
| 159 | if package.endswith(".conda"): |
| 160 | original_package = package[: -len(".conda")] + ".tar.bz2" |
| 161 | original_key = "packages" |
| 162 | elif package.endswith(".tar.bz2"): |
| 163 | original_package = package[: -len(".tar.bz2")] + ".conda" |
| 164 | original_key = "packages.conda" |
| 165 | else: |
| 166 | raise NotImplementedError("Package type is unknown for: %s" % package) |
| 167 | if original_package in full_repodata.get(original_key, {}): |
| 168 | data = deepcopy(full_repodata[original_key][original_package]) |
| 169 | pkg_fn = join(info["_download_dir"], package) |
| 170 | data["size"] = os.stat(pkg_fn).st_size |
| 171 | data["sha256"] = hash_files([pkg_fn], algorithm="sha256") |
| 172 | data["md5"] = hash_files([pkg_fn]) |
| 173 | used_repodata[key][package] = data |
| 174 | |
| 175 | # In conda <23.1, the first line of the JSON should contain cache metadata |
| 176 | # Choose an arbitrary old, expired date, so that conda will want to |
| 177 | # immediately update it when not being run in offline mode |
| 178 | repodata_url = used_repodata.pop("_url", url).rstrip("/") |
| 179 | used_repodata.pop("_mod", None) |
| 180 | repodata = json.dumps(used_repodata, indent=2) |
| 181 | mod_time = "Mon, 07 Jan 2019 15:22:15 GMT" |
| 182 | repodata_header = json.dumps( |
| 183 | { |
| 184 | "_mod": mod_time, |
| 185 | "_url": repodata_url, |
| 186 | } |
| 187 | ) |
| 188 | repodata = repodata_header[:-1] + "," + repodata[1:] |
| 189 | repodata_filepath = join(cache_dir, _cache_fn_url(repodata_url)) |
| 190 | with open(repodata_filepath, "w") as fh: |
| 191 | fh.write(repodata) |
| 192 | |
| 193 | # set the modification time to mod_time. needed for mamba |
| 194 | mod_time_datetime = datetime.datetime.strptime(mod_time, "%a, %d %b %Y %H:%M:%S %Z") |
| 195 | mod_time_s = int(mod_time_datetime.timestamp()) |
| 196 | os.utime(repodata_filepath, times=(mod_time_s, mod_time_s)) |
| 197 | |
| 198 | # TODO: write the state.json file, for conda >23.1 |
no test coverage detected