Updates the package cache at package_root for the given dictionary of packages as well as packages in the given local package path.
(package_root, remote_packages, local_package_path, refresh=False)
| 209 | |
| 210 | |
| 211 | def update_cache(package_root, remote_packages, local_package_path, refresh=False): |
| 212 | """Updates the package cache at package_root for the given dictionary |
| 213 | of packages as well as packages in the given local package path. |
| 214 | """ |
| 215 | requires_wipe = False |
| 216 | if refresh: |
| 217 | click.echo("Force package cache refresh.") |
| 218 | requires_wipe = True |
| 219 | |
| 220 | manifest_file = os.path.join(package_root, "lektor-packages.manifest") |
| 221 | local_packages = list_local_packages(local_package_path) |
| 222 | |
| 223 | old_manifest = load_manifest(manifest_file) |
| 224 | to_install = [] |
| 225 | |
| 226 | all_packages = dict(remote_packages) |
| 227 | all_packages.update((x, None) for x in local_packages) |
| 228 | |
| 229 | # step 1: figure out which remote packages to install. |
| 230 | for package, version in remote_packages.items(): |
| 231 | old_version = old_manifest.pop(package, None) |
| 232 | if old_version is None: |
| 233 | to_install.append((package, version)) |
| 234 | elif old_version != version: |
| 235 | requires_wipe = True |
| 236 | |
| 237 | # step 2: figure out which local packages to install |
| 238 | for package in local_packages: |
| 239 | if old_manifest.pop(package, False) is False: |
| 240 | to_install.append((package, None)) |
| 241 | |
| 242 | # Bad news, we need to wipe everything |
| 243 | if requires_wipe or old_manifest: |
| 244 | try: |
| 245 | shutil.rmtree(package_root) |
| 246 | except OSError: |
| 247 | pass |
| 248 | to_install = all_packages.items() |
| 249 | |
| 250 | if to_install: |
| 251 | click.echo("Updating packages in %s for project" % package_root) |
| 252 | try: |
| 253 | os.makedirs(package_root) |
| 254 | except OSError: |
| 255 | pass |
| 256 | for package, version in to_install: |
| 257 | if package[:1] == "@": |
| 258 | install_local_package( |
| 259 | package_root, os.path.join(local_package_path, package[1:]) |
| 260 | ) |
| 261 | else: |
| 262 | download_and_install_package(package_root, package, version) |
| 263 | write_manifest(manifest_file, all_packages) |
| 264 | |
| 265 | |
| 266 | def add_site(path): |
no test coverage detected