def remote(self, *args): """ manage remotes """ parser = argparse.ArgumentParser(description=self.remote.__doc__, prog="conan remote") subparsers = parser.add_subparsers(dest='subcommand', help='sub-command help') # create the parser for the "a" command subparsers.add_parser('list', help='list current remotes') parser_add = subparsers.add_parser('add', help='add a remote') parser_add.add_argument('remote', help='name of the remote') parser_add.add_argument('url', help='url of the remote') parser_rm = subparsers.add_parser('remove', help='remove a remote') parser_rm.add_argument('remote', help='name of the remote') parser_upd = subparsers.add_parser('update', help='update the remote url') parser_upd.add_argument('remote', help='name of the remote') parser_upd.add_argument('url', help='url') subparsers.add_parser( 'list_ref', help='list the package recipes and its associated remotes') parser_padd = subparsers.add_parser( 'add_ref', help="associate a recipe's reference to a remote") parser_padd.add_argument('reference', help='package recipe reference') parser_padd.add_argument('remote', help='name of the remote') parser_prm = subparsers.add_parser( 'remove_ref', help="dissociate a recipe's reference and its remote") parser_prm.add_argument('reference', help='package recipe reference') parser_pupd = subparsers.add_parser( 'update_ref', help="update the remote associated " "with a package recipe") parser_pupd.add_argument('reference', help='package recipe reference') parser_pupd.add_argument('remote', help='name of the remote') args = parser.parse_args(*args) registry = RemoteRegistry(self._conan_paths.registry, self._user_io.out) if args.subcommand == "list": for r in registry.remotes: self._user_io.out.info("%s: %s" % (r.name, r.url)) elif args.subcommand == "add": registry.add(args.remote, args.url) elif args.subcommand == "remove": registry.remove(args.remote) elif args.subcommand == "update": registry.update(args.remote, args.url) elif args.subcommand == "list_ref": for ref, remote in registry.refs.items(): self._user_io.out.info("%s: %s" % (ref, remote)) elif args.subcommand == "add_ref": registry.add_ref(args.reference, args.remote) elif args.subcommand == "remove_ref": registry.remove_ref(args.reference) elif args.subcommand == "update_ref": registry.update_ref(args.reference, args.remote)
def remote(self, *args): """ manage remotes """ parser = argparse.ArgumentParser(description=self.remote.__doc__, prog="conan remote") subparsers = parser.add_subparsers(dest='subcommand', help='sub-command help') # create the parser for the "a" command subparsers.add_parser('list', help='list current remotes') parser_add = subparsers.add_parser('add', help='add a remote') parser_add.add_argument('remote', help='name of the remote') parser_add.add_argument('url', help='url of the remote') parser_add.add_argument('verify_ssl', help='Verify SSL certificated. Default True', default="True", nargs="?") parser_rm = subparsers.add_parser('remove', help='remove a remote') parser_rm.add_argument('remote', help='name of the remote') parser_upd = subparsers.add_parser('update', help='update the remote url') parser_upd.add_argument('remote', help='name of the remote') parser_upd.add_argument('url', help='url') parser_upd.add_argument('verify_ssl', help='Verify SSL certificated. Default True', default="True", nargs="?") subparsers.add_parser('list_ref', help='list the package recipes and its associated remotes') parser_padd = subparsers.add_parser('add_ref', help="associate a recipe's reference to a remote") parser_padd.add_argument('reference', help='package recipe reference') parser_padd.add_argument('remote', help='name of the remote') parser_prm = subparsers.add_parser('remove_ref', help="dissociate a recipe's reference and its remote") parser_prm.add_argument('reference', help='package recipe reference') parser_pupd = subparsers.add_parser('update_ref', help="update the remote associated " "with a package recipe") parser_pupd.add_argument('reference', help='package recipe reference') parser_pupd.add_argument('remote', help='name of the remote') args = parser.parse_args(*args) registry = RemoteRegistry(self._client_cache.registry, self._user_io.out) if args.subcommand == "list": for r in registry.remotes: self._user_io.out.info("%s: %s [Verify SSL: %s]" % (r.name, r.url, r.verify_ssl)) elif args.subcommand == "add": verify = get_bool_from_text_value(args.verify_ssl) registry.add(args.remote, args.url, args.verify_ssl) elif args.subcommand == "remove": registry.remove(args.remote) elif args.subcommand == "update": verify = get_bool_from_text_value(args.verify_ssl) registry.update(args.remote, args.url, verify) elif args.subcommand == "list_ref": for ref, remote in registry.refs.items(): self._user_io.out.info("%s: %s" % (ref, remote)) elif args.subcommand == "add_ref": registry.add_ref(args.reference, args.remote) elif args.subcommand == "remove_ref": registry.remove_ref(args.reference) elif args.subcommand == "update_ref": registry.update_ref(args.reference, args.remote)
def remote(self, *args): """ manage remotes """ parser = argparse.ArgumentParser(description=self.remote.__doc__, prog="conan remote") subparsers = parser.add_subparsers(dest='subcommand', help='sub-command help') # create the parser for the "a" command subparsers.add_parser('list', help='list current remotes') parser_add = subparsers.add_parser('add', help='add a remote') parser_add.add_argument('remote', help='name of the remote') parser_add.add_argument('url', help='url of the remote') parser_rm = subparsers.add_parser('remove', help='remove a remote') parser_rm.add_argument('remote', help='name of the remote') parser_upd = subparsers.add_parser('update', help='update the remote url') parser_upd.add_argument('remote', help='name of the remote') parser_upd.add_argument('url', help='url') subparsers.add_parser('list_ref', help='list the package recipes and its associated remotes') parser_padd = subparsers.add_parser('add_ref', help="associate a recipe's reference to a remote") parser_padd.add_argument('reference', help='package recipe reference') parser_padd.add_argument('remote', help='name of the remote') parser_prm = subparsers.add_parser('remove_ref', help="dissociate a recipe's reference and its remote") parser_prm.add_argument('reference', help='package recipe reference') parser_pupd = subparsers.add_parser('update_ref', help="update the remote associated " "with a package recipe") parser_pupd.add_argument('reference', help='package recipe reference') parser_pupd.add_argument('remote', help='name of the remote') args = parser.parse_args(*args) registry = RemoteRegistry(self._conan_paths.registry, self._user_io.out) if args.subcommand == "list": for r in registry.remotes: self._user_io.out.info("%s: %s" % (r.name, r.url)) elif args.subcommand == "add": registry.add(args.remote, args.url) elif args.subcommand == "remove": registry.remove(args.remote) elif args.subcommand == "update": registry.update(args.remote, args.url) elif args.subcommand == "list_ref": for ref, remote in registry.refs.items(): self._user_io.out.info("%s: %s" % (ref, remote)) elif args.subcommand == "add_ref": registry.add_ref(args.reference, args.remote) elif args.subcommand == "remove_ref": registry.remove_ref(args.reference) elif args.subcommand == "update_ref": registry.update_ref(args.reference, args.remote)
def remote_remove_ref(self, reference): registry = RemoteRegistry(self._client_cache.registry, self._user_io.out) return registry.remove_ref(reference)
class ConanAPIV1(object): @staticmethod def instance_remote_manager(requester, client_cache, user_io, _client_version, min_server_compatible_version): # Verify client version against remotes version_checker_req = VersionCheckerRequester(requester, _client_version, min_server_compatible_version, user_io.out) # To handle remote connections put_headers = client_cache.read_put_headers() rest_api_client = RestApiClient(user_io.out, requester=version_checker_req, put_headers=put_headers) # To store user and token localdb = LocalDB(client_cache.localdb) # Wraps RestApiClient to add authentication support (same interface) auth_manager = ConanApiAuthManager(rest_api_client, user_io, localdb) # Handle remote connections remote_manager = RemoteManager(client_cache, auth_manager, user_io.out) return localdb, rest_api_client, remote_manager @staticmethod def factory(interactive=None): """Factory""" # Respect color env setting or check tty if unset color_set = "CONAN_COLOR_DISPLAY" in os.environ if ((color_set and get_env("CONAN_COLOR_DISPLAY", 1)) or (not color_set and hasattr(sys.stdout, "isatty") and sys.stdout.isatty())): import colorama if get_env("PYCHARM_HOSTED"): # in PyCharm disable convert/strip colorama.init(convert=False, strip=False) else: colorama.init() color = True else: color = False out = ConanOutput(sys.stdout, color) user_io = UserIO(out=out) try: user_home = get_conan_user_home() client_cache = migrate_and_get_client_cache(user_home, out) sys.path.append(os.path.join(user_home, "python")) except Exception as e: out.error(str(e)) raise with tools.environment_append(client_cache.conan_config.env_vars): # Adjust CONAN_LOGGING_LEVEL with the env readed conans.util.log.logger = configure_logger() # Get the new command instance after migrations have been done requester = get_basic_requester(client_cache) _, _, remote_manager = ConanAPIV1.instance_remote_manager( requester, client_cache, user_io, Version(client_version), Version(MIN_SERVER_COMPATIBLE_VERSION)) # Adjust global tool variables set_global_instances(out, requester) # Settings preprocessor if interactive is None: interactive = not get_env("CONAN_NON_INTERACTIVE", False) conan = ConanAPIV1(client_cache, user_io, get_conan_runner(), remote_manager, interactive=interactive) return conan, client_cache, user_io def __init__(self, client_cache, user_io, runner, remote_manager, interactive=True): assert isinstance(user_io, UserIO) assert isinstance(client_cache, ClientCache) self._client_cache = client_cache self._user_io = user_io self._runner = runner self._remote_manager = remote_manager self._registry = RemoteRegistry(self._client_cache.registry, self._user_io.out) if not interactive: self._user_io.disable_input() self._proxy = ConanProxy(client_cache, self._user_io.out, remote_manager, registry=self._registry) resolver = RangeResolver(self._user_io.out, client_cache, self._proxy) python_requires = ConanPythonRequire(self._proxy, resolver) self._loader = ConanFileLoader(self._runner, self._user_io.out, python_requires) self._graph_manager = GraphManager(self._user_io.out, self._client_cache, self._registry, self._remote_manager, self._loader, self._proxy, resolver) def _init_manager(self, action_recorder): """Every api call gets a new recorder and new manager""" return ConanManager(self._client_cache, self._user_io, self._runner, self._remote_manager, action_recorder, self._registry, self._graph_manager) @api_method def new(self, name, header=False, pure_c=False, test=False, exports_sources=False, bare=False, cwd=None, visual_versions=None, linux_gcc_versions=None, linux_clang_versions=None, osx_clang_versions=None, shared=None, upload_url=None, gitignore=None, gitlab_gcc_versions=None, gitlab_clang_versions=None, circleci_gcc_versions=None, circleci_clang_versions=None, circleci_osx_versions=None): from conans.client.cmd.new import cmd_new cwd = os.path.abspath(cwd or get_cwd()) files = cmd_new(name, header=header, pure_c=pure_c, test=test, exports_sources=exports_sources, bare=bare, visual_versions=visual_versions, linux_gcc_versions=linux_gcc_versions, linux_clang_versions=linux_clang_versions, osx_clang_versions=osx_clang_versions, shared=shared, upload_url=upload_url, gitignore=gitignore, gitlab_gcc_versions=gitlab_gcc_versions, gitlab_clang_versions=gitlab_clang_versions, circleci_gcc_versions=circleci_gcc_versions, circleci_clang_versions=circleci_clang_versions, circleci_osx_versions=circleci_osx_versions) save_files(cwd, files) for f in sorted(files): self._user_io.out.success("File saved: %s" % f) @api_method def test(self, path, reference, profile_name=None, settings=None, options=None, env=None, remote_name=None, update=False, build_modes=None, cwd=None, test_build_folder=None): settings = settings or [] options = options or [] env = env or [] conanfile_path = _get_conanfile_path(path, cwd, py=True) cwd = cwd or get_cwd() profile = profile_from_args(profile_name, settings, options, env, cwd, self._client_cache) reference = ConanFileReference.loads(reference) recorder = ActionRecorder() manager = self._init_manager(recorder) pt = PackageTester(manager, self._user_io) pt.install_build_and_test(conanfile_path, reference, profile, remote_name, update, build_modes=build_modes, test_build_folder=test_build_folder) @api_method def create(self, conanfile_path, name=None, version=None, user=None, channel=None, profile_name=None, settings=None, options=None, env=None, test_folder=None, not_export=False, build_modes=None, keep_source=False, keep_build=False, verify=None, manifests=None, manifests_interactive=None, remote_name=None, update=False, cwd=None, test_build_folder=None): """ API method to create a conan package :param test_folder: default None - looks for default 'test' or 'test_package' folder), string - test_folder path False - disabling tests """ settings = settings or [] options = options or [] env = env or [] try: cwd = cwd or os.getcwd() recorder = ActionRecorder() conanfile_path = _get_conanfile_path(conanfile_path, cwd, py=True) reference, conanfile = self._loader.load_export(conanfile_path, name, version, user, channel) # Make sure keep_source is set for keep_build keep_source = keep_source or keep_build # Forcing an export! if not not_export: cmd_export(conanfile_path, conanfile, reference, keep_source, self._user_io.out, self._client_cache) if build_modes is None: # Not specified, force build the tested library build_modes = [conanfile.name] manifests = _parse_manifests_arguments(verify, manifests, manifests_interactive, cwd) manifest_folder, manifest_interactive, manifest_verify = manifests profile = profile_from_args(profile_name, settings, options, env, cwd, self._client_cache) manager = self._init_manager(recorder) recorder.add_recipe_being_developed(reference) create(reference, manager, self._user_io, profile, remote_name, update, build_modes, manifest_folder, manifest_verify, manifest_interactive, keep_build, test_build_folder, test_folder, conanfile_path) return recorder.get_info() except ConanException as exc: recorder.error = True exc.info = recorder.get_info() raise @api_method def export_pkg(self, conanfile_path, name, channel, source_folder=None, build_folder=None, package_folder=None, install_folder=None, profile_name=None, settings=None, options=None, env=None, force=False, user=None, version=None, cwd=None): settings = settings or [] options = options or [] env = env or [] cwd = cwd or get_cwd() # Checks that info files exists if the install folder is specified if install_folder and not existing_info_files(_make_abs_path(install_folder, cwd)): raise ConanException("The specified install folder doesn't contain '%s' and '%s' " "files" % (CONANINFO, BUILD_INFO)) conanfile_path = _get_conanfile_path(conanfile_path, cwd, py=True) if package_folder: if build_folder or source_folder: raise ConanException("package folder definition incompatible with build and source folders") package_folder = _make_abs_path(package_folder, cwd) build_folder = _make_abs_path(build_folder, cwd) install_folder = _make_abs_path(install_folder, cwd, default=build_folder) source_folder = _make_abs_path(source_folder, cwd, default=os.path.dirname(conanfile_path)) # Checks that no both settings and info files are specified if install_folder and existing_info_files(install_folder) and \ (profile_name or settings or options or env): raise ConanException("%s and %s are found, at '%s' folder, so specifying profile, " "settings, options or env is not allowed" % (CONANINFO, BUILD_INFO, install_folder)) infos_present = existing_info_files(install_folder) if not infos_present: profile = profile_from_args(profile_name, settings, options, env=env, cwd=cwd, client_cache=self._client_cache) else: profile = read_conaninfo_profile(install_folder) reference, conanfile = self._loader.load_export(conanfile_path, name, version, user, channel) cmd_export(conanfile_path, conanfile, reference, False, self._user_io.out, self._client_cache) recorder = ActionRecorder() manager = self._init_manager(recorder) manager.export_pkg(reference, source_folder=source_folder, build_folder=build_folder, package_folder=package_folder, install_folder=install_folder, profile=profile, force=force) @api_method def download(self, reference, remote_name=None, package=None, recipe=False): if package and recipe: raise ConanException("recipe parameter cannot be used together with package") # Install packages without settings (fixed ids or all) conan_ref = ConanFileReference.loads(reference) recorder = ActionRecorder() download(conan_ref, package, remote_name, recipe, self._registry, self._remote_manager, self._client_cache, self._user_io.out, recorder, self._loader) @api_method def install_reference(self, reference, settings=None, options=None, env=None, remote_name=None, verify=None, manifests=None, manifests_interactive=None, build=None, profile_name=None, update=False, generators=None, install_folder=None, cwd=None): try: recorder = ActionRecorder() cwd = cwd or os.getcwd() install_folder = _make_abs_path(install_folder, cwd) manifests = _parse_manifests_arguments(verify, manifests, manifests_interactive, cwd) manifest_folder, manifest_interactive, manifest_verify = manifests profile = profile_from_args(profile_name, settings, options, env, cwd, self._client_cache) if not generators: # We don't want the default txt generators = False mkdir(install_folder) manager = self._init_manager(recorder) manager.install(reference=reference, install_folder=install_folder, remote_name=remote_name, profile=profile, build_modes=build, update=update, manifest_folder=manifest_folder, manifest_verify=manifest_verify, manifest_interactive=manifest_interactive, generators=generators) return recorder.get_info() except ConanException as exc: recorder.error = True exc.info = recorder.get_info() raise @api_method def install(self, path="", settings=None, options=None, env=None, remote_name=None, verify=None, manifests=None, manifests_interactive=None, build=None, profile_name=None, update=False, generators=None, no_imports=False, install_folder=None, cwd=None): try: recorder = ActionRecorder() cwd = cwd or os.getcwd() manifests = _parse_manifests_arguments(verify, manifests, manifests_interactive, cwd) manifest_folder, manifest_interactive, manifest_verify = manifests profile = profile_from_args(profile_name, settings, options, env, cwd, self._client_cache) wspath = _make_abs_path(path, cwd) if install_folder: if os.path.isabs(install_folder): wsinstall_folder = install_folder else: wsinstall_folder = os.path.join(cwd, install_folder) else: wsinstall_folder = None workspace = Workspace.get_workspace(wspath, wsinstall_folder) if workspace: self._user_io.out.success("Using conanws.yml file from %s" % workspace._base_folder) manager = self._init_manager(recorder) manager.install_workspace(profile, workspace, remote_name, build, update) return install_folder = _make_abs_path(install_folder, cwd) conanfile_path = _get_conanfile_path(path, cwd, py=None) manager = self._init_manager(recorder) manager.install(reference=conanfile_path, install_folder=install_folder, remote_name=remote_name, profile=profile, build_modes=build, update=update, manifest_folder=manifest_folder, manifest_verify=manifest_verify, manifest_interactive=manifest_interactive, generators=generators, no_imports=no_imports) return recorder.get_info() except ConanException as exc: recorder.error = True exc.info = recorder.get_info() raise @api_method def config_get(self, item): config_parser = ConanClientConfigParser(self._client_cache.conan_conf_path) self._user_io.out.info(config_parser.get_item(item)) return config_parser.get_item(item) @api_method def config_set(self, item, value): config_parser = ConanClientConfigParser(self._client_cache.conan_conf_path) config_parser.set_item(item, value) self._client_cache.invalidate() @api_method def config_rm(self, item): config_parser = ConanClientConfigParser(self._client_cache.conan_conf_path) config_parser.rm_item(item) self._client_cache.invalidate() @api_method def config_install(self, item, verify_ssl, config_type=None, args=None): from conans.client.conf.config_installer import configuration_install return configuration_install(item, self._client_cache, self._user_io.out, verify_ssl, config_type, args) def _info_get_profile(self, reference, install_folder, profile_name, settings, options, env): cwd = get_cwd() try: reference = ConanFileReference.loads(reference) except ConanException: reference = _get_conanfile_path(reference, cwd=None, py=None) if install_folder or not (profile_name or settings or options or env): # When not install folder is specified but neither any setting, we try to read the # info from cwd install_folder = _make_abs_path(install_folder, cwd) if existing_info_files(install_folder): return reference, read_conaninfo_profile(install_folder) return reference, profile_from_args(profile_name, settings, options, env=env, cwd=cwd, client_cache=self._client_cache) @api_method def info_build_order(self, reference, settings=None, options=None, env=None, profile_name=None, remote_name=None, build_order=None, check_updates=None, install_folder=None): reference, profile = self._info_get_profile(reference, install_folder, profile_name, settings, options, env) recorder = ActionRecorder() deps_graph, _, _ = self._graph_manager.load_graph(reference, None, profile, ["missing"], check_updates, False, remote_name, recorder, workspace=None) return deps_graph.build_order(build_order) @api_method def info_nodes_to_build(self, reference, build_modes, settings=None, options=None, env=None, profile_name=None, remote_name=None, check_updates=None, install_folder=None): reference, profile = self._info_get_profile(reference, install_folder, profile_name, settings, options, env) recorder = ActionRecorder() deps_graph, conanfile, _ = self._graph_manager.load_graph(reference, None, profile, build_modes, check_updates, False, remote_name, recorder, workspace=None) nodes_to_build = deps_graph.nodes_to_build() return nodes_to_build, conanfile @api_method def info(self, reference, remote_name=None, settings=None, options=None, env=None, profile_name=None, update=False, install_folder=None, build=None): reference, profile = self._info_get_profile(reference, install_folder, profile_name, settings, options, env) recorder = ActionRecorder() deps_graph, conanfile, _ = self._graph_manager.load_graph(reference, None, profile, build, update, False, remote_name, recorder, workspace=None) return deps_graph, conanfile @api_method def build(self, conanfile_path, source_folder=None, package_folder=None, build_folder=None, install_folder=None, should_configure=True, should_build=True, should_install=True, should_test=True, cwd=None): cwd = cwd or get_cwd() conanfile_path = _get_conanfile_path(conanfile_path, cwd, py=True) build_folder = _make_abs_path(build_folder, cwd) install_folder = _make_abs_path(install_folder, cwd, default=build_folder) source_folder = _make_abs_path(source_folder, cwd, default=os.path.dirname(conanfile_path)) default_pkg_folder = os.path.join(build_folder, "package") package_folder = _make_abs_path(package_folder, cwd, default=default_pkg_folder) recorder = ActionRecorder() manager = self._init_manager(recorder) manager.build(conanfile_path, source_folder, build_folder, package_folder, install_folder, should_configure=should_configure, should_build=should_build, should_install=should_install, should_test=should_test) @api_method def package(self, path, build_folder, package_folder, source_folder=None, install_folder=None, cwd=None): cwd = cwd or get_cwd() conanfile_path = _get_conanfile_path(path, cwd, py=True) build_folder = _make_abs_path(build_folder, cwd) install_folder = _make_abs_path(install_folder, cwd, default=build_folder) source_folder = _make_abs_path(source_folder, cwd, default=os.path.dirname(conanfile_path)) default_pkg_folder = os.path.join(build_folder, "package") package_folder = _make_abs_path(package_folder, cwd, default=default_pkg_folder) recorder = ActionRecorder() manager = self._init_manager(recorder) manager.local_package(package_folder, conanfile_path, build_folder, source_folder, install_folder) @api_method def source(self, path, source_folder=None, info_folder=None, cwd=None): cwd = cwd or get_cwd() conanfile_path = _get_conanfile_path(path, cwd, py=True) source_folder = _make_abs_path(source_folder, cwd) info_folder = _make_abs_path(info_folder, cwd) mkdir(source_folder) if not os.path.exists(info_folder): raise ConanException("Specified info-folder doesn't exist") recorder = ActionRecorder() manager = self._init_manager(recorder) manager.source(conanfile_path, source_folder, info_folder) @api_method def imports(self, path, dest=None, info_folder=None, cwd=None): """ :param path: Path to the conanfile :param dest: Dir to put the imported files. (Abs path or relative to cwd) :param info_folder: Dir where the conaninfo.txt and conanbuildinfo.txt files are :param cwd: Current working directory :return: None """ cwd = cwd or get_cwd() info_folder = _make_abs_path(info_folder, cwd) dest = _make_abs_path(dest, cwd) mkdir(dest) conanfile_abs_path = _get_conanfile_path(path, cwd, py=None) recorder = ActionRecorder() manager = self._init_manager(recorder) manager.imports(conanfile_abs_path, dest, info_folder) @api_method def imports_undo(self, manifest_path): cwd = get_cwd() manifest_path = _make_abs_path(manifest_path, cwd) undo_imports(manifest_path, self._user_io.out) @api_method def export(self, path, name, version, user, channel, keep_source=False, cwd=None): conanfile_path = _get_conanfile_path(path, cwd, py=True) reference, conanfile = self._loader.load_export(conanfile_path, name, version, user, channel) cmd_export(conanfile_path, conanfile, reference, keep_source, self._user_io.out, self._client_cache) @api_method def remove(self, pattern, query=None, packages=None, builds=None, src=False, force=False, remote_name=None, outdated=False): remover = ConanRemover(self._client_cache, self._remote_manager, self._user_io, self._registry) remover.remove(pattern, remote_name, src, builds, packages, force=force, packages_query=query, outdated=outdated) @api_method def copy(self, reference, user_channel, force=False, packages=None): """ param packages: None=No binaries, True=All binaries, else list of IDs """ from conans.client.cmd.copy import cmd_copy # FIXME: conan copy does not support short-paths in Windows reference = ConanFileReference.loads(str(reference)) cmd_copy(reference, user_channel, packages, self._client_cache, self._user_io, self._remote_manager, self._registry, self._loader, force=force) @api_method def authenticate(self, name, password, remote_name): remote = self.get_remote_by_name(remote_name) _, remote_name, prev_user, user = self._remote_manager.authenticate(remote, name, password) return remote_name, prev_user, user @api_method def user_set(self, user, remote_name=None): remote = self.get_default_remote() if not remote_name else self.get_remote_by_name(remote_name) return user_set(self._client_cache.localdb, user, remote) @api_method def users_clean(self): users_clean(self._client_cache.localdb) @api_method def users_list(self, remote_name=None): info = {"error": False, "remotes": []} remotes = [self.get_remote_by_name(remote_name)] if remote_name else self.remote_list() try: info["remotes"] = users_list(self._client_cache.localdb, remotes) return info except ConanException as exc: info["error"] = True exc.info = info raise @api_method def search_recipes(self, pattern, remote_name=None, case_sensitive=False): recorder = SearchRecorder() search = Search(self._client_cache, self._remote_manager, self._registry) try: references = search.search_recipes(pattern, remote_name, case_sensitive) except ConanException as exc: recorder.error = True exc.info = recorder.get_info() raise for remote_name, refs in references.items(): for ref in refs: recorder.add_recipe(remote_name, ref, with_packages=False) return recorder.get_info() @api_method def search_packages(self, reference, query=None, remote_name=None, outdated=False): recorder = SearchRecorder() search = Search(self._client_cache, self._remote_manager, self._registry) try: reference = ConanFileReference.loads(str(reference)) references = search.search_packages(reference, remote_name, query=query, outdated=outdated) except ConanException as exc: recorder.error = True exc.info = recorder.get_info() raise for remote_name, remote_ref in references.items(): recorder.add_recipe(remote_name, reference) if remote_ref.ordered_packages: for package_id, properties in remote_ref.ordered_packages.items(): package_recipe_hash = properties.get("recipe_hash", None) recorder.add_package(remote_name, reference, package_id, properties.get("options", []), properties.get("settings", []), properties.get("full_requires", []), remote_ref.recipe_hash != package_recipe_hash) return recorder.get_info() @api_method def upload(self, pattern, package=None, remote_name=None, all_packages=False, force=False, confirm=False, retry=2, retry_wait=5, skip_upload=False, integrity_check=False, no_overwrite=None, query=None): """ Uploads a package recipe and the generated binary packages to a specified remote """ recorder = UploadRecorder() if force and no_overwrite: exc = ConanException("'no_overwrite' argument cannot be used together with 'force'") recorder.error = True exc.info = recorder.get_info() raise exc uploader = CmdUpload(self._client_cache, self._user_io, self._remote_manager, self._registry, self._loader) try: uploader.upload(recorder, pattern, package, all_packages, force, confirm, retry, retry_wait, skip_upload, integrity_check, no_overwrite, remote_name, query=query) return recorder.get_info() except ConanException as exc: recorder.error = True exc.info = recorder.get_info() raise @api_method def remote_list(self): return self._registry.remotes @api_method def remote_add(self, remote_name, url, verify_ssl=True, insert=None, force=None): return self._registry.add(remote_name, url, verify_ssl, insert, force) @api_method def remote_remove(self, remote_name): return self._registry.remove(remote_name) @api_method def remote_update(self, remote_name, url, verify_ssl=True, insert=None): return self._registry.update(remote_name, url, verify_ssl, insert) @api_method def remote_rename(self, remote_name, new_new_remote): return self._registry.rename(remote_name, new_new_remote) @api_method def remote_list_ref(self): return self._registry.refs @api_method def remote_add_ref(self, reference, remote_name): reference = ConanFileReference.loads(str(reference)) return self._registry.set_ref(reference, remote_name, check_exists=True) @api_method def remote_remove_ref(self, reference): reference = ConanFileReference.loads(str(reference)) return self._registry.remove_ref(reference) @api_method def remote_update_ref(self, reference, remote_name): reference = ConanFileReference.loads(str(reference)) return self._registry.update_ref(reference, remote_name) @api_method def profile_list(self): return cmd_profile_list(self._client_cache.profiles_path, self._user_io.out) @api_method def create_profile(self, profile_name, detect=False): return cmd_profile_create(profile_name, self._client_cache.profiles_path, self._user_io.out, detect) @api_method def update_profile(self, profile_name, key, value): return cmd_profile_update(profile_name, key, value, self._client_cache.profiles_path) @api_method def get_profile_key(self, profile_name, key): return cmd_profile_get(profile_name, key, self._client_cache.profiles_path) @api_method def delete_profile_key(self, profile_name, key): return cmd_profile_delete_key(profile_name, key, self._client_cache.profiles_path) @api_method def read_profile(self, profile=None): p, _ = read_profile(profile, get_cwd(), self._client_cache.profiles_path) return p @api_method def get_path(self, reference, package_id=None, path=None, remote_name=None): from conans.client.local_file_getter import get_path reference = ConanFileReference.loads(str(reference)) if not path: path = "conanfile.py" if not package_id else "conaninfo.txt" if not remote_name: return get_path(self._client_cache, reference, package_id, path), path else: remote = self.get_remote_by_name(remote_name) return self._remote_manager.get_path(reference, package_id, path, remote), path @api_method def export_alias(self, reference, target_reference): reference = ConanFileReference.loads(reference) target_reference = ConanFileReference.loads(target_reference) return export_alias(reference, target_reference, self._client_cache) @api_method def get_default_remote(self): return self._registry.default_remote @api_method def get_remote_by_name(self, remote_name): return self._registry.remote(remote_name)
class ConanProxy(object): """ Class to access the conan storage, to perform typical tasks as to get packages, getting conanfiles, uploading, removing from remote, etc. It uses the RemoteRegistry to control where the packages come from. """ def __init__(self, client_cache, user_io, remote_manager, remote_name, update=False, check_updates=False, manifest_manager=False): self._client_cache = client_cache self._out = user_io.out self._remote_manager = remote_manager self._registry = RemoteRegistry(self._client_cache.registry, self._out) self._remote_name = remote_name self._update = update self._check_updates = check_updates or update # Update forces check self._manifest_manager = manifest_manager @property def registry(self): return self._registry def package_available(self, package_ref, short_paths, check_outdated): """ Returns True if there is a local or remote package available (and up to date if check_outdated). It wont download the package, just check its hash """ output = ScopedOutput(str(package_ref.conan), self._out) package_folder = self._client_cache.package(package_ref, short_paths=short_paths) remote_info = None # No package in local cache if not os.path.exists(package_folder): try: remote_info = self.get_package_info(package_ref) except ConanException: return False # Not local nor remote # Maybe we have the package (locally or in remote) but it's outdated if check_outdated: if remote_info: package_hash = remote_info.recipe_hash else: package_hash = self._client_cache.read_package_recipe_hash( package_folder) local_recipe_hash = self._client_cache.load_manifest( package_ref.conan).summary_hash up_to_date = local_recipe_hash == package_hash if not up_to_date: output.info("Outdated package!") else: output.info("Package is up to date") return up_to_date return True def get_package(self, package_ref, short_paths): """ obtain a package, either from disk or retrieve from remotes if necessary and not necessary to build """ output = ScopedOutput(str(package_ref.conan), self._out) package_folder = self._client_cache.package(package_ref, short_paths=short_paths) # Check current package status if os.path.exists(package_folder): if self._check_updates: read_manifest = self._client_cache.load_package_manifest( package_ref) try: # get_conan_digest can fail, not in server upstream_manifest = self.get_package_digest(package_ref) if upstream_manifest.file_sums != read_manifest.file_sums: if upstream_manifest.time > read_manifest.time: output.warn( "Current package is older than remote upstream one" ) if self._update: output.warn( "Removing it to retrieve or build an updated one" ) rmdir(package_folder) else: output.warn( "Current package is newer than remote upstream one" ) except ConanException: pass installed = False local_package = os.path.exists(package_folder) if local_package: output.info('Already installed!') installed = True else: installed = self._retrieve_remote_package(package_ref, package_folder, output) self.handle_package_manifest(package_ref, installed) return installed def _package_outdated(self, package_ref, package_folder): recipe_hash = self._client_cache.load_manifest( package_ref.conan).summary_hash package_recipe_hash = self._client_cache.read_package_recipe_hash( package_folder) return not recipe_hash == package_recipe_hash def handle_package_manifest(self, package_ref, installed): if installed and self._manifest_manager: remote = self._registry.get_ref(package_ref.conan) self._manifest_manager.check_package(package_ref, remote) def get_recipe(self, conan_reference): output = ScopedOutput(str(conan_reference), self._out) def _refresh(): export_path = self._client_cache.export(conan_reference) rmdir(export_path) # It might need to remove shortpath rm_conandir(self._client_cache.source(conan_reference)) current_remote, _ = self._get_remote(conan_reference) output.info("Retrieving from remote '%s'..." % current_remote.name) self._remote_manager.get_recipe(conan_reference, export_path, current_remote) if self._update: output.info("Updated!") else: output.info("Installed!") # check if it is in disk conanfile_path = self._client_cache.conanfile(conan_reference) if os.path.exists(conanfile_path): if self._check_updates: ret = self.update_available(conan_reference) if ret != 0: # Found and not equal remote, ref_remote = self._get_remote(conan_reference) if ret == 1: if not self._update: if remote != ref_remote: # Forced new remote output.warn( "There is a new conanfile in '%s' remote. " "Execute 'install -u -r %s' to update it." % (remote.name, remote.name)) else: output.warn( "There is a new conanfile in '%s' remote. " "Execute 'install -u' to update it." % remote.name) output.warn("Refused to install!") else: if remote != ref_remote: # Delete packages, could be non coherent with new remote DiskRemover( self._client_cache).remove_packages( conan_reference) _refresh() elif ret == -1: if not self._update: output.info("Current conanfile is newer " "than %s's one" % remote.name) else: output.error( "Current conanfile is newer than %s's one. " "Run 'conan remove %s' and run install again " "to replace it." % (remote.name, conan_reference)) else: self._retrieve_recipe(conan_reference, output) if self._manifest_manager: remote = self._registry.get_ref(conan_reference) self._manifest_manager.check_recipe(conan_reference, remote) return conanfile_path def update_available(self, conan_reference): """Returns 0 if the conanfiles are equal, 1 if there is an update and -1 if the local is newer than the remote""" if not conan_reference: return 0 read_manifest, _ = self._client_cache.conan_manifests(conan_reference) if read_manifest: try: # get_conan_digest can fail, not in server upstream_manifest = self.get_conan_digest(conan_reference) if upstream_manifest.file_sums != read_manifest.file_sums: return 1 if upstream_manifest.time > read_manifest.time else -1 except ConanException: pass return 0 def _retrieve_recipe(self, conan_reference, output): """ returns the requested conanfile object, retrieving it from remotes if necessary. Can raise NotFoundException """ def _retrieve_from_remote(remote): output.info("Trying with '%s'..." % remote.name) export_path = self._client_cache.export(conan_reference) result = self._remote_manager.get_recipe(conan_reference, export_path, remote) self._registry.set_ref(conan_reference, remote) return result if self._remote_name: output.info("Not found, retrieving from server '%s' " % self._remote_name) remote = self._registry.remote(self._remote_name) return _retrieve_from_remote(remote) else: output.info("Not found, looking in remotes...") remotes = self._registry.remotes for remote in remotes: logger.debug("Trying with remote %s" % remote.name) try: return _retrieve_from_remote(remote) # If exception continue with the next except (ConanOutdatedClient, ConanConnectionError) as exc: output.warn(str(exc)) if remote == remotes[-1]: # Last element not found raise ConanConnectionError("All remotes failed") except NotFoundException as exc: if remote == remotes[-1]: # Last element not found logger.debug("Not found in any remote, raising...%s" % exc) raise NotFoundException("Unable to find '%s' in remotes" % str(conan_reference)) raise ConanException("No remote defined") def upload_conan(self, conan_reference, retry, retry_wait): """ upload to defined remote in (-r=remote), to current remote or to default remote, in that order. If the remote is not set, set it """ remote, ref_remote = self._get_remote(conan_reference) result = self._remote_manager.upload_conan(conan_reference, remote, retry, retry_wait) if not ref_remote: self._registry.set_ref(conan_reference, remote) return result def _get_remote(self, conan_ref=None): # Prioritize -r , then reference registry and then the default remote ref_remote = self._registry.get_ref(conan_ref) if conan_ref else None if self._remote_name: remote = self._registry.remote(self._remote_name) else: if ref_remote: remote = ref_remote else: remote = self._registry.default_remote return remote, ref_remote def upload_package(self, package_ref, retry, retry_wait): remote, current_remote = self._get_remote(package_ref.conan) if not current_remote: self._out.warn("Remote for '%s' not defined, uploading to %s" % (str(package_ref.conan), remote.name)) result = self._remote_manager.upload_package(package_ref, remote, retry, retry_wait) if not current_remote: self._registry.set_ref(package_ref.conan, remote) return result def get_conan_digest(self, conan_ref): """ used by update to check the date of packages, require force if older """ remote, current_remote = self._get_remote(conan_ref) result = self._remote_manager.get_conan_digest(conan_ref, remote) if not current_remote: self._registry.set_ref(conan_ref, remote) return result def get_package_digest(self, package_ref): """ used by update to check the date of packages, require force if older """ remote, ref_remote = self._get_remote(package_ref.conan) result = self._remote_manager.get_package_digest(package_ref, remote) if not ref_remote: self._registry.set_ref(package_ref.conan, remote) return result def get_package_info(self, package_ref): """ Gets the package info to check if outdated """ remote, ref_remote = self._get_remote(package_ref.conan) result = self._remote_manager.get_package_info(package_ref, remote) if not ref_remote: self._registry.set_ref(package_ref.conan, remote) return result def search(self, pattern=None, ignorecase=True): remote, _ = self._get_remote() return self._remote_manager.search(remote, pattern, ignorecase) def search_remotes(self, pattern=None, ignorecase=True): if self._remote_name: remote = self._registry.remote(self._remote_name) search_result = self._remote_manager.search( remote, pattern, ignorecase) return search_result for remote in self._registry.remotes: search_result = self._remote_manager.search( remote, pattern, ignorecase) if search_result: return search_result def search_packages(self, reference, query): remote, _ = self._get_remote() return self._remote_manager.search_packages(remote, reference, query) def remove(self, conan_ref): if not self._remote_name: raise ConanException("Cannot remove, remote not defined") remote = self._registry.remote(self._remote_name) result = self._remote_manager.remove(conan_ref, remote) current_remote = self._registry.get_ref(conan_ref) if current_remote == remote: self._registry.remove_ref(conan_ref) return result def remove_packages(self, conan_ref, remove_ids): if not self._remote_name: raise ConanException("Cannot remove, remote not defined") remote = self._registry.remote(self._remote_name) return self._remote_manager.remove_packages(conan_ref, remove_ids, remote) def download_packages(self, reference, package_ids): assert (isinstance(package_ids, list)) remote, _ = self._get_remote(reference) export_path = self._client_cache.export(reference) self._remote_manager.get_recipe(reference, export_path, remote) conanfile_path = self._client_cache.conanfile(reference) loader = ConanFileLoader(None, None, None, None, None, None, None) conanfile = loader.load_class(conanfile_path) short_paths = conanfile.short_paths self._registry.set_ref(reference, remote) output = ScopedOutput(str(reference), self._out) for package_id in package_ids: package_ref = PackageReference(reference, package_id) package_folder = self._client_cache.package( package_ref, short_paths=short_paths) self._retrieve_remote_package(package_ref, package_folder, output, remote) def _retrieve_remote_package(self, package_ref, package_folder, output, remote=None): if remote is None: remote = self._registry.get_ref(package_ref.conan) if not remote: output.warn("Package doesn't have a remote defined. " "Probably created locally and not uploaded") return False package_id = str(package_ref.package_id) try: output.info("Looking for package %s in remote '%s' " % (package_id, remote.name)) # Will raise if not found NotFoundException self._remote_manager.get_package(package_ref, package_folder, remote) output.success('Package installed %s' % package_id) return True except ConanConnectionError: raise # This shouldn't be skipped except ConanException as e: output.warn('Binary for %s not in remote: %s' % (package_id, str(e))) return False def authenticate(self, name, password): if not name: # List all users, from all remotes remotes = self._registry.remotes if not remotes: self._out.error("No remotes defined") for remote in remotes: self._remote_manager.authenticate(remote, None, None) return remote, _ = self._get_remote() return self._remote_manager.authenticate(remote, name, password)
class ConanProxy(object): """ Class to access the conan storage, to perform typical tasks as to get packages, getting conanfiles, uploading, removing from remote, etc. It uses the RemoteRegistry to control where the packages come from. """ def __init__(self, paths, user_io, remote_manager, remote_name, update=False, check_updates=False, check_integrity=False): self._paths = paths self._out = user_io.out self._remote_manager = remote_manager self._registry = RemoteRegistry(self._paths.registry, self._out) self._remote_name = remote_name self._update = update self._check_updates = check_updates or update # Update forces check self._check_integrity = check_integrity @property def registry(self): return self._registry def get_package(self, package_reference, force_build): """ obtain a package, either from disk or retrieve from remotes if necessary and not necessary to build """ output = ScopedOutput(str(package_reference.conan), self._out) package_folder = self._paths.package(package_reference) # Check current package status if path_exists(package_folder, self._paths.store): if self._check_integrity or self._check_updates: read_manifest, expected_manifest = self._paths.package_manifests(package_reference) if self._check_integrity: # Check if package is corrupted if read_manifest.file_sums != expected_manifest.file_sums: # If not valid package, ensure empty folder output.warn("Bad package '%s' detected! Removing " "package directory... " % str(package_reference.package_id)) rmdir(package_folder) if self._check_updates: try: # get_conan_digest can fail, not in server upstream_manifest = self.get_package_digest(package_reference) if upstream_manifest.file_sums != read_manifest.file_sums: if upstream_manifest.time > read_manifest.time: output.warn("Current package is older than remote upstream one") if self._update: output.warn("Removing it to retrieve or build an updated one") rmdir(package_folder) else: output.warn("Current package is newer than remote upstream one") except ConanException: pass if not force_build: local_package = os.path.exists(package_folder) if local_package: output = ScopedOutput(str(package_reference.conan), self._out) output.info('Already installed!') return True return self._retrieve_remote_package(package_reference, output) return False def get_conanfile(self, conan_reference): output = ScopedOutput(str(conan_reference), self._out) def _refresh(): conan_dir_path = self._paths.export(conan_reference) rmdir(conan_dir_path) rmdir(self._paths.source(conan_reference), True) # It might need to remove shortpath current_remote, _ = self._get_remote(conan_reference) output.info("Retrieving from remote '%s'..." % current_remote.name) self._remote_manager.get_conanfile(conan_reference, current_remote) if self._update: output.info("Updated!") else: output.info("Installed!") # check if it is in disk conanfile_path = self._paths.conanfile(conan_reference) path_exist = path_exists(conanfile_path, self._paths.store) if path_exist: if self._check_integrity: # Check if package is corrupted read_manifest, expected_manifest = self._paths.conan_manifests(conan_reference) if read_manifest.file_sums != expected_manifest.file_sums: output.warn("Bad conanfile detected! Removing export directory... ") _refresh() else: # Check for updates if self._check_updates: ret = self.update_available(conan_reference) if ret != 0: # Found and not equal remote, ref_remote = self._get_remote(conan_reference) if ret == 1: if not self._update: if remote != ref_remote: # Forced new remote output.warn("There is a new conanfile in '%s' remote. " "Execute 'install -u -r %s' to update it." % (remote.name, remote.name)) else: output.warn("There is a new conanfile in '%s' remote. " "Execute 'install -u' to update it." % remote.name) output.warn("Refused to install!") else: if remote != ref_remote: # Delete packages, could be non coherent with new remote rmdir(self._paths.packages(conan_reference)) _refresh() elif ret == -1: if not self._update: output.info("Current conanfile is newer " "than %s's one" % remote.name) else: output.error("Current conanfile is newer than %s's one. " "Run 'conan remove %s' and run install again " "to replace it." % (remote.name, conan_reference)) else: self._retrieve_conanfile(conan_reference, output) return conanfile_path def update_available(self, conan_reference): """Returns 0 if the conanfiles are equal, 1 if there is an update and -1 if the local is newer than the remote""" if not conan_reference: return 0 read_manifest, _ = self._paths.conan_manifests(conan_reference) if read_manifest: try: # get_conan_digest can fail, not in server upstream_manifest = self.get_conan_digest(conan_reference) if upstream_manifest.file_sums != read_manifest.file_sums: return 1 if upstream_manifest.time > read_manifest.time else -1 except ConanException: pass return 0 def _retrieve_conanfile(self, conan_reference, output): """ returns the requested conanfile object, retrieving it from remotes if necessary. Can raise NotFoundException """ def _retrieve_from_remote(remote): output.info("Trying with '%s'..." % remote.name) result = self._remote_manager.get_conanfile(conan_reference, remote) self._registry.set_ref(conan_reference, remote) return result if self._remote_name: output.info("Not found, retrieving from server '%s' " % self._remote_name) remote = self._registry.remote(self._remote_name) return _retrieve_from_remote(remote) else: output.info("Not found, looking in remotes...") remotes = self._registry.remotes for remote in remotes: logger.debug("Trying with remote %s" % remote.name) try: return _retrieve_from_remote(remote) # If exception continue with the next except (ConanOutdatedClient, ConanConnectionError) as exc: output.warn(str(exc)) if remote == remotes[-1]: # Last element not found raise ConanConnectionError("All remotes failed") except NotFoundException as exc: if remote == remotes[-1]: # Last element not found logger.debug("Not found in any remote, raising...%s" % exc) raise NotFoundException("Unable to find '%s' in remotes" % str(conan_reference)) raise ConanException("No remote defined") def upload_conan(self, conan_reference): """ upload to defined remote in (-r=remote), to current remote or to default remote, in that order. If the remote is not set, set it """ remote, ref_remote = self._get_remote(conan_reference) result = self._remote_manager.upload_conan(conan_reference, remote) if not ref_remote: self._registry.set_ref(conan_reference, remote) return result def _get_remote(self, conan_ref=None): # Prioritize -r , then reference registry and then the default remote ref_remote = self._registry.get_ref(conan_ref) if conan_ref else None if self._remote_name: remote = self._registry.remote(self._remote_name) else: if ref_remote: remote = ref_remote else: remote = self._registry.default_remote return remote, ref_remote def upload_package(self, package_reference): remote, current_remote = self._get_remote(package_reference.conan) if not current_remote: self._out.warn("Remote for '%s' not defined, uploading to %s" % (str(package_reference.conan), remote.name)) result = self._remote_manager.upload_package(package_reference, remote) if not current_remote: self._registry.set_ref(package_reference.conan, remote) return result def get_conan_digest(self, conan_ref): """ used by update to check the date of packages, require force if older """ remote, current_remote = self._get_remote(conan_ref) result = self._remote_manager.get_conan_digest(conan_ref, remote) if not current_remote: self._registry.set_ref(conan_ref, remote) return result def get_package_digest(self, package_reference): """ used by update to check the date of packages, require force if older """ remote, ref_remote = self._get_remote(package_reference.conan) result = self._remote_manager.get_package_digest(package_reference, remote) if not ref_remote: self._registry.set_ref(package_reference.conan, remote) return result def search(self, pattern=None, ignorecase=True): remote, _ = self._get_remote() return self._remote_manager.search(remote, pattern, ignorecase) def remove(self, conan_ref): if not self._remote_name: raise ConanException("Cannot remove, remote not defined") remote = self._registry.remote(self._remote_name) result = self._remote_manager.remove(conan_ref, remote) current_remote = self._registry.get_ref(conan_ref) if current_remote == remote: self._registry.remove_ref(conan_ref) return result def remove_packages(self, conan_ref, remove_ids): if not self._remote_name: raise ConanException("Cannot remove, remote not defined") remote = self._registry.remote(self._remote_name) return self._remote_manager.remove_packages(conan_ref, remove_ids, remote) def download_packages(self, reference, package_ids): assert(isinstance(package_ids, list)) remote, _ = self._get_remote(reference) self._remote_manager.get_conanfile(reference, remote) self._registry.set_ref(reference, remote) output = ScopedOutput(str(reference), self._out) for package_id in package_ids: package_reference = PackageReference(reference, package_id) self._retrieve_remote_package(package_reference, output, remote) def _retrieve_remote_package(self, package_reference, output, remote=None): if remote is None: remote = self._registry.get_ref(package_reference.conan) if not remote: output.warn("Package doesn't have a remote defined. " "Probably created locally and not uploaded") return False package_id = str(package_reference.package_id) try: output.info("Looking for package %s in remote '%s' " % (package_id, remote.name)) # Will raise if not found NotFoundException self._remote_manager.get_package(package_reference, remote) output.success('Package installed %s' % package_id) return True except ConanConnectionError: raise # This shouldn't be skipped except ConanException as e: output.warn('Binary for %s not in remote: %s' % (package_id, str(e))) return False def authenticate(self, name, password): if not name: # List all users, from all remotes remotes = self._registry.remotes if not remotes: self._out.error("No remotes defined") for remote in remotes: self._remote_manager.authenticate(remote, None, None) return remote, _ = self._get_remote() return self._remote_manager.authenticate(remote, name, password)
class ConanProxy(object): """ Class to access the conan storage, to perform typical tasks as to get packages, getting conanfiles, uploading, removing from remote, etc. It uses the RemoteRegistry to control where the packages come from. """ def __init__(self, client_cache, user_io, remote_manager, remote_name, update=False, check_updates=False, manifest_manager=False): self._client_cache = client_cache self._out = user_io.out self._remote_manager = remote_manager self._registry = RemoteRegistry(self._client_cache.registry, self._out) self._remote_name = remote_name self._update = update self._check_updates = check_updates or update # Update forces check (and of course the update) self._manifest_manager = manifest_manager @property def registry(self): return self._registry def package_available(self, package_ref, short_paths, check_outdated): """ Returns True if there is a local or remote package available (and up to date if check_outdated). It wont download the package, just check its hash """ output = ScopedOutput(str(package_ref.conan), self._out) package_folder = self._client_cache.package(package_ref, short_paths=short_paths) remote_info = None # No package in local cache if not os.path.exists(package_folder): try: remote_info = self.get_package_info(package_ref) except ConanException: return False # Not local nor remote # Maybe we have the package (locally or in remote) but it's outdated if check_outdated: if remote_info: package_hash = remote_info.recipe_hash else: package_hash = self._client_cache.read_package_recipe_hash(package_folder) local_recipe_hash = self._client_cache.load_manifest(package_ref.conan).summary_hash up_to_date = local_recipe_hash == package_hash if not up_to_date: output.info("Outdated package!") else: output.info("Package is up to date") return up_to_date return True def get_package(self, package_ref, short_paths): """ obtain a package, either from disk or retrieve from remotes if necessary and not necessary to build """ output = ScopedOutput(str(package_ref.conan), self._out) package_folder = self._client_cache.package(package_ref, short_paths=short_paths) # Check current package status if os.path.exists(package_folder): if self._check_updates: read_manifest = self._client_cache.load_package_manifest(package_ref) try: # get_conan_digest can fail, not in server upstream_manifest = self.get_package_digest(package_ref) if upstream_manifest != read_manifest: if upstream_manifest.time > read_manifest.time: output.warn("Current package is older than remote upstream one") if self._update: output.warn("Removing it to retrieve or build an updated one") rmdir(package_folder) else: output.warn("Current package is newer than remote upstream one") except ConanException: pass installed = False local_package = os.path.exists(package_folder) if local_package: output.info('Already installed!') installed = True log_package_got_from_local_cache(package_ref) else: installed = self._retrieve_remote_package(package_ref, package_folder, output) self.handle_package_manifest(package_ref, installed) return installed def handle_package_manifest(self, package_ref, installed): if installed and self._manifest_manager: remote = self._registry.get_ref(package_ref.conan) self._manifest_manager.check_package(package_ref, remote) def get_recipe_sources(self, conan_reference): export_path = self._client_cache.export(conan_reference) sources_folder = os.path.join(export_path, EXPORT_SOURCES_DIR) if os.path.exists(sources_folder): return current_remote = self._registry.get_ref(conan_reference) if not current_remote: raise ConanException("Error while trying to get recipe sources for %s. " "No remote defined" % str(conan_reference)) else: self._remote_manager.get_recipe_sources(conan_reference, export_path, current_remote) def get_recipe(self, conan_reference): output = ScopedOutput(str(conan_reference), self._out) def _refresh(): export_path = self._client_cache.export(conan_reference) rmdir(export_path) # It might need to remove shortpath rm_conandir(self._client_cache.source(conan_reference)) current_remote, _ = self._get_remote(conan_reference) output.info("Retrieving from remote '%s'..." % current_remote.name) self._remote_manager.get_recipe(conan_reference, export_path, current_remote) if self._update: output.info("Updated!") else: output.info("Installed!") # check if it is in disk conanfile_path = self._client_cache.conanfile(conan_reference) if os.path.exists(conanfile_path): log_recipe_got_from_local_cache(conan_reference) if self._check_updates: ret = self.update_available(conan_reference) if ret != 0: # Found and not equal remote, ref_remote = self._get_remote(conan_reference) if ret == 1: if not self._update: if remote != ref_remote: # Forced new remote output.warn("There is a new conanfile in '%s' remote. " "Execute 'install -u -r %s' to update it." % (remote.name, remote.name)) else: output.warn("There is a new conanfile in '%s' remote. " "Execute 'install -u' to update it." % remote.name) output.warn("Refused to install!") else: if remote != ref_remote: # Delete packages, could be non coherent with new remote DiskRemover(self._client_cache).remove_packages(conan_reference) _refresh() elif ret == -1: if not self._update: output.info("Current conanfile is newer " "than %s's one" % remote.name) else: output.error("Current conanfile is newer than %s's one. " "Run 'conan remove %s' and run install again " "to replace it." % (remote.name, conan_reference)) else: self._retrieve_recipe(conan_reference, output) if self._manifest_manager: # Just make sure that the recipe sources are there to check self.get_recipe_sources(conan_reference) remote = self._registry.get_ref(conan_reference) self._manifest_manager.check_recipe(conan_reference, remote) return conanfile_path def update_available(self, conan_reference): """Returns 0 if the conanfiles are equal, 1 if there is an update and -1 if the local is newer than the remote""" if not conan_reference: return 0 read_manifest, _ = self._client_cache.conan_manifests(conan_reference) if read_manifest: try: # get_conan_digest can fail, not in server upstream_manifest = self.get_conan_digest(conan_reference) if upstream_manifest != read_manifest: return 1 if upstream_manifest.time > read_manifest.time else -1 except ConanException: pass return 0 def _retrieve_recipe(self, conan_reference, output): """ returns the requested conanfile object, retrieving it from remotes if necessary. Can raise NotFoundException """ def _retrieve_from_remote(remote): output.info("Trying with '%s'..." % remote.name) export_path = self._client_cache.export(conan_reference) result = self._remote_manager.get_recipe(conan_reference, export_path, remote) self._registry.set_ref(conan_reference, remote) return result if self._remote_name: output.info("Not found, retrieving from server '%s' " % self._remote_name) remote = self._registry.remote(self._remote_name) return _retrieve_from_remote(remote) else: output.info("Not found, looking in remotes...") remotes = self._registry.remotes for remote in remotes: logger.debug("Trying with remote %s" % remote.name) try: return _retrieve_from_remote(remote) # If exception continue with the next except (ConanOutdatedClient, ConanConnectionError) as exc: output.warn(str(exc)) if remote == remotes[-1]: # Last element not found raise ConanConnectionError("All remotes failed") except NotFoundException as exc: if remote == remotes[-1]: # Last element not found logger.debug("Not found in any remote, raising...%s" % exc) raise NotFoundException("Unable to find '%s' in remotes" % str(conan_reference)) raise ConanException("No remote defined") def complete_recipe_sources(self, conan_reference, force_complete=True): export_path = self._client_cache.export(conan_reference) sources_folder = os.path.join(export_path, EXPORT_SOURCES_DIR) ignore_deleted_file = None if not os.path.exists(sources_folder): # If not path to sources exists, we have a problem, at least an empty folder # should be there upload_remote, current_remote = self._get_remote(conan_reference) if not current_remote: raise ConanException("Trying to upload a package recipe without sources, " "and the remote for the sources no longer exists") if force_complete or current_remote != upload_remote: # If uploading to a different remote than the one from which the recipe # was retrieved, we definitely need to get the sources, so the recipe is complete self.get_recipe_sources(conan_reference) else: # But if same remote, no need to upload again the TGZ, it is already in the server # But the upload API needs to know it to not remove the server file. ignore_deleted_file = EXPORT_SOURCES_TGZ_NAME return ignore_deleted_file def upload_recipe(self, conan_reference, retry, retry_wait, skip_upload): """ upload to defined remote in (-r=remote), to current remote or to default remote, in that order. If the remote is not set, set it """ ignore_deleted_file = self.complete_recipe_sources(conan_reference, force_complete=False) remote, ref_remote = self._get_remote(conan_reference) result = self._remote_manager.upload_recipe(conan_reference, remote, retry, retry_wait, ignore_deleted_file=ignore_deleted_file, skip_upload=skip_upload) if not ref_remote and not skip_upload: self._registry.set_ref(conan_reference, remote) return result def _get_remote(self, conan_ref=None): # Prioritize -r , then reference registry and then the default remote ref_remote = self._registry.get_ref(conan_ref) if conan_ref else None if self._remote_name: remote = self._registry.remote(self._remote_name) else: if ref_remote: remote = ref_remote else: remote = self._registry.default_remote return remote, ref_remote def upload_package(self, package_ref, retry, retry_wait, skip_upload): remote, current_remote = self._get_remote(package_ref.conan) if not current_remote: self._out.warn("Remote for '%s' not defined, uploading to %s" % (str(package_ref.conan), remote.name)) result = self._remote_manager.upload_package(package_ref, remote, retry, retry_wait, skip_upload) if not current_remote and not skip_upload: self._registry.set_ref(package_ref.conan, remote) return result def get_conan_digest(self, conan_ref): """ used by update to check the date of packages, require force if older """ remote, current_remote = self._get_remote(conan_ref) result = self._remote_manager.get_conan_digest(conan_ref, remote) if not current_remote: self._registry.set_ref(conan_ref, remote) return result def get_package_digest(self, package_ref): """ used by update to check the date of packages, require force if older """ remote, ref_remote = self._get_remote(package_ref.conan) result = self._remote_manager.get_package_digest(package_ref, remote) if not ref_remote: self._registry.set_ref(package_ref.conan, remote) return result def get_package_info(self, package_ref): """ Gets the package info to check if outdated """ remote, ref_remote = self._get_remote(package_ref.conan) result = self._remote_manager.get_package_info(package_ref, remote) if not ref_remote: self._registry.set_ref(package_ref.conan, remote) return result def search(self, pattern=None, ignorecase=True): remote, _ = self._get_remote() return self._remote_manager.search(remote, pattern, ignorecase) def search_remotes(self, pattern=None, ignorecase=True): if self._remote_name: remote = self._registry.remote(self._remote_name) search_result = self._remote_manager.search(remote, pattern, ignorecase) return search_result for remote in self._registry.remotes: search_result = self._remote_manager.search(remote, pattern, ignorecase) if search_result: return search_result def search_packages(self, reference, query): remote, _ = self._get_remote() return self._remote_manager.search_packages(remote, reference, query) def remove(self, conan_ref): if not self._remote_name: raise ConanException("Cannot remove, remote not defined") remote = self._registry.remote(self._remote_name) result = self._remote_manager.remove(conan_ref, remote) current_remote = self._registry.get_ref(conan_ref) if current_remote == remote: self._registry.remove_ref(conan_ref) return result def remove_packages(self, conan_ref, remove_ids): if not self._remote_name: raise ConanException("Cannot remove, remote not defined") remote = self._registry.remote(self._remote_name) return self._remote_manager.remove_packages(conan_ref, remove_ids, remote) def download_packages(self, reference, package_ids): assert(isinstance(package_ids, list)) remote, _ = self._get_remote(reference) export_path = self._client_cache.export(reference) self._remote_manager.get_recipe(reference, export_path, remote) conanfile_path = self._client_cache.conanfile(reference) conanfile = load_conanfile_class(conanfile_path) short_paths = conanfile.short_paths self._registry.set_ref(reference, remote) output = ScopedOutput(str(reference), self._out) for package_id in package_ids: package_ref = PackageReference(reference, package_id) package_folder = self._client_cache.package(package_ref, short_paths=short_paths) self._retrieve_remote_package(package_ref, package_folder, output, remote) def _retrieve_remote_package(self, package_ref, package_folder, output, remote=None): if remote is None: remote = self._registry.get_ref(package_ref.conan) if not remote: output.warn("Package doesn't have a remote defined. " "Probably created locally and not uploaded") return False package_id = str(package_ref.package_id) try: output.info("Looking for package %s in remote '%s' " % (package_id, remote.name)) # Will raise if not found NotFoundException self._remote_manager.get_package(package_ref, package_folder, remote) output.success('Package installed %s' % package_id) return True except ConanConnectionError: raise # This shouldn't be skipped except ConanException as e: output.warn('Binary for %s not in remote: %s' % (package_id, str(e))) return False def authenticate(self, name, password): if not name: # List all users, from all remotes remotes = self._registry.remotes if not remotes: self._out.error("No remotes defined") for remote in remotes: self._remote_manager.authenticate(remote, None, None) return remote, _ = self._get_remote() return self._remote_manager.authenticate(remote, name, password)
class ConanProxy(object): """ Class to access the conan storage, to perform typical tasks as to get packages, getting conanfiles, uploading, removing from remote, etc. It uses the RemoteRegistry to control where the packages come from. """ def __init__(self, client_cache, user_io, remote_manager, remote_name, update=False, check_updates=False, manifest_manager=False): self._client_cache = client_cache self._out = user_io.out self._remote_manager = remote_manager self._registry = RemoteRegistry(self._client_cache.registry, self._out) self._remote_name = remote_name self._update = update self._check_updates = check_updates or update # Update forces check (and of course the update) self._manifest_manager = manifest_manager @property def registry(self): return self._registry def package_available(self, package_ref, short_paths, check_outdated): """ Returns True if there is a local or remote package available (and up to date if check_outdated). It wont download the package, just check its hash """ output = ScopedOutput(str(package_ref.conan), self._out) package_folder = self._client_cache.package(package_ref, short_paths=short_paths) remote_info = None # No package in local cache if not os.path.exists(package_folder): try: remote_info = self.get_package_info(package_ref) except (NotFoundException, NoRemoteAvailable): # 404 or no remote return False # Maybe we have the package (locally or in remote) but it's outdated if check_outdated: if remote_info: package_hash = remote_info.recipe_hash else: package_hash = self._client_cache.read_package_recipe_hash(package_folder) local_recipe_hash = self._client_cache.load_manifest(package_ref.conan).summary_hash up_to_date = local_recipe_hash == package_hash if not up_to_date: output.info("Outdated package!") else: output.info("Package is up to date") return up_to_date return True def get_package(self, package_ref, short_paths): """ obtain a package, either from disk or retrieve from remotes if necessary and not necessary to build """ output = ScopedOutput(str(package_ref.conan), self._out) package_folder = self._client_cache.package(package_ref, short_paths=short_paths) # Check current package status if os.path.exists(package_folder): if self._check_updates: read_manifest = self._client_cache.load_package_manifest(package_ref) try: # get_conan_digest can fail, not in server upstream_manifest = self.get_package_digest(package_ref) if upstream_manifest != read_manifest: if upstream_manifest.time > read_manifest.time: output.warn("Current package is older than remote upstream one") if self._update: output.warn("Removing it to retrieve or build an updated one") rmdir(package_folder) else: output.warn("Current package is newer than remote upstream one") except NotFoundException: pass local_package = os.path.exists(package_folder) if local_package: output.success('Already installed!') installed = True log_package_got_from_local_cache(package_ref) else: installed = self._retrieve_remote_package(package_ref, package_folder, output) self.handle_package_manifest(package_ref, installed) return installed def handle_package_manifest(self, package_ref, installed): if installed and self._manifest_manager: remote = self._registry.get_ref(package_ref.conan) self._manifest_manager.check_package(package_ref, remote) def get_recipe_sources(self, conan_reference, short_paths=False): export_path = self._client_cache.export(conan_reference) sources_folder = self._client_cache.export_sources(conan_reference, short_paths) if os.path.exists(sources_folder): return current_remote = self._registry.get_ref(conan_reference) if not current_remote: raise ConanException("Error while trying to get recipe sources for %s. " "No remote defined" % str(conan_reference)) else: self._remote_manager.get_recipe_sources(conan_reference, export_path, sources_folder, current_remote) def get_recipe(self, conan_reference): with self._client_cache.conanfile_write_lock(conan_reference): result = self._get_recipe(conan_reference) return result def _get_recipe(self, conan_reference): output = ScopedOutput(str(conan_reference), self._out) # check if it is in disk conanfile_path = self._client_cache.conanfile(conan_reference) if os.path.exists(conanfile_path): log_recipe_got_from_local_cache(conan_reference) if self._check_updates: ret = self.update_available(conan_reference) if ret != 0: # Found and not equal remote, ref_remote = self._get_remote(conan_reference) if ret == 1: if not self._update: if remote != ref_remote: # Forced new remote output.warn("There is a new conanfile in '%s' remote. " "Execute 'install -u -r %s' to update it." % (remote.name, remote.name)) else: output.warn("There is a new conanfile in '%s' remote. " "Execute 'install -u' to update it." % remote.name) output.warn("Refused to install!") else: export_path = self._client_cache.export(conan_reference) DiskRemover(self._client_cache).remove(conan_reference) output.info("Retrieving from remote '%s'..." % remote.name) self._remote_manager.get_recipe(conan_reference, export_path, remote) output.info("Updated!") elif ret == -1: if not self._update: output.info("Current conanfile is newer " "than %s's one" % remote.name) else: output.error("Current conanfile is newer than %s's one. " "Run 'conan remove %s' and run install again " "to replace it." % (remote.name, conan_reference)) else: self._retrieve_recipe(conan_reference, output) if self._manifest_manager: # Just make sure that the recipe sources are there to check conanfile = load_conanfile_class(conanfile_path) self.get_recipe_sources(conan_reference, conanfile.short_paths) remote = self._registry.get_ref(conan_reference) self._manifest_manager.check_recipe(conan_reference, remote) return conanfile_path def update_available(self, conan_reference): """Returns 0 if the conanfiles are equal, 1 if there is an update and -1 if the local is newer than the remote""" if not conan_reference: return 0 read_manifest, _ = self._client_cache.conan_manifests(conan_reference) if read_manifest: try: # get_conan_digest can fail, not in server upstream_manifest = self.get_conan_digest(conan_reference) if upstream_manifest != read_manifest: return 1 if upstream_manifest.time > read_manifest.time else -1 except (NotFoundException, NoRemoteAvailable): # 404 pass return 0 def _retrieve_recipe(self, conan_reference, output): """ returns the requested conanfile object, retrieving it from remotes if necessary. Can raise NotFoundException """ def _retrieve_from_remote(remote): output.info("Trying with '%s'..." % remote.name) export_path = self._client_cache.export(conan_reference) result = self._remote_manager.get_recipe(conan_reference, export_path, remote) self._registry.set_ref(conan_reference, remote) return result if self._remote_name: output.info("Not found, retrieving from server '%s' " % self._remote_name) ref_remote = self._registry.remote(self._remote_name) else: ref_remote = self._registry.get_ref(conan_reference) if ref_remote: output.info("Retrieving from predefined remote '%s'" % ref_remote.name) if ref_remote: try: return _retrieve_from_remote(ref_remote) except NotFoundException: raise NotFoundException("%s was not found in remote '%s'" % (str(conan_reference), ref_remote.name)) output.info("Not found in local cache, looking in remotes...") remotes = self._registry.remotes for remote in remotes: logger.debug("Trying with remote %s" % remote.name) try: return _retrieve_from_remote(remote) # If not found continue with the next, else raise except NotFoundException as exc: if remote == remotes[-1]: # Last element not found logger.debug("Not found in any remote, raising...%s" % exc) raise NotFoundException("Unable to find '%s' in remotes" % str(conan_reference)) raise ConanException("No remote defined") def complete_recipe_sources(self, conanfile, conan_reference, force_complete=True, short_paths=False): sources_folder = self._client_cache.export_sources(conan_reference, short_paths) if not hasattr(conanfile, "exports_sources"): mkdir(sources_folder) return None ignore_deleted_file = None if not os.path.exists(sources_folder): # If not path to sources exists, we have a problem, at least an empty folder # should be there upload_remote, current_remote = self._get_remote(conan_reference) if not current_remote: raise ConanException("Trying to upload a package recipe without sources, " "and the remote for the sources no longer exists") if force_complete or current_remote != upload_remote: # If uploading to a different remote than the one from which the recipe # was retrieved, we definitely need to get the sources, so the recipe is complete self.get_recipe_sources(conan_reference, short_paths=short_paths) else: # But if same remote, no need to upload again the TGZ, it is already in the server # But the upload API needs to know it to not remove the server file. ignore_deleted_file = EXPORT_SOURCES_TGZ_NAME return ignore_deleted_file def upload_recipe(self, conan_reference, retry, retry_wait, skip_upload): """ upload to defined remote in (-r=remote), to current remote or to default remote, in that order. If the remote is not set, set it """ conan_file_path = self._client_cache.conanfile(conan_reference) conanfile = load_conanfile_class(conan_file_path) ignore_deleted_file = self.complete_recipe_sources(conanfile, conan_reference, force_complete=False, short_paths=conanfile.short_paths) remote, ref_remote = self._get_remote(conan_reference) result = self._remote_manager.upload_recipe(conan_reference, remote, retry, retry_wait, ignore_deleted_file=ignore_deleted_file, skip_upload=skip_upload) if not ref_remote and not skip_upload: self._registry.set_ref(conan_reference, remote) return result def _get_remote(self, conan_ref=None): # Prioritize -r , then reference registry and then the default remote ref_remote = self._registry.get_ref(conan_ref) if conan_ref else None if self._remote_name: remote = self._registry.remote(self._remote_name) else: if ref_remote: remote = ref_remote else: remote = self._registry.default_remote return remote, ref_remote def upload_package(self, package_ref, retry, retry_wait, skip_upload, integrity_check): remote, current_remote = self._get_remote(package_ref.conan) if not current_remote: self._out.warn("Remote for '%s' not defined, uploading to %s" % (str(package_ref.conan), remote.name)) result = self._remote_manager.upload_package(package_ref, remote, retry, retry_wait, skip_upload, integrity_check) if not current_remote and not skip_upload: self._registry.set_ref(package_ref.conan, remote) return result def get_conan_digest(self, conan_ref): """ used by update to check the date of packages, require force if older """ remote, current_remote = self._get_remote(conan_ref) result = self._remote_manager.get_conan_digest(conan_ref, remote) if not current_remote: self._registry.set_ref(conan_ref, remote) return result def get_package_digest(self, package_ref): """ used by update to check the date of packages, require force if older """ remote, ref_remote = self._get_remote(package_ref.conan) result = self._remote_manager.get_package_digest(package_ref, remote) if not ref_remote: self._registry.set_ref(package_ref.conan, remote) return result def get_package_info(self, package_ref): """ Gets the package info to check if outdated """ remote, ref_remote = self._get_remote(package_ref.conan) result = self._remote_manager.get_package_info(package_ref, remote) if not ref_remote: self._registry.set_ref(package_ref.conan, remote) return result def search_remotes(self, pattern=None, ignorecase=True): if self._remote_name: remote = self._registry.remote(self._remote_name) search_result = self._remote_manager.search_recipes(remote, pattern, ignorecase) return search_result for remote in self._registry.remotes: search_result = self._remote_manager.search_recipes(remote, pattern, ignorecase) if search_result: return search_result def remove(self, conan_ref): if not self._remote_name: raise ConanException("Cannot remove, remote not defined") remote = self._registry.remote(self._remote_name) result = self._remote_manager.remove(conan_ref, remote) current_remote = self._registry.get_ref(conan_ref) if current_remote == remote: self._registry.remove_ref(conan_ref) return result def remove_packages(self, conan_ref, remove_ids): if not self._remote_name: raise ConanException("Cannot remove, remote not defined") remote = self._registry.remote(self._remote_name) return self._remote_manager.remove_packages(conan_ref, remove_ids, remote) def get_path(self, conan_ref, package_id, path): if not self._remote_name: return get_path(self._client_cache, conan_ref, package_id, path) else: remote = self._registry.remote(self._remote_name) return self._remote_manager.get_path(conan_ref, package_id, path, remote) def download_packages(self, reference, package_ids): assert(isinstance(package_ids, list)) remote, _ = self._get_remote(reference) export_path = self._client_cache.export(reference) self._remote_manager.get_recipe(reference, export_path, remote) conanfile_path = self._client_cache.conanfile(reference) conanfile = load_conanfile_class(conanfile_path) short_paths = conanfile.short_paths self._registry.set_ref(reference, remote) output = ScopedOutput(str(reference), self._out) for package_id in package_ids: package_ref = PackageReference(reference, package_id) package_folder = self._client_cache.package(package_ref, short_paths=short_paths) self._out.info("Downloading %s" % str(package_ref)) self._retrieve_remote_package(package_ref, package_folder, output, remote) def _retrieve_remote_package(self, package_ref, package_folder, output, remote=None): if remote is None: remote = self._registry.get_ref(package_ref.conan) if not remote: output.warn("Package doesn't have a remote defined. " "Probably created locally and not uploaded") return False package_id = str(package_ref.package_id) try: output.info("Looking for package %s in remote '%s' " % (package_id, remote.name)) # Will raise if not found NotFoundException self._remote_manager.get_package(package_ref, package_folder, remote) output.success('Package installed %s' % package_id) return True except NotFoundException as e: output.warn('Binary for %s not in remote: %s' % (package_id, str(e))) return False def authenticate(self, name, password): if not name: # List all users, from all remotes remotes = self._registry.remotes if not remotes: self._out.error("No remotes defined") for remote in remotes: self._remote_manager.authenticate(remote, None, None) return remote, _ = self._get_remote() return self._remote_manager.authenticate(remote, name, password)