MCPcopy
hub / github.com/lektor/lektor / update_cache

Function update_cache

lektor/packages.py:211–263  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

209
210
211def 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
266def add_site(path):

Callers 1

load_packagesFunction · 0.85

Calls 9

list_local_packagesFunction · 0.85
load_manifestFunction · 0.85
install_local_packageFunction · 0.85
write_manifestFunction · 0.85
updateMethod · 0.45
itemsMethod · 0.45
popMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected