def get_package(self, pref, dest_folder, remote, output, recorder): conanfile_path = self._cache.package_layout(pref.ref).conanfile() self._hook_manager.execute("pre_download_package", conanfile_path=conanfile_path, reference=pref.ref, package_id=pref.id, remote=remote) output.info("Retrieving package %s from remote '%s' " % (pref.id, remote.name)) rm_conandir(dest_folder) # Remove first the destination folder t1 = time.time() try: pref = self._resolve_latest_pref(pref, remote) snapshot = self._call_remote(remote, "get_package_snapshot", pref) if not is_package_snapshot_complete(snapshot): raise PackageNotFoundException(pref) zipped_files = self._call_remote(remote, "get_package", pref, dest_folder) package_checksums = calc_files_checksum(zipped_files) with self._cache.package_layout( pref.ref).update_metadata() as metadata: metadata.packages[pref.id].revision = pref.revision metadata.packages[pref.id].recipe_revision = pref.ref.revision metadata.packages[pref.id].checksums = package_checksums duration = time.time() - t1 log_package_download(pref, duration, remote, zipped_files) unzip_and_get_files(zipped_files, dest_folder, PACKAGE_TGZ_NAME, output=self._output) # Issue #214 https://github.com/conan-io/conan/issues/214 touch_folder(dest_folder) if get_env("CONAN_READ_ONLY_CACHE", False): make_read_only(dest_folder) recorder.package_downloaded(pref, remote.url) output.success('Package installed %s' % pref.id) except NotFoundException: raise PackageNotFoundException(pref) except BaseException as e: output.error("Exception while getting package: %s" % str(pref.id)) output.error("Exception: %s %s" % (type(e), str(e))) try: output.warn("Trying to remove package folder: %s" % dest_folder) rmdir(dest_folder) except OSError as e: raise ConanException( "%s\n\nCouldn't remove folder '%s', might be busy or open. " "Close any app using it, and retry" % (str(e), dest_folder)) raise self._hook_manager.execute("post_download_package", conanfile_path=conanfile_path, reference=pref.ref, package_id=pref.id, remote=remote)
def package(self): """Generate the info txt files and calls the conanfile package method. """ # FIXME: Is weak to assign here the recipe_hash manifest = self._client_cache.load_manifest(self._conan_ref) self._conan_file.info.recipe_hash = manifest.summary_hash # Creating ***info.txt files save(os.path.join(self.build_folder, CONANINFO), self._conan_file.info.dumps()) self._out.info("Generated %s" % CONANINFO) save(os.path.join(self.build_folder, BUILD_INFO), TXTGenerator(self._conan_file).content) self._out.info("Generated %s" % BUILD_INFO) os.chdir(self.build_folder) if getattr(self._conan_file, 'no_copy_source', False): source_folder = self.source_folder else: source_folder = self.build_folder with get_env_context_manager(self._conan_file): install_folder = self.build_folder # While installing, the infos goes to build folder pkg_id = self._conan_file.info.package_id() create_package(self._conan_file, pkg_id, source_folder, self.build_folder, self.package_folder, install_folder, self._out) if get_env("CONAN_READ_ONLY_CACHE", False): make_read_only(self.package_folder)
def get_package(self, package_reference, dest_folder, remote, output, recorder): package_id = package_reference.package_id output.info("Retrieving package %s from remote '%s' " % (package_id, remote.name)) rm_conandir(dest_folder) # Remove first the destination folder t1 = time.time() try: urls = self._call_remote(remote, "get_package_urls", package_reference) zipped_files = self._call_remote(remote, "download_files_to_folder", urls, dest_folder) duration = time.time() - t1 log_package_download(package_reference, duration, remote, zipped_files) unzip_and_get_files(zipped_files, dest_folder, PACKAGE_TGZ_NAME) # Issue #214 https://github.com/conan-io/conan/issues/214 touch_folder(dest_folder) if get_env("CONAN_READ_ONLY_CACHE", False): make_read_only(dest_folder) recorder.package_downloaded(package_reference, remote.url) output.success('Package installed %s' % package_id) except NotFoundException: raise NotFoundException("Package binary '%s' not found in '%s'" % (package_reference, remote.name)) except BaseException as e: output.error("Exception while getting package: %s" % str(package_reference.package_id)) output.error("Exception: %s %s" % (type(e), str(e))) try: output.warn("Trying to remove package folder: %s" % dest_folder) rmdir(dest_folder) except OSError as e: raise ConanException("%s\n\nCouldn't remove folder '%s', might be busy or open. Close any app " "using it, and retry" % (str(e), dest_folder)) raise
def _package(self, conanfile, pref, package_layout, conanfile_path): # FIXME: Is weak to assign here the recipe_hash manifest = package_layout.recipe_manifest() conanfile.info.recipe_hash = manifest.summary_hash # Creating ***info.txt files save(os.path.join(conanfile.folders.base_build, CONANINFO), conanfile.info.dumps()) self._output.info("Generated %s" % CONANINFO) save(os.path.join(conanfile.folders.base_build, BUILD_INFO), TXTGenerator(conanfile).content) self._output.info("Generated %s" % BUILD_INFO) package_id = pref.id # Do the actual copy, call the conanfile.package() method # While installing, the infos goes to build folder conanfile.folders.set_base_install(conanfile.folders.base_build) prev = run_package_method(conanfile, package_id, self._hook_manager, conanfile_path, pref.ref) update_package_metadata(prev, package_layout, package_id, pref.ref.revision) if get_env("CONAN_READ_ONLY_CACHE", False): make_read_only(conanfile.folders.base_package) # FIXME: Conan 2.0 Clear the registry entry (package ref) return prev
def package(self): """Generate the info txt files and calls the conanfile package method. Receives que build_folder because it can change if build_id() method exists""" # FIXME: Is weak to assign here the recipe_hash manifest = self._client_cache.load_manifest(self._conan_ref) self._conan_file.info.recipe_hash = manifest.summary_hash # Creating ***info.txt files save(os.path.join(self.build_folder, CONANINFO), self._conan_file.info.dumps()) self._out.info("Generated %s" % CONANINFO) save(os.path.join(self.build_folder, BUILD_INFO), TXTGenerator(self._conan_file).content) self._out.info("Generated %s" % BUILD_INFO) os.chdir(self.build_folder) if getattr(self._conan_file, 'no_copy_source', False): source_folder = self._client_cache.source( self._conan_ref, self._conan_file.short_paths) else: source_folder = self.build_folder with environment_append(self._conan_file.env): package_folder = self._client_cache.package( self._package_reference, self._conan_file.short_paths) install_folder = self.build_folder # While installing, the infos goes to build folder create_package(self._conan_file, source_folder, self.build_folder, package_folder, install_folder, self._out) if get_env("CONAN_READ_ONLY_CACHE", False): make_read_only(package_folder)
def get_package(self, package_reference, dest_folder, remote, output, recorder): package_id = package_reference.package_id conanfile_path = self._client_cache.conanfile(package_reference.conan) self._hook_manager.execute("pre_download_package", conanfile_path=conanfile_path, reference=package_reference.conan, package_id=package_id, remote=remote) output.info("Retrieving package %s from remote '%s' " % (package_id, remote.name)) rm_conandir(dest_folder) # Remove first the destination folder t1 = time.time() try: zipped_files, new_ref, rev_time = self._call_remote( remote, "get_package", package_reference, dest_folder) with self._client_cache.update_metadata(new_ref.conan) as metadata: metadata.packages[ new_ref.package_id].revision = new_ref.revision metadata.packages[ new_ref. package_id].recipe_revision = new_ref.conan.revision metadata.packages[new_ref.package_id].time = rev_time duration = time.time() - t1 log_package_download(package_reference, duration, remote, zipped_files) unzip_and_get_files(zipped_files, dest_folder, PACKAGE_TGZ_NAME, output=self._output) # Issue #214 https://github.com/conan-io/conan/issues/214 touch_folder(dest_folder) if get_env("CONAN_READ_ONLY_CACHE", False): make_read_only(dest_folder) recorder.package_downloaded(package_reference, remote.url) output.success('Package installed %s' % package_id) except NotFoundException: raise NotFoundException("Package binary '%s' not found in '%s'" % (package_reference, remote.name)) except BaseException as e: output.error("Exception while getting package: %s" % str(package_reference.package_id)) output.error("Exception: %s %s" % (type(e), str(e))) try: output.warn("Trying to remove package folder: %s" % dest_folder) rmdir(dest_folder) except OSError as e: raise ConanException( "%s\n\nCouldn't remove folder '%s', might be busy or open. Close any app " "using it, and retry" % (str(e), dest_folder)) raise self._hook_manager.execute("post_download_package", conanfile_path=conanfile_path, reference=package_reference.conan, package_id=package_id, remote=remote) return new_ref
def _get_remote_package(self, conan_file, package_reference, output, package_folder): """Get remote package. It won't check if it's outdated""" # Compute conan_file package from local (already compiled) or from remote # If already exists do not dirt the output, the common situation # is that package is already installed and OK. If don't, the proxy # will print some other message about it if not os.path.exists(package_folder): output.info("Retrieving package %s" % package_reference.package_id) try: if self._remote_proxy.get_package( package_reference, short_paths=conan_file.short_paths): _handle_system_requirements(conan_file, package_reference, self._client_cache, output) if get_env("CONAN_READ_ONLY_CACHE", False): make_read_only(package_folder) return True except ConanManifestException: raise # If is a manifest verify exception, do NOT remove folder except BaseException as e: output.error("Exception while getting package: %s" % str(package_reference.package_id)) output.error("Exception: %s %s" % (type(e), str(e))) try: output.warn("Trying to remove package folder: %s" % package_folder) rm_conandir(package_folder) except OSError as e: raise ConanException( "%s\n\nCouldn't remove folder '%s', might be busy or open. Close any app " "using it, and retry" % (str(e), package_folder)) raise _raise_package_not_found_error(conan_file, package_reference.conan, package_reference.package_id, output)
def get_package(conanfile, package_ref, package_folder, output, recorder, proxy, update): # TODO: This access to proxy attributes has to be improved remote_manager = proxy._remote_manager registry = proxy.registry try: if update: _remove_if_outdated(package_folder, package_ref, proxy, output) local_package = os.path.exists(package_folder) if local_package: output.success('Already installed!') log_package_got_from_local_cache(package_ref) recorder.package_fetched_from_cache(package_ref) return False else: remote = registry.get_ref(package_ref.conan) # remote will be defined, as package availability has been checked from installer remote_manager.get_package(conanfile, package_ref, package_folder, remote, output, recorder) if get_env("CONAN_READ_ONLY_CACHE", False): make_read_only(package_folder) recorder.package_downloaded(package_ref, remote.url) return True except BaseException as e: output.error("Exception while getting package: %s" % str(package_ref.package_id)) output.error("Exception: %s %s" % (type(e), str(e))) _clean_package(package_folder, output) raise
def _package(self, conanfile, pref, package_layout, conanfile_path, build_folder, package_folder): # FIXME: Is weak to assign here the recipe_hash manifest = package_layout.recipe_manifest() conanfile.info.recipe_hash = manifest.summary_hash # Creating ***info.txt files save(os.path.join(build_folder, CONANINFO), conanfile.info.dumps()) self._output.info("Generated %s" % CONANINFO) save(os.path.join(build_folder, BUILD_INFO), TXTGenerator(conanfile).content) self._output.info("Generated %s" % BUILD_INFO) package_id = pref.id # Do the actual copy, call the conanfile.package() method with get_env_context_manager(conanfile): # Could be source or build depends no_copy_source source_folder = conanfile.source_folder install_folder = build_folder # While installing, the infos goes to build folder prev = run_package_method(conanfile, package_id, source_folder, build_folder, package_folder, install_folder, self._hook_manager, conanfile_path, pref.ref) update_package_metadata(prev, package_layout, package_id, pref.ref.revision) if get_env("CONAN_READ_ONLY_CACHE", False): make_read_only(package_folder) # FIXME: Conan 2.0 Clear the registry entry (package ref) return prev
def package(self): """Generate the info txt files and calls the conanfile package method. """ # FIXME: Is weak to assign here the recipe_hash manifest = self._client_cache.load_manifest(self._conan_ref) self._conan_file.info.recipe_hash = manifest.summary_hash # Creating ***info.txt files save(os.path.join(self.build_folder, CONANINFO), self._conan_file.info.dumps()) self._out.info("Generated %s" % CONANINFO) save(os.path.join(self.build_folder, BUILD_INFO), TXTGenerator(self._conan_file).content) self._out.info("Generated %s" % BUILD_INFO) os.chdir(self.build_folder) if getattr(self._conan_file, 'no_copy_source', False): source_folder = self.source_folder else: source_folder = self.build_folder with get_env_context_manager(self._conan_file): install_folder = self.build_folder # While installing, the infos goes to build folder create_package(self._conan_file, source_folder, self.build_folder, self.package_folder, install_folder, self._out) if get_env("CONAN_READ_ONLY_CACHE", False): make_read_only(self.package_folder)
def read_only_test(self): folder = temp_folder() f = os.path.join(folder, "file.txt") save(f, "Hello World") make_read_only(folder) with self.assertRaises(IOError): save(f, "Bye World") self.assertEqual("Hello World", load(f))
def _get_package(self, layout, pref, remote, output, recorder, info): t1 = time.time() try: headers = _headers_for_info(info) pref = self._resolve_latest_pref(pref, remote, headers=headers) snapshot = self._call_remote(remote, "get_package_snapshot", pref) if not is_package_snapshot_complete(snapshot): raise PackageNotFoundException(pref) download_pkg_folder = layout.download_package(pref) # Download files to the pkg_tgz folder, not to the final one zipped_files = self._call_remote(remote, "get_package", pref, download_pkg_folder) # Compute and update the package metadata package_checksums = calc_files_checksum(zipped_files) with layout.update_metadata() as metadata: metadata.packages[pref.id].revision = pref.revision metadata.packages[pref.id].recipe_revision = pref.ref.revision metadata.packages[pref.id].checksums = package_checksums metadata.packages[pref.id].remote = remote.name duration = time.time() - t1 log_package_download(pref, duration, remote, zipped_files) tgz_file = zipped_files.pop(PACKAGE_TGZ_NAME, None) check_compressed_files(PACKAGE_TGZ_NAME, zipped_files) package_folder = layout.package(pref) if tgz_file: # This must happen always, but just in case # TODO: The output could be changed to the package one, but uncompress_file(tgz_file, package_folder, output=self._output) mkdir( package_folder ) # Just in case it doesn't exist, because uncompress did nothing for file_name, file_path in zipped_files.items( ): # copy CONANINFO and CONANMANIFEST shutil.move(file_path, os.path.join(package_folder, file_name)) # Issue #214 https://github.com/conan-io/conan/issues/214 touch_folder(package_folder) if get_env("CONAN_READ_ONLY_CACHE", False): make_read_only(package_folder) recorder.package_downloaded(pref, remote.url) output.success('Package installed %s' % pref.id) output.info("Downloaded package revision %s" % pref.revision) except NotFoundException: raise PackageNotFoundException(pref) except BaseException as e: output.error("Exception while getting package: %s" % str(pref.id)) output.error("Exception: %s %s" % (type(e), str(e))) raise
def package(self): """Generate the info txt files and calls the conanfile package method. """ # FIXME: Is weak to assign here the recipe_hash manifest = self._cache.package_layout(self._ref).recipe_manifest() self._conan_file.info.recipe_hash = manifest.summary_hash # Creating ***info.txt files save(os.path.join(self.build_folder, CONANINFO), self._conan_file.info.dumps()) self._out.info("Generated %s" % CONANINFO) save(os.path.join(self.build_folder, BUILD_INFO), TXTGenerator(self._conan_file).content) self._out.info("Generated %s" % BUILD_INFO) os.chdir(self.build_folder) if getattr(self._conan_file, 'no_copy_source', False): source_folder = self.source_folder else: source_folder = self.build_folder with get_env_context_manager(self._conan_file): install_folder = self.build_folder # While installing, the infos goes to build folder pkg_id = self._pref.id conanfile_path = self._cache.conanfile(self._ref) create_package(self._conan_file, pkg_id, source_folder, self.build_folder, self.package_folder, install_folder, self._hook_manager, conanfile_path, self._ref) layout = self._cache.package_layout(self._pref.ref, self._conan_file.short_paths) package_hash = layout.package_summary_hash(self._pref) package_id = self._pref.id with self._cache.package_layout(self._ref).update_metadata() as metadata: if metadata.packages[package_id].revision != package_hash: metadata.packages[package_id].revision = package_hash metadata.packages[package_id].recipe_revision = self._ref.revision if get_env("CONAN_READ_ONLY_CACHE", False): make_read_only(self.package_folder)
def _get_remote_package(self, conan_file, package_reference, output): """Get remote package. It won't check if it's outdated""" # Compute conan_file package from local (already compiled) or from remote package_folder = self._client_cache.package(package_reference, conan_file.short_paths) # If already exists do not dirt the output, the common situation # is that package is already installed and OK. If don't, the proxy # will print some other message about it if not os.path.exists(package_folder): self._out.info("Retrieving package %s" % package_reference.package_id) if self._remote_proxy.get_package(package_reference, short_paths=conan_file.short_paths): _handle_system_requirements(conan_file, package_reference, self._client_cache, output) if get_env("CONAN_READ_ONLY_CACHE", False): make_read_only(package_folder) return True _raise_package_not_found_error(conan_file, package_reference.conan, output)